Skip to content

Commit

Permalink
source/collection version export get request returns 208 if its still…
Browse files Browse the repository at this point in the history
… processing
  • Loading branch information
snyaggarwal committed Feb 4, 2021
1 parent 17c7365 commit 4304e23
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def get(self, request, *args, **kwargs): # pylint: disable=unused-argument
if version.is_head:
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)

if version.is_processing:
return Response(status=status.HTTP_208_ALREADY_REPORTED)

exists = S3.exists(version.export_path)

if not exists:
Expand Down
14 changes: 14 additions & 0 deletions core/integration_tests/tests_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,20 @@ def test_get_204(self, s3_exists_mock):
self.assertEqual(response.status_code, 204)
s3_exists_mock.assert_called_once_with("username/coll_v1.{}.zip".format(self.v1_updated_at))

@patch('core.common.services.S3.exists')
def test_get_208(self, s3_exists_mock):
self.collection_v1._background_process_ids = ['blah'] # pylint: disable=protected-access
self.collection_v1.save()

response = self.client.get(
'/collections/coll/v1/export/',
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 208)
s3_exists_mock.assert_not_called()

@patch('core.common.services.S3.url_for')
@patch('core.common.services.S3.exists')
def test_get_303(self, s3_exists_mock, s3_url_for_mock):
Expand Down
14 changes: 14 additions & 0 deletions core/integration_tests/tests_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@ def test_get_204(self, s3_exists_mock):
self.assertEqual(response.status_code, 204)
s3_exists_mock.assert_called_once_with("username/source1_v1.{}.zip".format(self.v1_updated_at))

@patch('core.common.services.S3.exists')
def test_get_208(self, s3_exists_mock):
self.source_v1._background_process_ids = ['blah'] # pylint: disable=protected-access
self.source_v1.save()

response = self.client.get(
'/sources/source1/v1/export/',
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 208)
s3_exists_mock.assert_not_called()

@patch('core.common.services.S3.url_for')
@patch('core.common.services.S3.exists')
def test_get_303(self, s3_exists_mock, s3_url_for_mock):
Expand Down

0 comments on commit 4304e23

Please sign in to comment.