Skip to content

Commit

Permalink
Test that incomplete submissions are not returned (#2140)
Browse files Browse the repository at this point in the history
Test that incomplete submissions are not returned on the Briefcase API
  • Loading branch information
DavisRayM authored Aug 24, 2021
1 parent 7be8919 commit 3b33776
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions onadata/apps/api/tests/fixtures/encrypted-submission.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<data xmlns="http://opendatakit.org/submissions" encrypted="yes" id="hh_survey2" version="202107261131"><base64EncryptedKey>J/0NM5BmSU1kYqd3utsZnk/7tbaUdmHAke5q6WrGBiIclhmwMuYXCcBvjrHAG/Lrqs6BRkTiRZc1ArgBkSxl97mVBGWaaRoBJXC9J5TD1c+j5JoDNXoFHC5OPiLnalAQzM4M7gmoHTMmNohNkakL2Xg8ud9zNxwJgrg11vAXbeithapcTnLEN7Da9bZnnaWhGdwBU0qNHmagpN2aT0nUli2Z5yHJYlY9O8VP6xQuMjcpzQzISQDDeNYFxhOJEsEcUrS1TfbNtXQwPndrRVWtwgAkwkjXzSUi/j+EIW0IdXWRq8uS1kB2fYz0y25zfJbI5EDP7HGCdgUBJXNtUZBl/Q==</base64EncryptedKey><meta xmlns="http://openrosa.org/xforms"><instanceID>uuid:dfc02f1f-3c5d-422d-8430-5694dfd07973</instanceID></meta><media><file>6-seater-7-15_15_11-15_45_15.jpg.enc</file></media><encryptedXmlFile>submission.xml.enc</encryptedXmlFile><base64EncryptedElementSignature>llUJLnkbxoyGZGVBpPU0/dsGa2/Xmd+5D2+d4zBGjK7R9cwS3z3byEndtG/jaN2ER2emHsCK6jsD6+59AFmSYcTEEZ/7PbbfEGHAoYgBM7EiDMDGMOcGCYMWiBWj7ibvZXSJEPfMK7wNoYZsY2zGlhNYufUC95oWkq12dVNYHp6cJVYaGrBU+vu5gDAFSTWWwQG/herc50Y3fR9e27lgpsX0UNMj/nm9srqsXpiaJ3zGVfuOniRtjy5ZQNZPTdtcyqfyoabBIcAb0xbKunITiovEf/7P5iK4S59frdr3tUg9b9kQOsNnj5I+0lEOzK7+bKqP9BsJKT0uH9e1f5dX4g==</base64EncryptedElementSignature></data>
36 changes: 36 additions & 0 deletions onadata/apps/api/tests/viewsets/test_briefcase_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import mock
from django.core.files.storage import get_storage_class
from django.conf import settings
from django.urls import reverse
from django.utils import timezone
from django.test import override_settings
Expand Down Expand Up @@ -66,6 +67,41 @@ def _publish_xml_form(self, auth=None):
response, "successfully published.", status_code=201)
self.xform = XForm.objects.order_by('pk').reverse()[0]

def test_retrieve_encrypted_form_submissions(self):
view = BriefcaseViewset.as_view({'get': 'list'})
path = os.path.join(
settings.PROJECT_ROOT, "apps", "api", "tests", "fixtures",
"encrypted-form.xls")
submission_path = os.path.join(
settings.PROJECT_ROOT, "apps", "api", "tests", "fixtures",
"encrypted-submission.xml")
self._publish_xls_form_to_project(xlsform_path=path)
form = XForm.objects.filter(id_string='hh_survey2').first()
self._make_submission(submission_path)

# Ensure media_all_received is false on the submission
# since the encrypted data wasn't sent alongside the submission
self.assertEqual(form.instances.count(), 1)
instance = form.instances.first()
self.assertEqual(instance.total_media, 2)
self.assertEqual(
set(instance.get_expected_media()),
set(['submission.xml.enc', '6-seater-7-15_15_11-15_45_15.jpg.enc'])
)
self.assertFalse(instance.media_all_received)

# Ensure submission is not returned on the Briefcase viewset
request = self.factory.get(
self._submission_list_url,
data={'formId': form.id_string})
response = view(request, username=self.user.username)
self.assertEqual(response.status_code, 401)
auth = DigestAuth(self.login_username, self.login_password)
request.META.update(auth(request.META, response))
response = view(request, username=self.user.username)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['instances'].count(), 0)

def test_view_submission_list(self):
view = BriefcaseViewset.as_view({'get': 'list'})
self._publish_xml_form()
Expand Down

0 comments on commit 3b33776

Please sign in to comment.