Skip to content

Commit

Permalink
Add submitted user to Attachment model
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Apr 16, 2024
1 parent 8f7bbab commit 8754085
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 332 deletions.
17 changes: 11 additions & 6 deletions onadata/apps/api/tests/viewsets/test_attachment_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def test_list_view_filter_by_attachment_type(self):
extension="MP4",
name=filename,
media_file=media_file,
xform=self.xform,
)

Attachment.objects.create(
Expand All @@ -295,42 +296,46 @@ def test_list_view_filter_by_attachment_type(self):
extension="PDF",
name=filename,
media_file=media_file,
xform=self.xform,
)
Attachment.objects.create(
instance=self.xform.instances.first(),
mimetype="text/plain",
extension="TXT",
name=filename,
media_file=media_file,
xform=self.xform,
)
Attachment.objects.create(
instance=self.xform.instances.first(),
mimetype="audio/mp3",
extension="MP3",
name=filename,
media_file=media_file,
xform=self.xform,
)
Attachment.objects.create(
instance=self.xform.instances.first(),
mimetype="application/geo+json",
extension="GEOJSON",
name=geojson_filename,
media_file=geojson_media_file,
xform=self.xform,
)
data = {}
data = {"xform": self.xform.pk}
request = self.factory.get("/", data, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 6)

# Apply image Filter
data["type"] = "image"
request = self.factory.get("/", data, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["mimetype"], "image/jpeg")
Expand All @@ -339,8 +344,8 @@ def test_list_view_filter_by_attachment_type(self):
data["type"] = "audio"
request = self.factory.get("/", data, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["mimetype"], "audio/mp3")
Expand All @@ -349,8 +354,8 @@ def test_list_view_filter_by_attachment_type(self):
data["type"] = "video"
request = self.factory.get("/", data, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["mimetype"], "video/mp4")
Expand All @@ -359,8 +364,8 @@ def test_list_view_filter_by_attachment_type(self):
data["type"] = "document"
request = self.factory.get("/", data, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 3)
self.assertEqual(response.data[0]["mimetype"], "application/pdf")
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/api/tests/viewsets/test_media_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestMediaViewSet(TestAbstractViewSet, TestBase):
"""

def setUp(self):
super(TestMediaViewSet, self).setUp()
super().setUp()
self.retrieve_view = MediaViewSet.as_view({"get": "retrieve"})

self._publish_xls_form_to_project()
Expand Down
Loading

0 comments on commit 8754085

Please sign in to comment.