Skip to content

Commit

Permalink
Issue-572 | source/collection export get doesn't wait for processing …
Browse files Browse the repository at this point in the history
…flag
  • Loading branch information
snyaggarwal committed Feb 23, 2021
1 parent 6079f02 commit ee5838a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 46 deletions.
33 changes: 15 additions & 18 deletions core/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,28 +506,25 @@ 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)
if version.has_export():
export_url = version.get_export_url()

if not version.has_export():
return Response(status=status.HTTP_204_NO_CONTENT)
no_redirect = request.query_params.get('noRedirect', False) in ['true', 'True', True]
if no_redirect:
return Response(dict(url=export_url), status=status.HTTP_200_OK)

export_url = version.get_export_url()
response = Response(status=status.HTTP_303_SEE_OTHER)
response['Location'] = export_url

no_redirect = request.query_params.get('noRedirect', False) in ['true', 'True', True]
if no_redirect:
return Response(dict(url=export_url), status=status.HTTP_200_OK)
# Set headers to ensure sure response is not cached by a client
response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response['Pragma'] = 'no-cache'
response['Expires'] = '0'
response['Last-Updated'] = version.last_child_update.isoformat()
response['Last-Updated-Timezone'] = settings.TIME_ZONE_PLACE
return response

response = Response(status=status.HTTP_303_SEE_OTHER)
response['Location'] = export_url

# Set headers to ensure sure response is not cached by a client
response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response['Pragma'] = 'no-cache'
response['Expires'] = '0'
response['Last-Updated'] = version.last_child_update.isoformat()
response['Last-Updated-Timezone'] = settings.TIME_ZONE_PLACE
return response
return Response(status=status.HTTP_204_NO_CONTENT)

def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
version = self.get_object()
Expand Down
14 changes: 0 additions & 14 deletions core/integration_tests/tests_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,20 +817,6 @@ 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: 0 additions & 14 deletions core/integration_tests/tests_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,20 +560,6 @@ 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 ee5838a

Please sign in to comment.