Skip to content

Commit

Permalink
add unittests for s3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Aug 2, 2023
1 parent 5b7ca19 commit e627806
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/providers/s3/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ async def test_validate_v1_path_file(self, provider, file_header_metadata, mock_

assert wb_path_v1 == wb_path_v0

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_file_with_subfolder(self, provider, file_header_metadata, mock_time):
file_path = '/my-subfolder/foobah'
provider.settings['id'] = 'the-bucket:/my-subfolder/'

good_metadata_url = provider.bucket.new_key(file_path).generate_url(100, 'HEAD')
aiohttpretty.register_uri('HEAD', good_metadata_url, headers=file_header_metadata)

assert WaterButlerPath('/my-subfolder/') == await provider.validate_v1_path('/')
wb_path_v1 = await provider.validate_v1_path(file_path)
wb_path_v0 = await provider.validate_path(file_path)

assert wb_path_v1 == wb_path_v0

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_folder(self, provider, folder_metadata, mock_time):
Expand Down Expand Up @@ -383,6 +398,35 @@ async def test_download_folder_400s(self, provider, mock_time):
await provider.download(WaterButlerPath('/cool/folder/mom/'))
assert e.value.code == 400

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_upload_to_subfolder_as_root(self,
provider,
file_content,
file_stream,
file_header_metadata,
mock_time
):

provider.settings['id'] = 'the-bucket:/my-subfolder/'
path = WaterButlerPath('/my-subfolder/foobah')

content_md5 = hashlib.md5(file_content).hexdigest()

url = provider.bucket.new_key(path.path).generate_url(100, 'PUT')
metadata_url = provider.bucket.new_key(path.path).generate_url(100, 'HEAD')
aiohttpretty.register_uri('HEAD', metadata_url, headers=file_header_metadata)
header = {'ETag': f'"{content_md5}"'}
aiohttpretty.register_uri('PUT', url, status=201, headers=header)

metadata, created = await provider.upload(file_stream, path)

assert metadata.kind == 'file'
assert metadata.path == '/my-subfolder/foobah'
assert not created
assert aiohttpretty.has_call(method='PUT', uri=url)
assert aiohttpretty.has_call(method='HEAD', uri=metadata_url)

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_upload_update(self,
Expand Down

0 comments on commit e627806

Please sign in to comment.