Skip to content

Commit

Permalink
Add test to ensure the namespace tag is removed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisRayM committed Aug 23, 2021
1 parent 4179ff0 commit d6be66c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions onadata/apps/api/tests/viewsets/test_briefcase_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core.files.storage import get_storage_class
from django.urls import reverse
from django.utils import timezone
from django.test import override_settings
from django_digest.test import DigestAuth
from rest_framework.test import APIRequestFactory

Expand Down Expand Up @@ -399,6 +400,61 @@ def test_form_export_with_no_xlsform_returns_200(self):
response = self.view(request, pk=xform.pk, format='xls')
self.assertEqual(response.status_code, 404)

@mock.patch.object(BriefcaseViewset, 'get_object')
def test_view_downloadSubmission_no_xmlns(self, mock_get_object):
view = BriefcaseViewset.as_view({'get': 'retrieve'})
self._publish_xml_form()
self.maxDiff = None
self._submit_transport_instance_w_attachment()
instanceId = u'5b2cc313-fc09-437e-8149-fcd32f695d41'
instance = Instance.objects.get(uuid=instanceId)
instance.xml = u'<?xml version=\'1.0\' ?><transportation xlmns="http://opendatakit.org/submission" id="transportation_2011_07_25"><transport><available_transportation_types_to_referral_facility>none</available_transportation_types_to_referral_facility><available_transportation_types_to_referral_facility>none</available_transportation_types_to_referral_facility><loop_over_transport_types_frequency><ambulance /><bicycle /><boat_canoe /><bus /><donkey_mule_cart /><keke_pepe /><lorry /><motorbike /><taxi /><other /></loop_over_transport_types_frequency></transport><meta><instanceID>uuid:5b2cc313-fc09-437e-8149-fcd32f695d41</instanceID></meta></transportation>\n' # noqa
mock_get_object.return_value = instance
formId = u'%(formId)s[@version=null and @uiVersion=null]/' \
u'%(formId)s[@key=uuid:%(instanceId)s]' % {
'formId': self.xform.id_string,
'instanceId': instanceId}
params = {'formId': formId}
auth = DigestAuth(self.login_username, self.login_password)
request = self.factory.get(
self._download_submission_url, data=params)
response = view(request, username=self.user.username)
self.assertEqual(response.status_code, 401)
request.META.update(auth(request.META, response))
response = view(request, username=self.user.username)
text = "uuid:%s" % instanceId
download_submission_path = os.path.join(
self.main_directory, 'fixtures', 'transportation',
'view', 'downloadSubmission.xml')
with codecs.open(download_submission_path, encoding='utf-8') as f:
text = f.read()
for var in ((u'{{submissionDate}}',
instance.date_created.isoformat()),
(u'{{form_id}}', str(self.xform.id))):
text = text.replace(*var)
self.assertNotIn(
'transportation id="transportation_2011_07_25"'
' instanceID="uuid:5b2cc313-fc09-437e-8149-fcd32f695d41"'
f' submissionDate="{ instance.date_created.isoformat() }" '
'xlmns="http://opendatakit.org/submission"',
text)
self.assertContains(response, instanceId, status_code=200)

with override_settings(SUPPORT_BRIEFCASE_SUBMISSION_DATE=False):
request = self.factory.get(
self._download_submission_url, data=params)
response = view(request, username=self.user.username)
self.assertEqual(response.status_code, 401)
request.META.update(auth(request.META, response))
response = view(request, username=self.user.username)
response.render()
self.assertIn(
'transportation id="transportation_2011_07_25"'
' instanceID="uuid:5b2cc313-fc09-437e-8149-fcd32f695d41"'
f' submissionDate="{ instance.date_created.isoformat() }" '
'xlmns="http://opendatakit.org/submission"',
response.content.decode('utf-8'))

@mock.patch.object(BriefcaseViewset, 'get_object')
def test_view_downloadSubmission_multiple_nodes(self, mock_get_object):
view = BriefcaseViewset.as_view({'get': 'retrieve'})
Expand Down

0 comments on commit d6be66c

Please sign in to comment.