Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <arapgodsmack@gmail.com>
  • Loading branch information
KipSigei committed Jul 20, 2023
1 parent 0c4bdd9 commit ef55fcb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions onadata/apps/api/tests/viewsets/test_briefcase_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def test_view_downloadSubmission(self):
text = f.read()
for var in ((u'{{submissionDate}}',
instance.date_created.isoformat()),
(u'{{form_id}}', str(self.xform.id))):
(u'{{form_id}}', str(self.xform.id)),
(u'{{media_id}}', str(self.attachment.id))):
text = text.replace(*var)
self.assertContains(response, instanceId, status_code=200)
self.assertMultiLineEqual(response.content.decode('utf-8'), text)
Expand Down Expand Up @@ -466,7 +467,8 @@ def test_view_downloadSubmission_no_xmlns(self, mock_get_object):
text = f.read()
for var in ((u'{{submissionDate}}',
instance.date_created.isoformat()),
(u'{{form_id}}', str(self.xform.id))):
(u'{{form_id}}', str(self.xform.id)),
(u'{{media_id}}', str(self.attachment.id))):
text = text.replace(*var)
self.assertNotIn(
'transportation id="transportation_2011_07_25"'
Expand Down Expand Up @@ -521,7 +523,8 @@ def test_view_downloadSubmission_multiple_nodes(self, mock_get_object):
text = f.read()
for var in ((u'{{submissionDate}}',
instance.date_created.isoformat()),
(u'{{form_id}}', str(self.xform.id))):
(u'{{form_id}}', str(self.xform.id)),
(u'{{media_id}}', str(self.attachment.id))):
text = text.replace(*var)
self.assertContains(response, instanceId, status_code=200)

Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/logger/templates/downloadSubmission.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
{% for media in media_files %}<mediaFile>
<filename>{{ media.name|safe }}</filename>
<hash>md5:{{ media.file_hash }}</hash>
<downloadUrl>{{ host }}{% url "attachment_url" 'original' %}?media_file={{ media.media_file.name|safe }}&attachment_id={{ media.pk }}</downloadUrl>
<downloadUrl>{{ host }}{% url "attachment_url" 'original' %}?media_file={{ media.media_file.name|safe }}&amp;attachment_id={{ media.pk|safe }}</downloadUrl>
</mediaFile>{% endfor %}
</submission>
2 changes: 1 addition & 1 deletion onadata/apps/logger/tests/test_briefcase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_view_downloadSubmission(self):
for var in (
("{{submissionDate}}", instance.date_created.isoformat()),
("{{form_id}}", str(self.xform.id)),
("{{attachment_id}}", str(self.attachment.id)),
("{{media_id}}", str(self.attachment.id)),
):
text = text.replace(*var)
self.assertContains(response, instanceId, status_code=200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<mediaFile>
<filename>1335783522563.jpg</filename>
<hash>md5:2ca0d22073a9b6b4ebe51368b08da60c</hash>
<downloadUrl>http://testserver/attachment/original?media_file=bob/attachments/{{form_id}}_transportation_2011_07_25/1335783522563.jpg&attachment_id={{attachment_id}}</downloadUrl>
<downloadUrl>http://testserver/attachment/original?media_file=bob/attachments/{{form_id}}_transportation_2011_07_25/1335783522563.jpg&amp;attachment_id={{media_id}}</downloadUrl>
</mediaFile>
</submission>
3 changes: 3 additions & 0 deletions onadata/apps/viewer/tests/test_attachment_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ def test_attachment_has_mimetype(self):
self.assertEqual(attachment.mimetype, 'image/jpeg')

def test_attachment_url_w_media_id(self):
"""Test attachment url with attachment id"""
self.assertEqual(
Attachment.objects.count(), self.attachment_count + 1)
response = self.client.get(
self.url, {"attachment_id": self.attachment.id})
self.assertEqual(response.status_code, 302) # redirects to amazon

# pylint: disable=invalid-name
def test_attachment_url_w_media_id_no_redirect(self):
"""Test attachment url with attachment id no redirect"""
self.assertEqual(
Attachment.objects.count(), self.attachment_count + 1)
response = self.client.get(
Expand Down

0 comments on commit ef55fcb

Please sign in to comment.