source: main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests.py @ 12200

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

We need documents which can be accessed or downloaded from product pages. These documents can provide general information of registration processes or pdf forms to be filled offline and later uploaded by customers.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1## $Id: tests.py 12200 2014-12-12 15:34:50Z 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.documents.interfaces import (
26    IDocumentsContainer, IDocument, IPDFDocument, IHTMLDocument)
27from waeup.ikoba.interfaces import IObjectHistory
28from waeup.ikoba.documents.container import DocumentsContainer
29from waeup.ikoba.documents.document import (
30    Document, PDFDocument, HTMLDocument)
31from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
32
33class DocumentsContainerTestCase(FunctionalTestCase):
34
35    layer = FunctionalLayer
36
37    def test_interfaces(self):
38        # Make sure the correct interfaces are implemented.
39        self.assertTrue(
40            verifyClass(
41                IDocumentsContainer, DocumentsContainer)
42            )
43        self.assertTrue(
44            verifyObject(
45                IDocumentsContainer, DocumentsContainer())
46            )
47        self.assertTrue(
48            verifyClass(
49                IDocument, Document)
50            )
51        self.assertTrue(
52            verifyObject(
53                IDocument, Document())
54            )
55
56        self.assertTrue(
57            verifyClass(
58                IPDFDocument, PDFDocument)
59            )
60        self.assertTrue(
61            verifyObject(
62                IPDFDocument, PDFDocument())
63            )
64
65        self.assertTrue(
66            verifyClass(
67                IHTMLDocument, HTMLDocument)
68            )
69        self.assertTrue(
70            verifyObject(
71                IHTMLDocument, HTMLDocument())
72            )
73        return
74
75    def test_addDocument(self):
76        container = DocumentsContainer()
77        document = createObject(u'waeup.HTMLDocument')
78        document_id = document.document_id
79        container.addDocument(document)
80        self.assertEqual(container[document_id], document)
81        self.assertRaises(TypeError, container.addDocument, object())
82        self.assertEqual(document_id, 'd123')
83        return
84
85    def test_document_workflow(self):
86        document = createObject(u'waeup.HTMLDocument')
87        IWorkflowInfo(document).fireTransition('create')
88        self.assertEqual(IWorkflowState(document).getState(), 'created')
89        IWorkflowInfo(document).fireTransition('submit')
90        self.assertEqual(IWorkflowState(document).getState(), 'submitted')
91        IWorkflowInfo(document).fireTransition('verify')
92        self.assertEqual(IWorkflowState(document).getState(), 'verified')
93        IWorkflowInfo(document).fireTransition('reset2')
94        self.assertEqual(IWorkflowState(document).getState(), 'created')
95        self.assertRaises(InvalidTransitionError,
96            IWorkflowInfo(document).fireTransition, 'verify')
97        IWorkflowInfo(document).fireTransition('submit')
98        IWorkflowInfo(document).fireTransition('reset3')
99        self.assertEqual(IWorkflowState(document).getState(), 'created')
100        IWorkflowInfo(document).fireTransition('publish')
101        self.assertEqual(IWorkflowState(document).getState(), 'published')
102        return
103
104    def test_document_history(self):
105        doc = createObject(u'waeup.HTMLDocument')
106        IWorkflowInfo(doc).fireTransition('create')
107        messages = ' '.join(doc.history.messages)
108        self.assertTrue('Document created by system' in messages)
109        return
Note: See TracBrowser for help on using the repository browser.