Skip to content

Commit

Permalink
tests: check bucket metadata and locked status
Browse files Browse the repository at this point in the history
Signed-off-by: Parth Shandilya <parth.shandilya@cern.ch>
  • Loading branch information
ParthS007 authored and pamfilos committed Jul 24, 2023
1 parent 2873515 commit 48707de
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/deposits/test_files_for_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from pytest import mark
from six import BytesIO

from cap.modules.deposit.api import CAPDeposit

#########################################
# api/deposits/{pid}/files [GET]
Expand Down Expand Up @@ -572,6 +573,51 @@ def test_put_header_invalid_tags(client, users, auth_headers_for_user,
assert resp.status_code == 400


def test_bucket_locked_status(client, users, auth_headers_for_user, create_deposit):
owner = users['cms_user']
headers = auth_headers_for_user(owner)
deposit = create_deposit(owner, 'test', experiment='CMS')
depid = deposit['_deposit']['id']
deposit_bucket = deposit.files.bucket
assert deposit_bucket.locked is False

# Upload file
client.put('/files/{}/file_1.txt'.format(deposit_bucket),
input_stream=BytesIO(b'Hello world!'),
headers=headers)

client.post('/deposits/{}/actions/publish'.format(depid), headers=headers)
assert deposit_bucket.locked is True

deposit = CAPDeposit.get_record(deposit.id)
assert deposit.files.bucket.locked == True

_, record = deposit.fetch_published()
record_bucket = record.files.bucket
assert record_bucket.locked == True
resp_put = client.put('/files/{}/file_2.txt'.format(record_bucket),
input_stream=BytesIO(b'Hello brave new world!'),
headers=headers)
assert resp_put.status_code == 403

# check the record contains different bucket
assert deposit_bucket != record_bucket

# check the content of record_bucket matched the get record `files` response
resp = client.get('/records/{}'.format(record['control_number']),
headers=auth_headers_for_user(owner))

rec_files = resp.json.get('files')
assert len(rec_files) == len(record_bucket.objects)

# Check the response object has same metadata as the bucket
assert rec_files[0].get('key') == record_bucket.objects[0].key
assert rec_files[0].get('version_id') == str(record_bucket.objects[0].version_id)
assert rec_files[0].get('mimetype') == record_bucket.objects[0].mimetype
assert rec_files[0].get('size') == record_bucket.objects[0].file.size
assert rec_files[0].get('checksum') == record_bucket.objects[0].file.checksum


#########################################
# api/files/{bucket_id}/{filekey} [DELETE]
#########################################
Expand Down

0 comments on commit 48707de

Please sign in to comment.