Skip to content

Commit 888f23e

Browse files
authored
Merge branch 'master' into fix-astroid-dependency
2 parents 9e95b78 + cc90320 commit 888f23e

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

timesketch/api/v1/resources_test.py

+90
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,49 @@ def test_append_label_to_sketch(self):
151151
)
152152
self.assert200(response)
153153

154+
def test_archive_sketch(self):
155+
"""Authenticated request to archive a sketch."""
156+
self.login()
157+
158+
# Create sketch to test with
159+
data = dict(
160+
name="test_archive_sketch",
161+
description="test_archive_sketch",
162+
)
163+
response = self.client.post(
164+
"/api/v1/sketches/",
165+
data=json.dumps(data, ensure_ascii=False),
166+
content_type="application/json",
167+
)
168+
created_id = response.json["objects"][0]["id"]
169+
170+
self.assertEqual(HTTP_STATUS_CODE_CREATED, response.status_code)
171+
172+
# Pull sketch
173+
response = self.client.get(f"/api/v1/sketches/{created_id}/")
174+
self.assertEqual(HTTP_STATUS_CODE_OK, response.status_code)
175+
self.assertEqual(len(response.json["objects"]), 1)
176+
self.assertEqual(response.json["objects"][0]["name"], "test_archive_sketch")
177+
178+
# Archive sketch
179+
resource_url = f"/api/v1/sketches/{created_id}/archive/"
180+
data = {"action": "archive"}
181+
response = self.client.post(
182+
resource_url,
183+
data=json.dumps(data, ensure_ascii=False),
184+
content_type="application/json",
185+
)
186+
self.assert200(response)
187+
188+
# Pull the sketch again to get the status
189+
response = self.client.get(f"/api/v1/sketches/{created_id}/")
190+
self.assertEqual(
191+
response.json["objects"][0]["name"],
192+
"test_archive_sketch",
193+
)
194+
self.assert200(response)
195+
self.assertIn("archived", response.json["objects"][0]["status"][0]["status"])
196+
154197
def test_sketch_delete_not_existant_sketch(self):
155198
"""Authenticated request to delete a sketch that does not exist."""
156199
self.login()
@@ -194,6 +237,53 @@ def test_attempt_to_delete_protected_sketch(self):
194237
response = self.client.delete("/api/v1/sketches/4/")
195238
self.assert403(response)
196239

240+
def test_attempt_to_delete_archived_sketch(self):
241+
"""Authenticated request to archive a sketch."""
242+
self.login()
243+
244+
# Create sketch to test with
245+
data = dict(
246+
name="test_delete_archive_sketch",
247+
description="test_delete_archive_sketch",
248+
)
249+
response = self.client.post(
250+
"/api/v1/sketches/",
251+
data=json.dumps(data, ensure_ascii=False),
252+
content_type="application/json",
253+
)
254+
created_id = response.json["objects"][0]["id"]
255+
256+
self.assertEqual(HTTP_STATUS_CODE_CREATED, response.status_code)
257+
response = self.client.get(f"/api/v1/sketches/{created_id}/")
258+
self.assertEqual(len(response.json["objects"]), 1)
259+
self.assertEqual(
260+
response.json["objects"][0]["name"], "test_delete_archive_sketch"
261+
)
262+
self.assertEqual(200, response.status_code)
263+
264+
# Archive sketch
265+
resource_url = f"/api/v1/sketches/{created_id}/archive/"
266+
data = {"action": "archive"}
267+
response = self.client.post(
268+
resource_url,
269+
data=json.dumps(data, ensure_ascii=False),
270+
content_type="application/json",
271+
)
272+
self.assert200(response)
273+
274+
# Pull the sketch again to get the status
275+
response = self.client.get(f"/api/v1/sketches/{created_id}/")
276+
self.assertEqual(
277+
response.json["objects"][0]["name"],
278+
"test_delete_archive_sketch",
279+
)
280+
self.assert200(response)
281+
self.assertIn("archived", response.json["objects"][0]["status"][0]["status"])
282+
283+
# delete an archived sketch at the moment returns a 200
284+
response = self.client.delete(f"/api/v1/sketches/{created_id}/")
285+
self.assertEqual(200, response.status_code)
286+
197287

198288
class ViewListResourceTest(BaseTest):
199289
"""Test ViewListResource."""

0 commit comments

Comments
 (0)