source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py @ 12016

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

Replace 'id' by 'document_id'.

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1## $Id: test_document.py 12004 2014-11-20 04:11:18Z 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"""
19Tests for documents.
20"""
21from zope.interface.verify import verifyClass, verifyObject
22from zope.component import createObject
23from hurry.workflow.interfaces import (
24    IWorkflowInfo, IWorkflowState, InvalidTransitionError)
25from waeup.ikoba.customers.interfaces import (
26    ICustomerDocumentsContainer, ICustomerDocument)
27from waeup.ikoba.interfaces import IObjectHistory
28from waeup.ikoba.customers.documents import (
29    CustomerDocumentsContainer, CustomerDocument)
30from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
31
32class CustomerDocumentsContainerTestCase(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                ICustomerDocumentsContainer, CustomerDocumentsContainer)
41            )
42        self.assertTrue(
43            verifyObject(
44                ICustomerDocumentsContainer, CustomerDocumentsContainer())
45            )
46        self.assertTrue(
47            verifyClass(
48                ICustomerDocument, CustomerDocument)
49            )
50        self.assertTrue(
51            verifyObject(
52                ICustomerDocument, CustomerDocument())
53            )
54        return
55
56    def test_addDocument(self):
57        container = CustomerDocumentsContainer()
58        document = createObject(u'waeup.CustomerDocument')
59        id = document.document_id
60        container.addDocument(document)
61        self.assertEqual(container[id], document)
62        self.assertRaises(TypeError, container.addDocument, object())
63        return
64
65    def test_document_workflow(self):
66        document = createObject(u'waeup.CustomerDocument')
67        IWorkflowInfo(document).fireTransition('create')
68        self.assertEqual(IWorkflowState(document).getState(), 'created')
69        IWorkflowInfo(document).fireTransition('submit')
70        self.assertEqual(IWorkflowState(document).getState(), 'submitted')
71        IWorkflowInfo(document).fireTransition('verify')
72        self.assertEqual(IWorkflowState(document).getState(), 'verified')
73        IWorkflowInfo(document).fireTransition('reset2')
74        self.assertEqual(IWorkflowState(document).getState(), 'created')
75        self.assertRaises(InvalidTransitionError,
76            IWorkflowInfo(document).fireTransition, 'verify')
77        IWorkflowInfo(document).fireTransition('submit')
78        IWorkflowInfo(document).fireTransition('reset3')
79        self.assertEqual(IWorkflowState(document).getState(), 'created')
80        return
81
82    def test_document_history(self):
83        doc = createObject(u'waeup.CustomerDocument')
84        IWorkflowInfo(doc).fireTransition('create')
85        messages = ' '.join(doc.history.messages)
86        self.assertTrue('Document created by system' in messages)
87        return
Note: See TracBrowser for help on using the repository browser.