source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_interfaces.py

Last change on this file was 12809, checked in by Henrik Bettermann, 10 years ago

Remove ellipses.

  • Property svn:keywords set to Id
File size: 6.0 KB
RevLine 
[12101]1# -*- coding: utf-8 -*-
2## $Id: test_interfaces.py 12809 2015-03-21 13:31:16Z henrik $
3##
[12102]4## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
[12101]5## This program is free software; you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 2 of the License, or
8## (at your option) any later version.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
17## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18##
19
20# Tests for interfaces and included components.
21import grok
22import unittest
23import tempfile
24import shutil
[12585]25from datetime import date
[12785]26from zope.event import notify
[12101]27from zope.component.hooks import setSite
28from zope.component import queryUtility, createObject
29from hurry.workflow.interfaces import IWorkflowState
30from waeup.ikoba.app import Company
[12785]31from waeup.ikoba.interfaces import SUBMITTED, APPROVED
[12101]32from waeup.ikoba.customers.vocabularies import (
[12785]33    ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource,
34    RefereeSourceFactory
35    )
[12101]36from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
37
38
39class SourceTests(FunctionalTestCase):
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(SourceTests, self).setUp()
45
46        # Prepopulate ZODB
47        app = Company()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        self.app = self.getRootFolder()['app']
54        setSite(self.app)
55
56        # Create customer with subobjects
57        customer = createObject('waeup.Customer')
58        customer.firstname = u'Bob'
59        customer.lastname = u'Tester'
60        customer.matric_number = u'1234'
61        self.app['customers'].addCustomer(customer)
62        self.customer_id = customer.customer_id
63        self.customer = self.app['customers'][self.customer_id]
64
65        product = createObject('waeup.Product')
66        product.product_id = u'SAM'
67        product.title = u'Our Sample Product'
68        product.contract_category = u'sample'
69        self.app['products'].addProduct(product)
70        self.product_id = product.product_id
71        self.product = self.app['products'][self.product_id]
72
73        contract = createObject('waeup.SampleContract')
74        contract.product = product
75        contract.last_product_id = product.product_id
76        self.customer['contracts'].addContract(contract)
77        self.contract_id = contract.contract_id
78        self.contract = self.customer['contracts'][self.contract_id]
79
80        document = createObject('waeup.CustomerSampleDocument')
[12336]81        document.title = u'My Sample Document'
[12256]82        document.document_id = u'DOC1'
[12101]83        self.customer['documents'].addDocument(document)
84        self.document_id = document.document_id
85        self.document = self.customer['documents'][self.document_id]
86        return
87
88    def test_getValues_ConCatProductSource(self):
89        source = ConCatProductSource()
90        self.product.contract_category = u'sample'
91        result = source.factory.getValues(self.contract)
92        self.assertTrue(self.product in result)
93        self.product.contract_category = u'license'
94        result = source.factory.getValues(self.contract)
95        self.assertEqual(len(result), 0)
96
97    def test_getTitle_ConCatProductSource(self):
98        source = ConCatProductSource()
99        result = source.factory.getTitle(object(), self.product)
100        self.assertEqual(result, u'SAM - Our Sample Product')
101
[12585]102    def test_getValues_ConCatActiveProductSource(self):
103        source = ConCatActiveProductSource()
104        self.product.valid_from = date(2030, 12, 4)
105        self.product.valid_to = None
106        self.product.contract_category = u'sample'
107        result = source.factory.getValues(self.contract)
108        self.assertFalse(self.product in result)
109        self.product.valid_from = None
110        self.product.valid_to = date(2030, 12, 4)
111        self.product.contract_category = u'sample'
112        result = source.factory.getValues(self.contract)
113        self.assertTrue(self.product in result)
114        self.product.valid_from = None
115        self.product.valid_to = date(2010, 12, 4)
116        self.product.contract_category = u'sample'
117        result = source.factory.getValues(self.contract)
118        self.assertFalse(self.product in result)
119        self.product.valid_from = date(2010, 12, 4)
120        self.product.valid_to = None
121        self.product.contract_category = u'sample'
122        result = source.factory.getValues(self.contract)
123        self.assertTrue(self.product in result)
124
[12101]125    def test_getValues_CustomerDocumentSource(self):
126        source = CustomerDocumentSource()
127        result = source.factory.getValues(self.contract)
128        self.assertFalse(self.document in result)
129        IWorkflowState(self.document).setState(SUBMITTED)
130        result = source.factory.getValues(self.contract)
131        self.assertTrue(self.document in result)
132
133    def test_getTitle_CustomerDocumentSource(self):
134        source = CustomerDocumentSource()
135        result = source.factory.getTitle(object(), self.document)
[12809]136        self.assertEqual(result, u'DOC1 - My Sample Document')
[12101]137
[12785]138    def test_getValues_RefereeSourceFactory(self):
139        source = RefereeSourceFactory()
140        result = source.factory.getValues(object())
141        self.assertFalse(self.customer in result)
142        IWorkflowState(self.customer).setState(APPROVED)
143        notify(grok.ObjectModifiedEvent(self.customer))
144        result = source.factory.getValues(object())
145        self.assertTrue(self.customer in result)
146
147    def test_getTitle_RefereeSourceFactory(self):
148        source = RefereeSourceFactory()
149        result = source.factory.getTitle(object(), self.customer)
150        self.assertEqual(result, u'Bob Tester (K1000000)')
Note: See TracBrowser for help on using the repository browser.