1 | ## $Id: test_contract.py 12259 2014-12-18 15:47:12Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """ |
---|
19 | Tests for contracts. |
---|
20 | """ |
---|
21 | from zope.interface.verify import verifyClass, verifyObject |
---|
22 | from zope.component import createObject |
---|
23 | from hurry.workflow.interfaces import ( |
---|
24 | IWorkflowInfo, IWorkflowState, InvalidTransitionError) |
---|
25 | from waeup.ikoba.customers.interfaces import ( |
---|
26 | IContractsContainer, IContract) |
---|
27 | from waeup.ikoba.interfaces import IObjectHistory |
---|
28 | from waeup.ikoba.customers.contracts import ( |
---|
29 | ContractsContainer, SampleContract) |
---|
30 | from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) |
---|
31 | |
---|
32 | class ContractsContainerTestCase(FunctionalTestCase): |
---|
33 | |
---|
34 | layer = FunctionalLayer |
---|
35 | |
---|
36 | def test_interfaces(self): |
---|
37 | # Make sure the correct interfaces are implemented. |
---|
38 | self.assertTrue( |
---|
39 | verifyClass( |
---|
40 | IContractsContainer, ContractsContainer) |
---|
41 | ) |
---|
42 | self.assertTrue( |
---|
43 | verifyObject( |
---|
44 | IContractsContainer, ContractsContainer()) |
---|
45 | ) |
---|
46 | self.assertTrue( |
---|
47 | verifyClass( |
---|
48 | IContract, SampleContract) |
---|
49 | ) |
---|
50 | self.assertTrue( |
---|
51 | verifyObject( |
---|
52 | IContract, SampleContract()) |
---|
53 | ) |
---|
54 | return |
---|
55 | |
---|
56 | def test_addContract(self): |
---|
57 | container = ContractsContainer() |
---|
58 | contract = createObject(u'waeup.SampleContract') |
---|
59 | id = contract.contract_id |
---|
60 | container.addContract(contract) |
---|
61 | self.assertEqual(container[id], contract) |
---|
62 | self.assertRaises(TypeError, container.addContract, object()) |
---|
63 | self.assertEqual(contract.class_name, 'SampleContract') |
---|
64 | return |
---|
65 | |
---|
66 | def test_contract_workflow(self): |
---|
67 | contract = createObject(u'waeup.SampleContract') |
---|
68 | IWorkflowInfo(contract).fireTransition('create') |
---|
69 | self.assertEqual(IWorkflowState(contract).getState(), 'created') |
---|
70 | IWorkflowInfo(contract).fireTransition('submit') |
---|
71 | self.assertEqual(IWorkflowState(contract).getState(), 'submitted') |
---|
72 | IWorkflowInfo(contract).fireTransition('approve') |
---|
73 | self.assertEqual(IWorkflowState(contract).getState(), 'approved') |
---|
74 | IWorkflowInfo(contract).fireTransition('expire') |
---|
75 | self.assertEqual(IWorkflowState(contract).getState(), 'expired') |
---|
76 | IWorkflowInfo(contract).fireTransition('reset4') |
---|
77 | self.assertEqual(IWorkflowState(contract).getState(), 'created') |
---|
78 | self.assertRaises(InvalidTransitionError, |
---|
79 | IWorkflowInfo(contract).fireTransition, 'approve') |
---|
80 | IWorkflowInfo(contract).fireTransition('submit') |
---|
81 | IWorkflowInfo(contract).fireTransition('reset3') |
---|
82 | self.assertEqual(IWorkflowState(contract).getState(), 'created') |
---|
83 | return |
---|
84 | |
---|
85 | def test_contract_history(self): |
---|
86 | doc = createObject(u'waeup.SampleContract') |
---|
87 | IWorkflowInfo(doc).fireTransition('create') |
---|
88 | messages = ' '.join(doc.history.messages) |
---|
89 | self.assertTrue('Contract created by system' in messages) |
---|
90 | return |
---|