File: testPosting.py

package info (click to toggle)
squishdot 1.3.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 896 kB
  • ctags: 349
  • sloc: python: 2,313; makefile: 56; sh: 54
file content (184 lines) | stat: -rw-r--r-- 6,855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from unittest import makeSuite

from base import SquishdotBase

from re import search

class PostingTests(SquishdotBase):

    def testAddArticle(self):
        "Check the SquishSite.addPosting method works"
        
        id = self._addPosting(title    = 'testSquishSiteAddPosting',
                              author   = 'tester',
                              body     = 'body',
                              email    = 'email',
                              notify   = 1,
                              encoding = 'Plain',
                              subject  = 'test subject',
                              summary  = 'summary',
                              dept     = 'dept')
        
        Posting = self.Site[id]
        
        assert Posting.title    =='testSquishSiteAddPosting'
        assert Posting.author   =='tester'
        assert Posting.body     ==['body']
        assert Posting.email    =='email'
        assert Posting.notify   ==1
        assert Posting.encoding =='Plain'
        assert Posting.subject  =='test subject'
        assert Posting.summary  ==['summary']
        assert Posting.dept     =='dept'

    def testAddArticleTTW(self):
        "Check the SquishSite.addPosting method works TTW"
        
        REQUEST=self.Site.REQUEST
        RESPONSE=REQUEST.RESPONSE
        REQUEST['title']    = 'testSquishSiteAddPosting'
        REQUEST['author']   = 'tester'
        REQUEST['body']     = 'body'
        REQUEST['email']    = 'email'
        REQUEST['notify']   = 1
        REQUEST['encoding'] = 'Plain'
        REQUEST['subject']  = 'test subject'
        REQUEST['summary']  = 'summary'
        REQUEST['dept']     = 'dept'

        self.Site.addPosting(REQUEST=REQUEST,RESPONSE=RESPONSE)
        Posting = self._getPosting(title="testSquishSiteAddPosting")
        
        assert Posting.title    =='testSquishSiteAddPosting'
        assert Posting.author   =='tester'
        assert Posting.body     ==['body']
        assert Posting.email    =='email'
        assert Posting.notify   ==1
        assert Posting.encoding =='Plain'
        assert Posting.subject  =='test subject'
        assert Posting.summary  ==['summary']
        assert Posting.dept     =='dept'

    def testAddArticleIncomplete(self):
        "Check the SquishSite.addPosting handles incomplete postings correctly"
        
        self.Site.REQUEST.HTTP_REFERER='where I came from'
        result = self._addPosting(title    = 'testSquishSiteAddPostingIncomplete')
        assert search('<FORM ACTION="where I came from"',result) is not None

    def testAddComment(self):
        "Check the Article.addPosting method works"
        
        parent = self._getPosting()
        id = self._addPosting(object   = parent,
                              title    = 'testArticleAddPosting',
                              author   = 'tester',
                              body     = 'body',
                              email    = 'email',
                              notify   = 1,
                              encoding = 'Plain')
        
        Posting = self.Site[parent.id][id]
        
        assert Posting.title    =='testArticleAddPosting'
        assert Posting.author   =='tester'
        assert Posting.body     ==['body']
        assert Posting.email    =='email'
        assert Posting.notify   ==1
        assert Posting.encoding =='Plain'
        # Comments take their subject from their parent Article.
        assert Posting.subject  ==parent.subject
        return Posting

    def testAddCommentTTW(self):
        "Check the Posting.addPosting method works TTW"
        
        REQUEST=self.Site.REQUEST
        RESPONSE=REQUEST.RESPONSE
        REQUEST['title']    = 'testSquishSiteAddPosting'
        REQUEST['author']   = 'tester'
        REQUEST['body']     = 'body'
        REQUEST['email']    = 'email'
        REQUEST['notify']   = 1
        REQUEST['encoding'] = 'Plain'

        parent = self._getPosting()
        parent.addPosting(REQUEST=REQUEST,RESPONSE=RESPONSE)
        Posting = self._getPosting(title="testSquishSiteAddPosting")
        
        assert Posting.title    =='testSquishSiteAddPosting'
        assert Posting.author   =='tester'
        assert Posting.body     ==['body']
        assert Posting.email    =='email'
        assert Posting.notify   ==1
        assert Posting.encoding =='Plain'
        assert Posting.subject  ==parent.subject

    def testAddCommentIncomplete(self):
        "Check the Posting.addPosting handles incomplete postings correctly"
        
        self.Site.REQUEST.HTTP_REFERER='where I came from'
        result = self._addPosting(object = self._getPosting(),
                                  title    = 'testSquishSiteAddPostingIncomplete')
        assert search('<FORM ACTION="where I came from"',result) is not None

    def testEditArticle(self):
        "Check the edit method makes the necessary changes to Articles"
        REQUEST = {}
        Posting = self._getPosting()
        
        REQUEST['title']   ='testEditPosting'
        REQUEST['author']  ='tester'
        REQUEST['body']    ='body'
        REQUEST['email']   ='email'
        REQUEST['notify']  =1
        REQUEST['encoding']='Plain'
        REQUEST['subject'] ='test subject'
        REQUEST['summary'] ='summary'
        REQUEST['dept']    ='dept'
        
        Posting.edit(REQUEST=REQUEST)
        
        assert Posting.title    =='testEditPosting'
        assert Posting.author   =='tester'
        assert Posting.body     ==['body']
        assert Posting.email    =='email'
        assert Posting.notify   ==1
        assert Posting.encoding =='Plain'
        assert Posting.subject  =='test subject'
        assert Posting.summary  ==['summary']
        assert Posting.dept     =='dept'

    def testEditComment(self):
        "Check the edit method makes the necessary changes to Comments"
        Posting = self.testAddComment()
        old_subject = Posting.subject
        REQUEST = {}
        
        REQUEST['title']   ='testEditComment'
        REQUEST['author']  ='tester edit'
        REQUEST['body']    ='body edit'
        REQUEST['email']   ='email edit'
        REQUEST['notify']  =0
        REQUEST['encoding']='HTML'
        
        Posting.edit(REQUEST=REQUEST)
        
        assert Posting.title    =='testEditComment'
        assert Posting.author   =='tester edit'
        assert Posting.body     ==['body edit']
        assert Posting.email    =='email edit'
        assert Posting.notify   ==0
        assert Posting.encoding =='HTML'
        assert Posting.subject  ==old_subject

    def testPreviewPosting(self):
        "Check that previewPosting doesn't barf"
        self.Site.previewPosting(self.Site,self.Site.REQUEST)
        
def test_suite():
    return makeSuite(PostingTests)

def debug():
   test_suite().debug()