Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_binary.py
Show All 10 Lines | |||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.test import APITestCase | from rest_framework.test import APITestCase | ||||
from swh.deposit.tests import TEST_CONFIG | from swh.deposit.tests import TEST_CONFIG | ||||
from swh.deposit.config import COL_IRI, EM_IRI | from swh.deposit.config import COL_IRI, EM_IRI | ||||
from swh.deposit.config import DEPOSIT_STATUS_DEPOSITED | from swh.deposit.config import DEPOSIT_STATUS_DEPOSITED | ||||
from swh.deposit.models import Deposit, DepositRequest | from swh.deposit.models import Deposit, DepositRequest | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from ..common import BasicTestCase, WithAuthTestCase, create_arborescence_zip | from ..common import BasicTestCase, WithAuthTestCase, create_arborescence_archive | ||||
from ..common import FileSystemCreationRoutine | from ..common import FileSystemCreationRoutine | ||||
class DepositTestCase(APITestCase, WithAuthTestCase, BasicTestCase, | class DepositTestCase(APITestCase, WithAuthTestCase, BasicTestCase, | ||||
FileSystemCreationRoutine): | FileSystemCreationRoutine): | ||||
"""Try and upload one single deposit | """Try and upload one single deposit | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | </entry>""" | ||||
def post_deposit_binary_upload_fail_if_upload_size_limit_exceeded( | def post_deposit_binary_upload_fail_if_upload_size_limit_exceeded( | ||||
self): | self): | ||||
"""Binary upload must not exceed the limit set up... | """Binary upload must not exceed the limit set up... | ||||
""" | """ | ||||
# given | # given | ||||
url = reverse(COL_IRI, args=[self.collection.name]) | url = reverse(COL_IRI, args=[self.collection.name]) | ||||
archive = create_arborescence_zip( | archive = create_arborescence_archive( | ||||
self.root_path, 'archive2', 'file2', b'some content in file', | self.root_path, 'archive2', 'file2', b'some content in file', | ||||
up_to_size=TEST_CONFIG['max_upload_size']) | up_to_size=TEST_CONFIG['max_upload_size']) | ||||
external_id = 'some-external-id' | external_id = 'some-external-id' | ||||
# when | # when | ||||
response = self.client.post( | response = self.client.post( | ||||
url, | url, | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | def post_deposit_binary_and_post_to_add_another_archive(self): | ||||
self.assertIsNone(deposit.swh_id) | self.assertIsNone(deposit.swh_id) | ||||
deposit_request = DepositRequest.objects.get(deposit=deposit) | deposit_request = DepositRequest.objects.get(deposit=deposit) | ||||
self.assertEquals(deposit_request.deposit, deposit) | self.assertEquals(deposit_request.deposit, deposit) | ||||
self.assertEquals(deposit_request.type.name, 'archive') | self.assertEquals(deposit_request.type.name, 'archive') | ||||
self.assertRegex(deposit_request.archive.name, self.archive['name']) | self.assertRegex(deposit_request.archive.name, self.archive['name']) | ||||
# 2nd archive to upload | # 2nd archive to upload | ||||
archive2 = create_arborescence_zip( | archive2 = create_arborescence_archive( | ||||
self.root_path, 'archive2', 'file2', b'some other content in file') | self.root_path, 'archive2', 'file2', b'some other content in file') | ||||
# uri to update the content | # uri to update the content | ||||
update_uri = reverse(EM_IRI, args=[self.collection.name, deposit_id]) | update_uri = reverse(EM_IRI, args=[self.collection.name, deposit_id]) | ||||
# adding another archive for the deposit and finalizing it | # adding another archive for the deposit and finalizing it | ||||
response = self.client.post( | response = self.client.post( | ||||
update_uri, | update_uri, | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | def post_deposit_then_post_or_put_is_refused_when_status_ready(self): | ||||
edit_se_iri = reverse( | edit_se_iri = reverse( | ||||
'edit_se_iri', args=[self.collection.name, deposit_id]) | 'edit_se_iri', args=[self.collection.name, deposit_id]) | ||||
em_iri = reverse( | em_iri = reverse( | ||||
'em_iri', args=[self.collection.name, deposit_id]) | 'em_iri', args=[self.collection.name, deposit_id]) | ||||
# Testing all update/add endpoint should fail | # Testing all update/add endpoint should fail | ||||
# since the status is ready | # since the status is ready | ||||
archive2 = create_arborescence_zip( | archive2 = create_arborescence_archive( | ||||
self.root_path, 'archive2', 'file2', b'some content in file 2') | self.root_path, 'archive2', 'file2', b'some content in file 2') | ||||
# replacing file is no longer possible since the deposit's | # replacing file is no longer possible since the deposit's | ||||
# status is ready | # status is ready | ||||
r = self.client.put( | r = self.client.put( | ||||
em_iri, | em_iri, | ||||
content_type='application/zip', | content_type='application/zip', | ||||
data=archive2['data'], | data=archive2['data'], | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |