Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_update_status.py
Show All 22 Lines | def setUp(self): | ||||
super().setUp() | super().setUp() | ||||
deposit = Deposit(status=DEPOSIT_STATUS_VERIFIED, | deposit = Deposit(status=DEPOSIT_STATUS_VERIFIED, | ||||
collection=self.collection, | collection=self.collection, | ||||
client=self.user) | client=self.user) | ||||
deposit.save() | deposit.save() | ||||
self.deposit = Deposit.objects.get(pk=deposit.id) | self.deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert self.deposit.status == DEPOSIT_STATUS_VERIFIED | assert self.deposit.status == DEPOSIT_STATUS_VERIFIED | ||||
def private_deposit_url(self, deposit_id): | |||||
return reverse(PRIVATE_PUT_DEPOSIT, | |||||
args=[self.collection.name, deposit_id]) | |||||
def test_update_deposit_status(self): | def test_update_deposit_status(self): | ||||
"""Existing status for update should return a 204 response | """Existing status for update should return a 204 response | ||||
""" | """ | ||||
url = reverse(PRIVATE_PUT_DEPOSIT, | url = self.private_deposit_url(self.deposit.id) | ||||
args=[self.collection.name, self.deposit.id]) | |||||
possible_status = set(DEPOSIT_STATUS_DETAIL.keys()) - set( | possible_status = set(DEPOSIT_STATUS_DETAIL.keys()) - set( | ||||
[DEPOSIT_STATUS_LOAD_SUCCESS]) | [DEPOSIT_STATUS_LOAD_SUCCESS]) | ||||
for _status in possible_status: | for _status in possible_status: | ||||
response = self.client.put( | response = self.client.put( | ||||
url, | url, | ||||
content_type='application/json', | content_type='application/json', | ||||
data=json.dumps({'status': _status})) | data=json.dumps({'status': _status})) | ||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) | self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) | ||||
deposit = Deposit.objects.get(pk=self.deposit.id) | deposit = Deposit.objects.get(pk=self.deposit.id) | ||||
self.assertEqual(deposit.status, _status) | self.assertEqual(deposit.status, _status) | ||||
def test_update_deposit_status_with_info(self): | def test_update_deposit_status_with_info(self): | ||||
"""Existing status for update with info should return a 204 response | """Existing status for update with info should return a 204 response | ||||
""" | """ | ||||
url = reverse(PRIVATE_PUT_DEPOSIT, | url = self.private_deposit_url(self.deposit.id) | ||||
args=[self.collection.name, self.deposit.id]) | |||||
expected_status = DEPOSIT_STATUS_LOAD_SUCCESS | expected_status = DEPOSIT_STATUS_LOAD_SUCCESS | ||||
origin_url = 'something' | origin_url = 'something' | ||||
directory_id = '42a13fc721c8716ff695d0d62fc851d641f3a12b' | directory_id = '42a13fc721c8716ff695d0d62fc851d641f3a12b' | ||||
revision_id = '47dc6b4636c7f6cba0df83e3d5490bf4334d987e' | revision_id = '47dc6b4636c7f6cba0df83e3d5490bf4334d987e' | ||||
expected_swh_id = 'swh:1:dir:%s' % directory_id | expected_swh_id = 'swh:1:dir:%s' % directory_id | ||||
expected_swh_id_context = 'swh:1:dir:%s;origin=%s' % ( | expected_swh_id_context = 'swh:1:dir:%s;origin=%s' % ( | ||||
directory_id, origin_url) | directory_id, origin_url) | ||||
Show All 20 Lines | def test_update_deposit_status_with_info(self): | ||||
self.assertEqual(deposit.swh_anchor_id, expected_swh_anchor_id) | self.assertEqual(deposit.swh_anchor_id, expected_swh_anchor_id) | ||||
self.assertEqual(deposit.swh_anchor_id_context, | self.assertEqual(deposit.swh_anchor_id_context, | ||||
expected_swh_anchor_id_context) | expected_swh_anchor_id_context) | ||||
def test_update_deposit_status_will_fail_with_unknown_status(self): | def test_update_deposit_status_will_fail_with_unknown_status(self): | ||||
"""Unknown status for update should return a 400 response | """Unknown status for update should return a 400 response | ||||
""" | """ | ||||
url = reverse(PRIVATE_PUT_DEPOSIT, | url = self.private_deposit_url(self.deposit.id) | ||||
args=[self.collection.name, self.deposit.id]) | |||||
response = self.client.put( | response = self.client.put( | ||||
url, | url, | ||||
content_type='application/json', | content_type='application/json', | ||||
data=json.dumps({'status': 'unknown'})) | data=json.dumps({'status': 'unknown'})) | ||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||||
def test_update_deposit_status_will_fail_with_no_status_key(self): | def test_update_deposit_status_will_fail_with_no_status_key(self): | ||||
"""No status provided for update should return a 400 response | """No status provided for update should return a 400 response | ||||
""" | """ | ||||
url = reverse(PRIVATE_PUT_DEPOSIT, | url = self.private_deposit_url(self.deposit.id) | ||||
args=[self.collection.name, self.deposit.id]) | |||||
response = self.client.put( | response = self.client.put( | ||||
url, | url, | ||||
content_type='application/json', | content_type='application/json', | ||||
data=json.dumps({'something': 'something'})) | data=json.dumps({'something': 'something'})) | ||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||||
def test_update_deposit_status_success_without_swh_id_fail(self): | def test_update_deposit_status_success_without_swh_id_fail(self): | ||||
"""Providing successful status without swh_id should return a 400 | """Providing successful status without swh_id should return a 400 | ||||
""" | """ | ||||
url = reverse(PRIVATE_PUT_DEPOSIT, | url = self.private_deposit_url(self.deposit.id) | ||||
args=[self.collection.name, self.deposit.id]) | |||||
response = self.client.put( | response = self.client.put( | ||||
url, | url, | ||||
content_type='application/json', | content_type='application/json', | ||||
data=json.dumps({'status': DEPOSIT_STATUS_LOAD_SUCCESS})) | data=json.dumps({'status': DEPOSIT_STATUS_LOAD_SUCCESS})) | ||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||||
class UpdateDepositStatusTest2(UpdateDepositStatusTest): | |||||
def private_deposit_url(self, deposit_id): | |||||
ardumont: "here we are" | |||||
return reverse(PRIVATE_PUT_DEPOSIT+'-nc', args=[deposit_id]) |
"here we are"