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

Last change on this file since 12253 was 12102, checked in by Henrik Bettermann, 10 years ago

Change some copyright dates.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: test_interfaces.py 12102 2014-12-01 06:46:13Z henrik $
3##
4## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
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
25from zope.component.hooks import setSite
26from zope.component import queryUtility, createObject
27from hurry.workflow.interfaces import IWorkflowState
28from waeup.ikoba.app import Company
29from waeup.ikoba.interfaces import SUBMITTED
30from waeup.ikoba.customers.vocabularies import (
31    ConCatProductSource, CustomerDocumentSource)
32from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
33
34
35class SourceTests(FunctionalTestCase):
36
37    layer = FunctionalLayer
38
39    def setUp(self):
40        super(SourceTests, self).setUp()
41
42        # Prepopulate ZODB
43        app = Company()
44        self.dc_root = tempfile.mkdtemp()
45        app['datacenter'].setStoragePath(self.dc_root)
46
47        # Prepopulate the ZODB...
48        self.getRootFolder()['app'] = app
49        self.app = self.getRootFolder()['app']
50        setSite(self.app)
51
52        # Create customer with subobjects
53        customer = createObject('waeup.Customer')
54        customer.firstname = u'Bob'
55        customer.lastname = u'Tester'
56        customer.matric_number = u'1234'
57        self.app['customers'].addCustomer(customer)
58        self.customer_id = customer.customer_id
59        self.customer = self.app['customers'][self.customer_id]
60
61        product = createObject('waeup.Product')
62        product.product_id = u'SAM'
63        product.title = u'Our Sample Product'
64        product.contract_category = u'sample'
65        self.app['products'].addProduct(product)
66        self.product_id = product.product_id
67        self.product = self.app['products'][self.product_id]
68
69        contract = createObject('waeup.SampleContract')
70        contract.title = u'My Samle Contract'
71        contract.product = product
72        contract.last_product_id = product.product_id
73        self.customer['contracts'].addContract(contract)
74        self.contract_id = contract.contract_id
75        self.contract = self.customer['contracts'][self.contract_id]
76
77        document = createObject('waeup.CustomerSampleDocument')
78        document.title = u'My Samle Document'
79        self.customer['documents'].addDocument(document)
80        self.document_id = document.document_id
81        self.document = self.customer['documents'][self.document_id]
82        return
83
84    def test_getValues_ConCatProductSource(self):
85        source = ConCatProductSource()
86        self.product.contract_category = u'sample'
87        result = source.factory.getValues(self.contract)
88        self.assertTrue(self.product in result)
89        self.product.contract_category = u'license'
90        result = source.factory.getValues(self.contract)
91        self.assertEqual(len(result), 0)
92
93    def test_getTitle_ConCatProductSource(self):
94        source = ConCatProductSource()
95        result = source.factory.getTitle(object(), self.product)
96        self.assertEqual(result, u'SAM - Our Sample Product')
97
98    def test_getValues_CustomerDocumentSource(self):
99        source = CustomerDocumentSource()
100        result = source.factory.getValues(self.contract)
101        self.assertFalse(self.document in result)
102        IWorkflowState(self.document).setState(SUBMITTED)
103        result = source.factory.getValues(self.contract)
104        self.assertTrue(self.document in result)
105
106    def test_getTitle_CustomerDocumentSource(self):
107        source = CustomerDocumentSource()
108        result = source.factory.getTitle(object(), self.document)
109        self.assertEqual(result, u'd101 - My Samle Document')
110
Note: See TracBrowser for help on using the repository browser.