source: main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_interfaces.py @ 12699

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

Only valid (active) products are selectable in UI.

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: test_interfaces.py 12585 2015-02-10 15:39:09Z 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 datetime import date
26from zope.component.hooks import setSite
27from zope.component import queryUtility, createObject
28from hurry.workflow.interfaces import IWorkflowState
29from waeup.ikoba.app import Company
30from waeup.ikoba.interfaces import SUBMITTED
31from waeup.ikoba.customers.vocabularies import (
32    ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource)
33from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
34
35
36class SourceTests(FunctionalTestCase):
37
38    layer = FunctionalLayer
39
40    def setUp(self):
41        super(SourceTests, self).setUp()
42
43        # Prepopulate ZODB
44        app = Company()
45        self.dc_root = tempfile.mkdtemp()
46        app['datacenter'].setStoragePath(self.dc_root)
47
48        # Prepopulate the ZODB...
49        self.getRootFolder()['app'] = app
50        self.app = self.getRootFolder()['app']
51        setSite(self.app)
52
53        # Create customer with subobjects
54        customer = createObject('waeup.Customer')
55        customer.firstname = u'Bob'
56        customer.lastname = u'Tester'
57        customer.matric_number = u'1234'
58        self.app['customers'].addCustomer(customer)
59        self.customer_id = customer.customer_id
60        self.customer = self.app['customers'][self.customer_id]
61
62        product = createObject('waeup.Product')
63        product.product_id = u'SAM'
64        product.title = u'Our Sample Product'
65        product.contract_category = u'sample'
66        self.app['products'].addProduct(product)
67        self.product_id = product.product_id
68        self.product = self.app['products'][self.product_id]
69
70        contract = createObject('waeup.SampleContract')
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 Sample 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_ConCatActiveProductSource(self):
100        source = ConCatActiveProductSource()
101        self.product.valid_from = date(2030, 12, 4)
102        self.product.valid_to = None
103        self.product.contract_category = u'sample'
104        result = source.factory.getValues(self.contract)
105        self.assertFalse(self.product in result)
106        self.product.valid_from = None
107        self.product.valid_to = date(2030, 12, 4)
108        self.product.contract_category = u'sample'
109        result = source.factory.getValues(self.contract)
110        self.assertTrue(self.product in result)
111        self.product.valid_from = None
112        self.product.valid_to = date(2010, 12, 4)
113        self.product.contract_category = u'sample'
114        result = source.factory.getValues(self.contract)
115        self.assertFalse(self.product in result)
116        self.product.valid_from = date(2010, 12, 4)
117        self.product.valid_to = None
118        self.product.contract_category = u'sample'
119        result = source.factory.getValues(self.contract)
120        self.assertTrue(self.product in result)
121
122    def test_getValues_CustomerDocumentSource(self):
123        source = CustomerDocumentSource()
124        result = source.factory.getValues(self.contract)
125        self.assertFalse(self.document in result)
126        IWorkflowState(self.document).setState(SUBMITTED)
127        result = source.factory.getValues(self.contract)
128        self.assertTrue(self.document in result)
129
130    def test_getTitle_CustomerDocumentSource(self):
131        source = CustomerDocumentSource()
132        result = source.factory.getTitle(object(), self.document)
133        self.assertEqual(result, u'DOC1... - My Sample Document')
134
Note: See TracBrowser for help on using the repository browser.