source: products/SimpleBlog/trunk/tests/testContentCreation.py

Last change on this file was 1, checked in by myroslav, 15 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1
2import os, sys
3if __name__ == '__main__':
4    execfile(os.path.join(sys.path[0], 'framework.py'))
5
6from Testing import ZopeTestCase
7from Products.SimpleBlog.tests import SimpleBlogTC
8from DateTime import DateTime
9from Products.Archetypes.utils import shasattr
10
11# A test class defines a set of tests
12class TestContentCreation(SimpleBlogTC.SimpleBlogTestCase):
13
14    # The afterSetUp method can be used to define test class variables
15    # and perform initialisation before tests are run. The beforeTearDown()
16    # method can also be used to clean up anything set up in afterSetUp(),
17    # though it is less commonly used since test always run in a sandbox
18    # that is cleared after the test is run.
19    def afterSetUp(self):
20        self.membership = self.portal.portal_membership
21        self.membership.memberareaCreationFlag = 1   
22        self.addMember('fred', 'Fred Flintstone', 'fred@bedrock.com', ['Member', 'Manager'], '2002-01-01')
23        self.addMember('barney', 'Barney Rubble', 'barney@bedrock.com', ['Member'], '2002-01-01')
24        self.addMember('brubble', 'Bambam Rubble', 'bambam@bambam.net', ['Member'], '2003-12-31')
25        self.login('fred')
26        self.portal.invokeFactory('Folder', 'f1')
27        self.f1 = self.portal.f1
28
29
30    def addMember(self, username, fullname, email, roles, last_login_time):
31        self.membership.addMember(username, 'secret', roles, [])
32        member = self.membership.getMemberById(username)
33        member.setMemberProperties({'fullname': fullname, 'email': email,
34                                    'last_login_time': DateTime(last_login_time),}) 
35           
36
37    def testAddBlog(self):
38        self.portal.invokeFactory('Blog', 'blog1')
39        blog1 = self.f1.blog1
40        blog1.setTitle('A Title')
41        blog1.setDescription('A Description')
42        blog1.setDisplayItems(5)
43        blog1.setWarnForUnpublishedEntries(0)
44        blog1.setAllowCrossPosting(0)
45        blog1.setCategories(('cat1','cat2','cat3'))
46       
47        self.failUnlessEqual(blog1.Title(), 'A Title')
48        self.failUnlessEqual(blog1.Description(), 'A Description')
49        self.failUnlessEqual(blog1.getDisplayItems(), 5)
50        self.failUnlessEqual(blog1.getWarnForUnpublishedEntries(), 0)
51        self.failUnlessEqual(blog1.getAllowCrossPosting(), 0)
52        self.failUnlessEqual(blog1.getCategories(), ('cat1', 'cat2', 'cat3'))
53       
54    def testAddEntry(self):
55        self.portal.invokeFactory('Blog', 'blog1')
56        self.portal.blog1.invokeFactory('BlogEntry', 'entry1')
57        self.portal.blog1.setCategories(('cat1','cat2','cat3'))
58       
59        entry1 = self.portal.blog1.entry1
60        entry1.setTitle('A Title')
61        entry1.setDescription('A Description')
62        entry1.setBody('<p>Some text</p>')
63        entry1.setAlwaysOnTop(1)
64        entry1.setCategories(('cat2', 'cat3'))
65       
66        self.failUnlessEqual(entry1.Title(), 'A Title')
67        self.failUnlessEqual(entry1.Description(), 'A Description')
68        self.failUnlessEqual(entry1.getBody(), '<p>Some text</p>')
69        self.failUnlessEqual(entry1.getAlwaysOnTop(), 1)
70        self.failUnlessEqual(entry1.EntryCategory(), ('cat2', 'cat3'))
71        self.failUnlessEqual(entry1.getIcon(), 'entry_pin.gif')
72       
73        entry1.setAlwaysOnTop(0)
74        self.failUnlessEqual(entry1.getIcon(), 'entry_icon.gif')
75
76    def testAddBlogFolder(self):
77        self.portal.invokeFactory('Blog', 'blog1')
78        self.portal.blog1.invokeFactory('BlogFolder', 'folder1')
79        self.portal.blog1.setCategories(('cat1','cat2','cat3'))
80
81        folder1 = self.portal.blog1.folder1
82        folder1.setTitle('A Title')
83        folder1.setDescription('A Description')
84        folder1.setCategories(('catx', 'caty'))
85       
86        self.failUnlessEqual(folder1.Title(), 'A Title')
87        self.failUnlessEqual(folder1.Description(), 'A Description')
88        self.failUnlessEqual(folder1.getCategories(), ('catx', 'caty'))
89
90    def testCategoryInheritence(self):
91        self.portal.invokeFactory('Blog', 'blog1')
92        self.portal.blog1.setCategories(('cat1','cat2','cat3'))
93        self.portal.blog1.invokeFactory('BlogFolder', 'folder1')
94        folder1 = self.portal.blog1.folder1
95        folder1.setCategories(('catx', 'caty'))
96       
97        # see if it adds the cats in this context
98        folder1.invokeFactory('BlogEntry', 'entry1')
99        cats = list(folder1.entry1.listCategories())
100        cats.sort()
101       
102        self.failUnlessEqual(cats, ['cat1', 'cat2', 'cat3', 'catx', 'caty'])
103       
104    def testGetEntries(self):
105        self.portal.invokeFactory('Blog', 'blog1')
106       
107        for i in range(4):
108            self.portal.blog1.invokeFactory('BlogEntry', 'entry' + str(i))
109            entry = getattr(self.portal.blog1, 'entry' + str(i))
110            entry.reindexObject()
111       
112        for i in range(3):
113            entry = getattr(self.portal.blog1, 'entry' + str(i))
114            entry.content_status_modify(workflow_action='publish')
115            entry.setEffectiveDate(DateTime() + i)
116            entry.reindexObject()
117           
118        self.portal.blog1.entry0.setAlwaysOnTop(1)
119        self.portal.blog1.entry0.reindexObject()
120       
121        topentries, bottomentries = self.portal.blog1.getEntries()
122       
123        self.failUnlessEqual(len(topentries), 1)
124        self.failUnlessEqual(topentries[0].id, 'entry0')
125       
126        self.failUnlessEqual(len(bottomentries), 2)
127        bottomentries = [e.id for e in bottomentries]
128       
129        self.failUnlessEqual(bottomentries, ['entry2', 'entry1'])
130       
131# This boilerplate method sets up the test suite
132def test_suite():
133    from unittest import TestSuite, makeSuite
134    suite = TestSuite()
135    # Add our test class here - you can add more test classes if you wish,
136    # and they will be run together.
137    suite.addTest(makeSuite(TestContentCreation))
138    return suite
139
140if __name__ == '__main__':
141    framework()
Note: See TracBrowser for help on using the repository browser.