@@ -114,6 +114,99 @@ def test_sketch_acl(self):
114
114
response = self .client .get ("/api/v1/sketches/2/" )
115
115
self .assert403 (response )
116
116
117
+ def test_create_a_sketch (self ):
118
+ """Authenticated request to create a sketch."""
119
+ self .login ()
120
+ data = dict (
121
+ name = "test_create_a_sketch" ,
122
+ description = "test_create_a_sketch" ,
123
+ )
124
+ response = self .client .post (
125
+ "/api/v1/sketches/" ,
126
+ data = json .dumps (data , ensure_ascii = False ),
127
+ content_type = "application/json" ,
128
+ )
129
+ self .assertEqual (HTTP_STATUS_CODE_CREATED , response .status_code )
130
+
131
+ # check the created sketch
132
+
133
+ response = self .client .get ("/api/v1/sketches/" )
134
+ self .assertEqual (len (response .json ["objects" ]), 3 )
135
+ self .assertIn (b"test_create_a_sketch" , response .data )
136
+ self .assert200 (response )
137
+
138
+ def test_append_label_to_sketch (self ):
139
+ """Authenticated request to append a label to a sketch."""
140
+ self .login ()
141
+
142
+ data = dict (
143
+ labels = ["test_append_label_to_sketch" ],
144
+ label_action = "add" ,
145
+ )
146
+
147
+ response = self .client .post (
148
+ "/api/v1/sketches/3/" ,
149
+ data = json .dumps (data , ensure_ascii = False ),
150
+ content_type = "application/json" ,
151
+ )
152
+
153
+ self .assertEqual (response .status_code , HTTP_STATUS_CODE_CREATED )
154
+
155
+ # check the result in content
156
+ response = self .client .get ("/api/v1/sketches/3/" )
157
+ self .assertEqual (len (response .json ["objects" ]), 1 )
158
+ self .assertEqual (response .json ["objects" ][0 ]["name" ], "Test 3" )
159
+ self .assertIn (
160
+ "test_append_label_to_sketch" , response .json ["objects" ][0 ]["label_string" ]
161
+ )
162
+ self .assert200 (response )
163
+
164
+ def test_sketch_delete_not_existant_sketch (self ):
165
+ """Authenticated request to delete a sketch that does not exist."""
166
+ self .login ()
167
+ response = self .client .delete ("/api/v1/sketches/99/" )
168
+ self .assert404 (response )
169
+
170
+ def test_sketch_delete_no_acl (self ):
171
+ """Authenticated request to delete a sketch that the User has no read
172
+ permission on.
173
+ """
174
+ self .login ()
175
+ response = self .client .delete ("/api/v1/sketches/2/" )
176
+ self .assert403 (response )
177
+
178
+ def test_attempt_to_delete_protected_sketch (self ):
179
+ """Authenticated request to delete a protected sketch."""
180
+ self .login ()
181
+ data = dict (
182
+ name = "test_attempt_to_delete_protected_sketch" ,
183
+ description = "test_attempt_to_delete_protected_sketch" ,
184
+ )
185
+ response = self .client .post (
186
+ "/api/v1/sketches/" ,
187
+ data = json .dumps (data , ensure_ascii = False ),
188
+ content_type = "application/json" ,
189
+ )
190
+ self .assertEqual (HTTP_STATUS_CODE_CREATED , response .status_code )
191
+ data = dict (
192
+ labels = ["protected" ],
193
+ label_action = "add" ,
194
+ )
195
+ response = self .client .post (
196
+ "/api/v1/sketches/4/" ,
197
+ data = json .dumps (data , ensure_ascii = False ),
198
+ content_type = "application/json" ,
199
+ )
200
+
201
+ self .assertEqual (
202
+ response .json ["objects" ][0 ]["name" ],
203
+ "test_attempt_to_delete_protected_sketch" ,
204
+ )
205
+ self .assertIn ("protected" , response .json ["objects" ][0 ]["label_string" ])
206
+
207
+ response = self .client .delete ("/api/v1/sketches/4/" )
208
+ self .assert403 (response )
209
+
117
210
118
211
class ViewListResourceTest (BaseTest ):
119
212
"""Test ViewListResource."""
0 commit comments