source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_application.py @ 12093

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

Implement application content components and rework workflows.

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1## $Id: test_application.py 12089 2014-11-28 21:35:09Z 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 applications.
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    IApplicationsContainer, IApplication)
27from waeup.ikoba.interfaces import IObjectHistory
28from waeup.ikoba.customers.applications import (
29    ApplicationsContainer, SampleApplication)
30from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
31
32class ApplicationsContainerTestCase(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                IApplicationsContainer, ApplicationsContainer)
41            )
42        self.assertTrue(
43            verifyObject(
44                IApplicationsContainer, ApplicationsContainer())
45            )
46        self.assertTrue(
47            verifyClass(
48                IApplication, SampleApplication)
49            )
50        self.assertTrue(
51            verifyObject(
52                IApplication, SampleApplication())
53            )
54        return
55
56    def test_addApplication(self):
57        container = ApplicationsContainer()
58        application = createObject(u'waeup.SampleApplication')
59        id = application.application_id
60        container.addApplication(application)
61        self.assertEqual(container[id], application)
62        self.assertRaises(TypeError, container.addApplication, object())
63        self.assertEqual(application.class_name, 'SampleApplication')
64        self.assertEqual(id, 'a123')
65        return
66
67    def test_application_workflow(self):
68        application = createObject(u'waeup.SampleApplication')
69        IWorkflowInfo(application).fireTransition('create')
70        self.assertEqual(IWorkflowState(application).getState(), 'created')
71        IWorkflowInfo(application).fireTransition('submit')
72        self.assertEqual(IWorkflowState(application).getState(), 'submitted')
73        IWorkflowInfo(application).fireTransition('approve')
74        self.assertEqual(IWorkflowState(application).getState(), 'approved')
75        IWorkflowInfo(application).fireTransition('expire')
76        self.assertEqual(IWorkflowState(application).getState(), 'expired')
77        IWorkflowInfo(application).fireTransition('reset4')
78        self.assertEqual(IWorkflowState(application).getState(), 'created')
79        self.assertRaises(InvalidTransitionError,
80            IWorkflowInfo(application).fireTransition, 'approve')
81        IWorkflowInfo(application).fireTransition('submit')
82        IWorkflowInfo(application).fireTransition('reset3')
83        self.assertEqual(IWorkflowState(application).getState(), 'created')
84        return
85
86    def test_application_history(self):
87        doc = createObject(u'waeup.SampleApplication')
88        IWorkflowInfo(doc).fireTransition('create')
89        messages = ' '.join(doc.history.messages)
90        self.assertTrue('Application record created by system' in messages)
91        return
Note: See TracBrowser for help on using the repository browser.