Skip to content

Commit

Permalink
test list blobs with metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
xiafu-msft committed Sep 4, 2020
1 parent d934c20 commit 11b96b9
Show file tree
Hide file tree
Showing 2 changed files with 256 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:52 GMT
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b?restype=container
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ContainerAlreadyExists</Code><Message>The
specified container already exists.\nRequestId:4d6b1fbe-501e-0079-7c95-77b184000000\nTime:2020-08-21T08:34:52.7820585Z</Message></Error>"
headers:
content-length:
- '230'
content-type:
- application/xml
date:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-error-code:
- ContainerAlreadyExists
x-ms-version:
- '2019-12-12'
status:
code: 409
message: The specified container already exists.
- request:
body: hello world
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '11'
Content-Type:
- application/octet-stream
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-blob-content-disposition:
- inline
x-ms-blob-content-language:
- spanish
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Fri, 21 Aug 2020 08:34:52 GMT
x-ms-meta-name:
- bob
x-ms-meta-number:
- '1'
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob1
response:
body:
string: ''
headers:
content-length:
- '0'
content-md5:
- XrY7u+Ae7tCTyyK7j1rNww==
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD135C55E0"'
last-modified:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- vo7q9sPVKY0=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:52.9412336Z'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob1?comp=snapshot
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD135C55E0"'
last-modified:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-server-encrypted:
- 'false'
x-ms-snapshot:
- '2020-08-21T08:34:53.0423049Z'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:53.0433049Z'
status:
code: 201
message: Created
- request:
body: hello world
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '11'
Content-Type:
- application/octet-stream
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-blob-content-disposition:
- inline
x-ms-blob-content-language:
- spanish
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-meta-name:
- car
x-ms-meta-number:
- '2'
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob2
response:
body:
string: ''
headers:
content-length:
- '0'
content-md5:
- XrY7u+Ae7tCTyyK7j1rNww==
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD137CDC23"'
last-modified:
- Fri, 21 Aug 2020 08:34:53 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- vo7q9sPVKY0=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:53.1543859Z'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- application/xml
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-version:
- '2019-12-12'
method: GET
uri: https://storagename.blob.core.windows.net/container3851155b?include=metadata&restype=container&comp=list
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults
ServiceEndpoint=\"https://storagename.blob.core.windows.net/\" ContainerName=\"container3851155b\"><Blobs><Blob><Name>blob1</Name><VersionId>2020-08-21T08:34:53.0433049Z</VersionId><IsCurrentVersion>true</IsCurrentVersion><Properties><Creation-Time>Fri,
21 Aug 2020 08:34:52 GMT</Creation-Time><Last-Modified>Fri, 21 Aug 2020 08:34:52
GMT</Last-Modified><Etag>0x8D845AD135C55E0</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language>spanish</Content-Language><Content-CRC64 /><Content-MD5>XrY7u+Ae7tCTyyK7j1rNww==</Content-MD5><Cache-Control
/><Content-Disposition>inline</Content-Disposition><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><ServerEncrypted>true</ServerEncrypted></Properties><Metadata><number>1</number><name>bob</name></Metadata><OrMetadata
/></Blob><Blob><Name>blob2</Name><VersionId>2020-08-21T08:34:53.1543859Z</VersionId><IsCurrentVersion>true</IsCurrentVersion><Properties><Creation-Time>Fri,
21 Aug 2020 08:34:53 GMT</Creation-Time><Last-Modified>Fri, 21 Aug 2020 08:34:53
GMT</Last-Modified><Etag>0x8D845AD137CDC23</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language>spanish</Content-Language><Content-CRC64 /><Content-MD5>XrY7u+Ae7tCTyyK7j1rNww==</Content-MD5><Cache-Control
/><Content-Disposition>inline</Content-Disposition><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><ServerEncrypted>true</ServerEncrypted></Properties><Metadata><number>2</number><name>car</name></Metadata><OrMetadata
/></Blob></Blobs><NextMarker /></EnumerationResults>"
headers:
content-type:
- application/xml
date:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-ms-version:
- '2019-12-12'
status:
code: 200
message: OK
version: 1
14 changes: 10 additions & 4 deletions sdk/storage/azure-storage-blob/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PremiumPageBlobTier,
generate_container_sas,
PartialBatchErrorException,
generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient)
generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient, ContentSettings)

#------------------------------------------------------------------------------
TEST_CONTAINER_PREFIX = 'container'
Expand Down Expand Up @@ -974,13 +974,17 @@ def test_list_blobs_with_include_snapshots(self, resource_group, location, stora
@GlobalStorageAccountPreparer()
def test_list_blobs_with_include_metadata(self, resource_group, location, storage_account, storage_account_key):
bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
pytest.skip("Waiting on metadata XML fix in msrest")
# pytest.skip("Waiting on metadata XML fix in msrest")
container = self._create_container(bsc)
data = b'hello world'
content_settings = ContentSettings(
content_language='spanish',
content_disposition='inline')
blob1 = container.get_blob_client('blob1')
blob1.upload_blob(data, metadata={'number': '1', 'name': 'bob'})
blob1.upload_blob(data, overwrite=True, content_settings=content_settings, metadata={'number': '1', 'name': 'bob'})
blob1.create_snapshot()
container.get_blob_client('blob2').upload_blob(data, metadata={'number': '2', 'name': 'car'})

container.get_blob_client('blob2').upload_blob(data, overwrite=True, content_settings=content_settings, metadata={'number': '2', 'name': 'car'})

# Act
blobs =list(container.list_blobs(include="metadata"))
Expand All @@ -993,6 +997,8 @@ def test_list_blobs_with_include_metadata(self, resource_group, location, storag
self.assertEqual(blobs[1].name, 'blob2')
self.assertEqual(blobs[1].metadata['number'], '2')
self.assertEqual(blobs[1].metadata['name'], 'car')
self.assertEqual(blobs[1].content_settings.content_language, 'spanish')
self.assertEqual(blobs[1].content_settings.content_disposition, 'inline')

@GlobalStorageAccountPreparer()
def test_list_blobs_with_include_uncommittedblobs(self, resource_group, location, storage_account, storage_account_key):
Expand Down

0 comments on commit 11b96b9

Please sign in to comment.