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 | """ |
---|
19 | Tests for documents. |
---|
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.documents.interfaces import ( |
---|
26 | IDocumentsContainer, IDocument, IPDFDocument, IHTMLDocument) |
---|
27 | from waeup.ikoba.interfaces import IObjectHistory |
---|
28 | from waeup.ikoba.documents.container import DocumentsContainer |
---|
29 | from waeup.ikoba.documents.document import ( |
---|
30 | Document, PDFDocument, HTMLDocument) |
---|
31 | from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) |
---|
32 | |
---|
33 | class 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 |
---|