Skip to content

Commit

Permalink
Merge pull request #3877 from kobotoolbox/3876-fix-submission-edit-au…
Browse files Browse the repository at this point in the history
…th-loop

Fix submission edit authentication loop
  • Loading branch information
noliveleger authored Jun 17, 2022
2 parents edbe6e3 + c22f58e commit 34a7d2b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kpi/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def versioned_snapshot(
self, version_uid: str, root_node_name: Optional[str] = None
) -> AssetSnapshot:
return self._snapshot(
regenerate=True,
regenerate=False,
version_uid=version_uid,
root_node_name=root_node_name,
)
Expand Down
40 changes: 40 additions & 0 deletions kpi/tests/api/v2/test_api_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,46 @@ def test_edit_submission_with_authenticated_session_but_no_digest(self):
with pytest.raises(KeyError) as e:
req = self.client.post(url)

@responses.activate
def test_get_multiple_edit_links_and_attempt_submit_edits(self):
"""
Ensure that opening multiple edits allows for all to be submitted
without the snapshot being recreated and rejecting any of the edits.
"""
ee_url = (
f'{settings.ENKETO_URL}/{settings.ENKETO_EDIT_INSTANCE_ENDPOINT}'
)
# Mock Enketo response
responses.add_callback(
responses.POST, ee_url,
callback=enketo_edit_instance_response,
content_type='application/json',
)

# open several submissions for editing and store their submission URLs
# for POSTing to later
submission_urls = []
for _ in range(2):
submission = self.get_random_submission(self.asset.owner)
edit_url = reverse(
self._get_endpoint('submission-enketo-edit'),
kwargs={
'parent_lookup_asset': self.asset.uid,
'pk': submission['_id'],
},
)
self.client.get(edit_url, {'format': 'json'})
url = reverse(
self._get_endpoint('assetsnapshot-submission'),
args=(self.asset.snapshot.uid,),
)
submission_urls.append(url)
# Post all edits to their submission URLs. There is no valid XML being
# sent, so we expect a KeyError exeption if all is good
for url in submission_urls:
with pytest.raises(KeyError) as e:
res = self.client.post(url)


class SubmissionViewApiTests(BaseSubmissionTestCase):

Expand Down

0 comments on commit 34a7d2b

Please sign in to comment.