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

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

Change document_id generation algorithm. Use Universally Unique IDentifiers instead of consecutive numbers.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: test_interfaces.py 12256 2014-12-18 12:58:12Z 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        document.document_id = u'DOC1'
80        self.customer['documents'].addDocument(document)
81        self.document_id = document.document_id
82        self.document = self.customer['documents'][self.document_id]
83        return
84
85    def test_getValues_ConCatProductSource(self):
86        source = ConCatProductSource()
87        self.product.contract_category = u'sample'
88        result = source.factory.getValues(self.contract)
89        self.assertTrue(self.product in result)
90        self.product.contract_category = u'license'
91        result = source.factory.getValues(self.contract)
92        self.assertEqual(len(result), 0)
93
94    def test_getTitle_ConCatProductSource(self):
95        source = ConCatProductSource()
96        result = source.factory.getTitle(object(), self.product)
97        self.assertEqual(result, u'SAM - Our Sample Product')
98
99    def test_getValues_CustomerDocumentSource(self):
100        source = CustomerDocumentSource()
101        result = source.factory.getValues(self.contract)
102        self.assertFalse(self.document in result)
103        IWorkflowState(self.document).setState(SUBMITTED)
104        result = source.factory.getValues(self.contract)
105        self.assertTrue(self.document in result)
106
107    def test_getTitle_CustomerDocumentSource(self):
108        source = CustomerDocumentSource()
109        result = source.factory.getTitle(object(), self.document)
110        self.assertEqual(result, u'DOC1 - My Samle Document')
111
Note: See TracBrowser for help on using the repository browser.