Skip to content

Commit

Permalink
Update replaced attachment test
Browse files Browse the repository at this point in the history
Update test_replaced_attachments_not_tracked test making sure that file
uploads are properly handled and the soft_deletion feature works as
expected
  • Loading branch information
DavisRayM committed Apr 20, 2020
1 parent fc63174 commit 52a5020
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions onadata/libs/tests/utils/test_logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,31 +247,39 @@ def test_replaced_attachments_not_tracked(self):
md = """
| survey | | | |
| | type | name | label |
| | image | image1 | Photo |
| | file | file | File |
| | image | image | Image |
"""
self._create_user_and_login()
self.xform = self._publish_markdown(md, self.user)

xml_string = """
<data id="{}">
<data xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" id="{}">
<meta>
<instanceID>uuid:UJ5jz4EszdgH8uhy8nss1AsKaqBPO5VN7</instanceID>
</meta>
<image1>1300221157303.jpg</image1>
<file>Health_2011_03_13.xml_2011-03-15_20-30-28.xml</file>
<image>1300221157303.jpg</image>
</data>
""".format(self.xform.id_string)
file_path = "{}/apps/logger/tests/Health_2011_03_13."\
"xml_2011-03-15_20-30-28/1300221157303"\
".jpg".format(settings.PROJECT_ROOT)
media_file = django_file(
path=file_path, field_name="image1", content_type="image/jpeg")
media_root = (f'{settings.PROJECT_ROOT}/apps/logger/tests/Health'
'_2011_03_13.xml_2011-03-15_20-30-28/')
image_media = django_file(
path=f'{media_root}1300221157303.jpg', field_name='image',
content_type='image/jpeg')
file_media = django_file(
path=f'{media_root}Health_2011_03_13.xml_2011-03-15_20-30-28.xml',
field_name='file', content_type='text/xml')
instance = create_instance(
self.user.username,
BytesIO(xml_string.strip().encode('utf-8')),
media_files=[media_file])
media_files=[file_media, image_media])
self.assertTrue(instance.json[MEDIA_ALL_RECEIVED])
self.assertEquals(instance.json[TOTAL_MEDIA], 1)
self.assertEquals(instance.json[MEDIA_COUNT], 1)
self.assertEqual(
instance.attachments.filter(deleted_at__isnull=True).count(),
2)
self.assertEquals(instance.json[TOTAL_MEDIA], 2)
self.assertEquals(instance.json[MEDIA_COUNT], 2)
self.assertEquals(instance.json[TOTAL_MEDIA], instance.total_media)
self.assertEquals(instance.json[MEDIA_COUNT], instance.media_count)
self.assertEquals(instance.json[MEDIA_ALL_RECEIVED],
Expand Down Expand Up @@ -304,6 +312,7 @@ def test_replaced_attachments_not_tracked(self):
instance2 = Instance.objects.get(pk=instance.pk)
self.assertTrue(instance2.json[MEDIA_ALL_RECEIVED])
# Test that only one attachment is recognised for this submission
# Since the file is no longer present in the submission
self.assertEquals(instance2.json[TOTAL_MEDIA], 1)
self.assertEquals(instance2.json[MEDIA_COUNT], 1)
self.assertEquals(
Expand Down

0 comments on commit 52a5020

Please sign in to comment.