File: testSquishfile.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 (172 lines) | stat: -rw-r--r-- 6,098 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
from unittest import makeSuite

from base import SquishdotBase

from Products.Squishdot.Utility import addFile, createUploadable

class SquishfileTests(SquishdotBase):

    def _fileAssertions(self,Posting):
        theFile = Posting.file
        assert theFile.meta_type=="Squishdot File"
        assert theFile.file_name()=="test.txt"
        assert theFile.file_bytes()==1952
        assert theFile.getContentType()=='text/plain'
        assert hasattr(Posting,'test.txt')
        

    def testAddFile(self):
        "test the Utility.addFile method"
        Posting = self._getPosting()
        addFile(Posting,'tests/test.txt')
        self._fileAssertions(Posting)

    def testAddArticleWithAttachment(self):
        "test adding an Article with an attachment"
        self._addPosting(title    = 'testAddPostingWithAttachment',
                         author   = 'tester',
                         summary  = 'body',
                         encoding = 'Plain',
                         filepath = 'test.txt',
                         subject  = 'test subject')
        Posting = self._getPosting(title='testAddPostingWithAttachment')
        self._fileAssertions(Posting)
        return Posting
        
    def testAddCommentWithAttachment(self):
        "test adding a Comment with an attachment"
        parent = self._getPosting()
        self._addPosting(object=parent,
                         title    = 'testAddPostingWithAttachment',
                         author   = 'tester',
                         body     = 'body',
                         encoding = 'Plain',
                         filepath = 'test.txt')
        Posting = self._getPosting(title='testAddPostingWithAttachment')
        self._fileAssertions(Posting)
        return Posting
        
    def testEditCommentWithAttachment(self):
        "Check the Comment edit method leaves file attachments alone"
        Posting = self.testAddCommentWithAttachment()
        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)
        
        self._fileAssertions(Posting)

    def testEditArticleWithAttachment(self):
        "Check the Article edit method leaves file attachments alone"
        Posting = self.testAddArticleWithAttachment()

        REQUEST={}
        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)
        
        self._fileAssertions(Posting)

    def testDeleteArticleAttachment(self):
        "Check deletion of Article attachments"
        Posting = self.testAddArticleWithAttachment()
        
        REQUEST={}
        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,delete_attachment='yes')

        theFile = Posting.file
        assert theFile==""
        assert not hasattr(theFile,'test.txt')
        
    def testDeleteCommentAttachment(self):
        "Check deletion of Comment attachments"
        Posting = self.testAddCommentWithAttachment()
        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,delete_attachment='yes')
        
        theFile = Posting.file
        assert theFile==""
        assert not hasattr(theFile,'test.txt')

    def testReplaceArticleAttachment(self):
        "Check deletion of Article attachments"
        Posting = self.testAddArticleWithAttachment()
        
        REQUEST={}
        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'

        file = createUploadable('../demo/messages/images.zip')

        Posting.edit(REQUEST=REQUEST,new_attachment=file)

        theFile = Posting.file
        assert theFile.meta_type=="Squishdot File"
        assert theFile.file_name()=="images.zip"
        assert theFile.file_bytes()==17291
        assert theFile.getContentType()=='application/zip'
        assert hasattr(Posting,'images.zip')
        assert not hasattr(theFile,'test.txt')
        
    def testReplaceCommentAttachment(self):
        "Check deletion of Comment attachments"
        Posting = self.testAddCommentWithAttachment()
        REQUEST = {}
        REQUEST['title']   ='testEditComment'
        REQUEST['author']  ='tester edit'
        REQUEST['body']    ='body edit'
        REQUEST['email']   ='email edit'
        REQUEST['notify']  =0
        REQUEST['encoding']='HTML'
        
        file = createUploadable('../demo/messages/images.zip')

        Posting.edit(REQUEST=REQUEST,new_attachment=file)
        
        theFile = Posting.file
        assert theFile.meta_type=="Squishdot File"
        assert theFile.file_name()=="images.zip"
        assert theFile.file_bytes()==17291
        assert theFile.getContentType()=='application/zip'
        assert hasattr(Posting,'images.zip')
        assert not hasattr(theFile,'test.txt')

def test_suite():
    return makeSuite(SquishfileTests)

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