diff --git a/sdk/storage/azure-storage-queue/README.md b/sdk/storage/azure-storage-queue/README.md index 9411c72f900d..cd90862ccbfb 100644 --- a/sdk/storage/azure-storage-queue/README.md +++ b/sdk/storage/azure-storage-queue/README.md @@ -114,6 +114,13 @@ from azure.storage.queue import QueueClient queue = QueueClient.from_connection_string(conn_str="my_connection_string", queue="myqueue") queue.create_queue() ``` +Create a queue asynchronously. +```python +from azure.storage.queue.aio import QueueClient + +queue = QueueClient.from_connection_string(conn_str="my_connection_string", queue="myqueue") +await queue.create_queue() +``` ### Enqueue messages Enqueue a message in your queue. @@ -124,6 +131,15 @@ queue = QueueClient.from_connection_string(conn_str="my_connection_string", queu queue.enqueue_message("I'm using queues!") queue.enqueue_message("This is my second message") ``` +Enqueue messages with an async client +```python +from azure.storage.queue.aio import QueueClient + +queue = QueueClient.from_connection_string(conn_str="my_connection_string", queue="myqueue") +await asyncio.gather( + queue.enqueue_message("I'm using queues!"), + queue.enqueue_message("This is my second message")) +``` ### Receive messages Receive messages from your queue. @@ -136,11 +152,34 @@ response = queue.receive_messages() for message in response: print(message.content) + queue.delete_message(message) # Printed messages from the front of the queue # >>I'm using queues! # >>This is my second message ``` +Receive messages by batch. +```python +queue = QueueClient.from_connection_string(conn_str="my_connection_string", queue="myqueue") +response = queue.receive_messages(messages_per_page=10) + +for message_batch in response.by_page(): + for message in message_batch: + print(message.content) + queue.delete_message(message) +``` +Receive messages asynchronously: +```python +from azure.storage.queue.aio import QueueClient + +queue = QueueClient.from_connection_string(conn_str="my_connection_string", queue="myqueue") +response = queue.receive_messages() + +async for message in response: + print(message.content) + await queue.delete_message(message) + +``` ## Troubleshooting Storage Queue clients raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/docs/exceptions.md). @@ -154,25 +193,25 @@ Get started with our [Queue samples](https://github.com/Azure/azure-sdk-for-pyth Several Storage Queues Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Storage Queues: -* [`test_queue_samples_hello_world.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world.py) - Examples found in this article: +* [`test_queue_samples_hello_world.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world_async.py)) - Examples found in this article: * Client creation * Create a queue * Enqueue messages * Receive messages -* [`test_queue_samples_authentication.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py) - Examples for authenticating and creating the client: +* [`test_queue_samples_authentication.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication_async.py)) - Examples for authenticating and creating the client: * From a connection string * From a shared access key * From a shared access signature token * From active directory -* [`test_queue_samples_service.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py) - Examples for interacting with the queue service: +* [`test_queue_samples_service.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_service_async.py)) - Examples for interacting with the queue service: * Get and set service properties * List queues in a storage account * Create and delete a queue from the service * Get the QueueClient -* [`test_queue_samples_message.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py) - Examples for working with queues and messages: +* [`test_queue_samples_message.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-queue/tests/test_queue_samples_message_async.py)) - Examples for working with queues and messages: * Set an access policy * Get and set queue metadata * Enqueue and receive messages diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py index 00ab0b454154..e370da036795 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py @@ -85,12 +85,19 @@ class QueueClient(AsyncStorageAccountHostsMixin, QueueClientBase): shared access key, or an instance of a TokenCredentials class from azure.identity. Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START create_queue_client] - :end-before: [END create_queue_client] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_create_queue_client] + :end-before: [END async_create_queue_client] :language: python :dedent: 12 :caption: Create the queue client with url and credential. + + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_create_queue_client_from_connection_string] + :end-before: [END async_create_queue_client_from_connection_string] + :language: python + :dedent: 8 + :caption: Create the queue client with a connection string. """ def __init__( @@ -127,9 +134,9 @@ async def create_queue(self, metadata=None, timeout=None, **kwargs): # type: ig ~azure.storage.queue._generated.models._models.StorageErrorException Example: - .. literalinclude:: ../tests/test_queue_samples_hello_world.py - :start-after: [START create_queue] - :end-before: [END create_queue] + .. literalinclude:: ../tests/test_queue_samples_hello_world_async.py + :start-after: [START async_create_queue] + :end-before: [END async_create_queue] :language: python :dedent: 8 :caption: Create a queue. @@ -161,9 +168,9 @@ async def delete_queue(self, timeout=None, **kwargs): # type: ignore :rtype: None Example: - .. literalinclude:: ../tests/test_queue_samples_hello_world.py - :start-after: [START delete_queue] - :end-before: [END delete_queue] + .. literalinclude:: ../tests/test_queue_samples_hello_world_async.py + :start-after: [START async_delete_queue] + :end-before: [END async_delete_queue] :language: python :dedent: 12 :caption: Delete a queue. @@ -186,9 +193,9 @@ async def get_queue_properties(self, timeout=None, **kwargs): # type: ignore :rtype: ~azure.storage.queue.models.QueueProperties Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START get_queue_properties] - :end-before: [END get_queue_properties] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_get_queue_properties] + :end-before: [END async_get_queue_properties] :language: python :dedent: 12 :caption: Get the properties on the queue. @@ -217,9 +224,9 @@ async def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): # ty The server timeout, expressed in seconds. Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START set_queue_metadata] - :end-before: [END set_queue_metadata] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_set_queue_metadata] + :end-before: [END async_set_queue_metadata] :language: python :dedent: 12 :caption: Set metadata on the queue. @@ -278,9 +285,9 @@ async def set_queue_access_policy(self, signed_identifiers=None, timeout=None, * The server timeout, expressed in seconds. Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START set_access_policy] - :end-before: [END set_access_policy] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_set_access_policy] + :end-before: [END async_set_access_policy] :language: python :dedent: 12 :caption: Set an access policy on the queue. @@ -350,9 +357,9 @@ async def enqueue_message( # type: ignore :rtype: ~azure.storage.queue.models.QueueMessage Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START enqueue_messages] - :end-before: [END enqueue_messages] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_enqueue_messages] + :end-before: [END async_enqueue_messages] :language: python :dedent: 12 :caption: Enqueue messages. @@ -414,9 +421,9 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.queue.models.Message] Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START receive_messages] - :end-before: [END receive_messages] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_receive_messages] + :end-before: [END async_receive_messages] :language: python :dedent: 12 :caption: Receive messages from the queue. @@ -484,9 +491,9 @@ async def update_message( :rtype: ~azure.storage.queue.models.QueueMessage Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START update_message] - :end-before: [END update_message] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_update_message] + :end-before: [END async_update_message] :language: python :dedent: 12 :caption: Update a message. @@ -567,9 +574,9 @@ async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # typ :rtype: list(:class:`~azure.storage.queue.models.QueueMessage`) Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START peek_message] - :end-before: [END peek_message] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_peek_message] + :end-before: [END async_peek_message] :language: python :dedent: 12 :caption: Peek messages. @@ -599,9 +606,9 @@ async def clear_messages(self, timeout=None, **kwargs): # type: ignore The server timeout, expressed in seconds. Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START clear_messages] - :end-before: [END clear_messages] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_clear_messages] + :end-before: [END async_clear_messages] :language: python :dedent: 12 :caption: Clears all messages. @@ -635,9 +642,9 @@ async def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs The server timeout, expressed in seconds. Example: - .. literalinclude:: ../tests/test_queue_samples_message.py - :start-after: [START delete_message] - :end-before: [END delete_message] + .. literalinclude:: ../tests/test_queue_samples_message_async.py + :start-after: [START async_delete_message] + :end-before: [END async_delete_message] :language: python :dedent: 12 :caption: Delete a message. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py index 409888af1146..0e57858ea5cd 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py @@ -75,12 +75,19 @@ class QueueServiceClient(AsyncStorageAccountHostsMixin, QueueServiceClientBase): shared access key, or an instance of a TokenCredentials class from azure.identity. Example: - .. literalinclude:: ../tests/test_queue_samples_authentication.py - :start-after: [START create_queue_service_client] - :end-before: [END create_queue_service_client] + .. literalinclude:: ../tests/test_queue_samples_authentication_async.py + :start-after: [START async_create_queue_service_client] + :end-before: [END async_create_queue_service_client] :language: python :dedent: 8 :caption: Creating the QueueServiceClient with an account url and credential. + + .. literalinclude:: ../tests/test_queue_samples_authentication_async.py + :start-after: [START async_create_queue_service_client_token] + :end-before: [END async_create_queue_service_client_token] + :language: python + :dedent: 8 + :caption: Creating the QueueServiceClient with Azure Identity credentials. """ def __init__( @@ -142,9 +149,9 @@ async def get_service_properties(self, timeout=None, **kwargs): # type: ignore :rtype: ~azure.storage.queue._generated.models._models.StorageServiceProperties Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START get_queue_service_properties] - :end-before: [END get_queue_service_properties] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_get_queue_service_properties] + :end-before: [END async_get_queue_service_properties] :language: python :dedent: 8 :caption: Getting queue service properties. @@ -191,9 +198,9 @@ async def set_service_properties( # type: ignore :rtype: None Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START set_queue_service_properties] - :end-before: [END set_queue_service_properties] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_set_queue_service_properties] + :end-before: [END async_set_queue_service_properties] :language: python :dedent: 8 :caption: Setting queue service properties. @@ -238,9 +245,9 @@ def list_queues( :rtype: ~azure.core.paging.AsyncItemPaged[~azure.core.queue.models.QueueProperties] Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START qsc_list_queues] - :end-before: [END qsc_list_queues] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_qsc_list_queues] + :end-before: [END async_qsc_list_queues] :language: python :dedent: 12 :caption: List queues in the service. @@ -277,12 +284,12 @@ async def create_queue( # type: ignore :type metadata: dict(str, str) :param int timeout: The timeout parameter is expressed in seconds. - :rtype: ~azure.storage.queue.queue_client.QueueClient + :rtype: ~azure.storage.queue.aio.queue_client_async.QueueClient Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START qsc_create_queue] - :end-before: [END qsc_create_queue] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_qsc_create_queue] + :end-before: [END async_qsc_create_queue] :language: python :dedent: 8 :caption: Create a queue in the service. @@ -318,9 +325,9 @@ async def delete_queue( # type: ignore :rtype: None Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START qsc_delete_queue] - :end-before: [END qsc_delete_queue] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_qsc_delete_queue] + :end-before: [END async_qsc_delete_queue] :language: python :dedent: 12 :caption: Delete a queue in the service. @@ -339,12 +346,12 @@ def get_queue_client(self, queue, **kwargs): or an instance of QueueProperties. :type queue: str or ~azure.storage.queue.models.QueueProperties :returns: A :class:`~azure.core.queue.queue_client.QueueClient` object. - :rtype: ~azure.core.queue.queue_client.QueueClient + :rtype: ~azure.storage.queue.aio.queue_client_async.QueueClient Example: - .. literalinclude:: ../tests/test_queue_samples_service.py - :start-after: [START get_queue_client] - :end-before: [END get_queue_client] + .. literalinclude:: ../tests/test_queue_samples_service_async.py + :start-after: [START async_get_queue_client] + :end-before: [END async_get_queue_client] :language: python :dedent: 8 :caption: Get the queue client. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py index 9946c77d99d6..58cd13d57b94 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py @@ -80,6 +80,13 @@ class QueueServiceClient(StorageAccountHostsMixin): :language: python :dedent: 8 :caption: Creating the QueueServiceClient with an account url and credential. + + .. literalinclude:: ../tests/test_queue_samples_authentication.py + :start-after: [START create_queue_service_client_token] + :end-before: [END create_queue_service_client_token] + :language: python + :dedent: 8 + :caption: Creating the QueueServiceClient with Azure Identity credentials. """ def __init__( diff --git a/sdk/storage/azure-storage-queue/tests/recordings/test_queue_samples_message.test_enqueue_and_receive_messages.yaml b/sdk/storage/azure-storage-queue/tests/recordings/test_queue_samples_message.test_enqueue_and_receive_messages.yaml index 8962b3d84e81..570bbc0e6a8e 100644 --- a/sdk/storage/azure-storage-queue/tests/recordings/test_queue_samples_message.test_enqueue_and_receive_messages.yaml +++ b/sdk/storage/azure-storage-queue/tests/recordings/test_queue_samples_message.test_enqueue_and_receive_messages.yaml @@ -11,13 +11,13 @@ interactions: Content-Length: - '0' User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) content-type: - application/xml; charset=utf-8 x-ms-client-request-id: - - 98049ae8-b575-11e9-90ac-2816a845e8c6 + - 3cd6ea6c-ba32-11e9-b30c-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:47 GMT + - Thu, 08 Aug 2019 23:14:14 GMT x-ms-version: - '2018-03-28' method: PUT @@ -29,11 +29,11 @@ interactions: Content-Length: - '0' Date: - - Fri, 02 Aug 2019 22:33:47 GMT + - Thu, 08 Aug 2019 23:14:16 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 x-ms-request-id: - - 46026c75-2003-003f-4f82-49d3dc000000 + - 24c6df8d-4003-00ca-133f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -55,32 +55,32 @@ interactions: Content-Type: - application/xml; charset=utf-8 User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) x-ms-client-request-id: - - 9839bb7a-b575-11e9-b3f7-2816a845e8c6 + - 3f090a66-ba32-11e9-b627-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:18 GMT x-ms-version: - '2018-03-28' method: POST uri: https://storagename.queue.core.windows.net/messagequeue/messages response: body: - string: "\uFEFF271eb91f-eddc-460e-a75e-01d4a1ddd6e7Fri, - 02 Aug 2019 22:33:47 GMTFri, 09 Aug 2019 22:33:47 - GMTAgAAAAMAAAAAAAAAuobUWYJJ1QE=Fri, - 02 Aug 2019 22:33:47 GMT" + string: "\uFEFFc6beb214-980a-40e9-84c9-bc20af5a3281Thu, + 08 Aug 2019 23:14:18 GMTThu, 15 Aug 2019 23:14:18 + GMTAgAAAAMAAAAAAAAADoXpAD9O1QE=Thu, + 08 Aug 2019 23:14:18 GMT" headers: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:47 GMT + - Thu, 08 Aug 2019 23:14:18 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: - chunked x-ms-request-id: - - 46026c7e-2003-003f-5482-49d3dc000000 + - 24c6e035-4003-00ca-203f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -102,32 +102,32 @@ interactions: Content-Type: - application/xml; charset=utf-8 User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) x-ms-client-request-id: - - 98465d1c-b575-11e9-bea2-2816a845e8c6 + - 3f8c0ee8-ba32-11e9-8ac4-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:18 GMT x-ms-version: - '2018-03-28' method: POST uri: https://storagename.queue.core.windows.net/messagequeue/messages?visibilitytimeout=30 response: body: - string: "\uFEFF26f00845-a414-41c4-8dfe-8e33e7d7b671Fri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAAh87Ga4JJ1QE=Fri, - 02 Aug 2019 22:34:18 GMT" + string: "\uFEFF1b029463-6d90-4d88-a6bd-85f63fce5883Thu, + 08 Aug 2019 23:14:19 GMTThu, 15 Aug 2019 23:14:19 + GMTAgAAAAMAAAAAAAAAhHNHEz9O1QE=Thu, + 08 Aug 2019 23:14:49 GMT" headers: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:47 GMT + - Thu, 08 Aug 2019 23:14:18 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: - chunked x-ms-request-id: - - 46026c8a-2003-003f-5e82-49d3dc000000 + - 24c6e0d0-4003-00ca-243f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -149,32 +149,32 @@ interactions: Content-Type: - application/xml; charset=utf-8 User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) x-ms-client-request-id: - - 9856579c-b575-11e9-86be-2816a845e8c6 + - 3fce7b9a-ba32-11e9-8336-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:19 GMT x-ms-version: - '2018-03-28' method: POST uri: https://storagename.queue.core.windows.net/messagequeue/messages response: body: - string: "\uFEFFd545c6fc-d2b6-49e1-a590-64d47b3959e1Fri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAAG1HwWYJJ1QE=Fri, - 02 Aug 2019 22:33:48 GMT" + string: "\uFEFF3e2489dd-1b30-4d86-853d-d2fc61ac08a8Thu, + 08 Aug 2019 23:14:19 GMTThu, 15 Aug 2019 23:14:19 + GMTAgAAAAMAAAAAAAAA1p6yAT9O1QE=Thu, + 08 Aug 2019 23:14:19 GMT" headers: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:19 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: - chunked x-ms-request-id: - - 46026c91-2003-003f-6282-49d3dc000000 + - 24c6e129-4003-00ca-763f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -196,32 +196,32 @@ interactions: Content-Type: - application/xml; charset=utf-8 User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) x-ms-client-request-id: - - 9862d236-b575-11e9-b8d1-2816a845e8c6 + - 40566a74-ba32-11e9-b6ca-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:20 GMT x-ms-version: - '2018-03-28' method: POST uri: https://storagename.queue.core.windows.net/messagequeue/messages response: body: - string: "\uFEFF2f739567-eee6-4bdf-a42d-ce7cfc9edff8Fri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAADMH9WYJJ1QE=Fri, - 02 Aug 2019 22:33:48 GMT" + string: "\uFEFF2c64160d-cbf7-4e21-8c30-2d8ce5d5cd90Thu, + 08 Aug 2019 23:14:20 GMTThu, 15 Aug 2019 23:14:20 + GMTAgAAAAMAAAAAAAAAsCYuAj9O1QE=Thu, + 08 Aug 2019 23:14:20 GMT" headers: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:20 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: - chunked x-ms-request-id: - - 46026c94-2003-003f-6582-49d3dc000000 + - 24c6e19c-4003-00ca-623f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -243,32 +243,32 @@ interactions: Content-Type: - application/xml; charset=utf-8 User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) x-ms-client-request-id: - - 986f891a-b575-11e9-a406-2816a845e8c6 + - 410f8c7a-ba32-11e9-9b60-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:21 GMT x-ms-version: - '2018-03-28' method: POST uri: https://storagename.queue.core.windows.net/messagequeue/messages response: body: - string: "\uFEFF5e0f1f2d-eac2-4b39-b2ab-1a637e5382fdFri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAA3LcMWoJJ1QE=Fri, - 02 Aug 2019 22:33:48 GMT" + string: "\uFEFFa8ccfc6e-c4e9-4e45-ad33-1d88ee4a2aecThu, + 08 Aug 2019 23:14:21 GMTThu, 15 Aug 2019 23:14:21 + GMTAgAAAAMAAAAAAAAAy8zrAj9O1QE=Thu, + 08 Aug 2019 23:14:21 GMT" headers: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:21 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: - chunked x-ms-request-id: - - 46026c99-2003-003f-6982-49d3dc000000 + - 24c6e282-4003-00ca-213f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -284,39 +284,216 @@ interactions: Connection: - keep-alive User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) content-type: - application/xml; charset=utf-8 x-ms-client-request-id: - - 987db01a-b575-11e9-baba-2816a845e8c6 + - 416e63da-ba32-11e9-b321-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:22 GMT x-ms-version: - '2018-03-28' method: GET - uri: https://storagename.queue.core.windows.net/messagequeue/messages?numofmessages=5 + uri: https://storagename.queue.core.windows.net/messagequeue/messages + response: + body: + string: "\uFEFFc6beb214-980a-40e9-84c9-bc20af5a3281Thu, + 08 Aug 2019 23:14:18 GMTThu, 15 Aug 2019 23:14:18 + GMTAgAAAAMAAAAAAAAAoKwyFT9O1QE=Thu, + 08 Aug 2019 23:14:52 GMT1message1" + headers: + Cache-Control: + - no-cache + Content-Type: + - application/xml + Date: + - Thu, 08 Aug 2019 23:14:22 GMT + Server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + Transfer-Encoding: + - chunked + Vary: + - Origin + x-ms-request-id: + - 24c6e31b-4003-00ca-163f-4ef7cd000000 + x-ms-version: + - '2018-03-28' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) + content-type: + - application/xml; charset=utf-8 + x-ms-client-request-id: + - 41eed63a-ba32-11e9-8137-b831b5891408 + x-ms-date: + - Thu, 08 Aug 2019 23:14:22 GMT + x-ms-version: + - '2018-03-28' + method: GET + uri: https://storagename.queue.core.windows.net/messagequeue/messages + response: + body: + string: "\uFEFF3e2489dd-1b30-4d86-853d-d2fc61ac08a8Thu, + 08 Aug 2019 23:14:19 GMTThu, 15 Aug 2019 23:14:19 + GMTAgAAAAMAAAAAAAAADAK0FT9O1QE=Thu, + 08 Aug 2019 23:14:53 GMT1message3" + headers: + Cache-Control: + - no-cache + Content-Type: + - application/xml + Date: + - Thu, 08 Aug 2019 23:14:22 GMT + Server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + Transfer-Encoding: + - chunked + Vary: + - Origin + x-ms-request-id: + - 24c6e3da-4003-00ca-3c3f-4ef7cd000000 + x-ms-version: + - '2018-03-28' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) + content-type: + - application/xml; charset=utf-8 + x-ms-client-request-id: + - 425866cc-ba32-11e9-9ff2-b831b5891408 + x-ms-date: + - Thu, 08 Aug 2019 23:14:23 GMT + x-ms-version: + - '2018-03-28' + method: GET + uri: https://storagename.queue.core.windows.net/messagequeue/messages response: body: - string: "\uFEFF271eb91f-eddc-460e-a75e-01d4a1ddd6e7Fri, - 02 Aug 2019 22:33:47 GMTFri, 09 Aug 2019 22:33:47 - GMTAgAAAAMAAAAAAAAA/mr6a4JJ1QE=Fri, - 02 Aug 2019 22:34:18 GMT1message1d545c6fc-d2b6-49e1-a590-64d47b3959e1Fri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAA/mr6a4JJ1QE=Fri, - 02 Aug 2019 22:34:18 GMT1message32f739567-eee6-4bdf-a42d-ce7cfc9edff8Fri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAA/mr6a4JJ1QE=Fri, - 02 Aug 2019 22:34:18 GMT1message45e0f1f2d-eac2-4b39-b2ab-1a637e5382fdFri, - 02 Aug 2019 22:33:48 GMTFri, 09 Aug 2019 22:33:48 - GMTAgAAAAMAAAAAAAAA/mr6a4JJ1QE=Fri, - 02 Aug 2019 22:34:18 GMT1message5" + string: "\uFEFF2c64160d-cbf7-4e21-8c30-2d8ce5d5cd90Thu, + 08 Aug 2019 23:14:20 GMTThu, 15 Aug 2019 23:14:20 + GMTAgAAAAMAAAAAAAAAHdsZFj9O1QE=Thu, + 08 Aug 2019 23:14:53 GMT1message4" + headers: + Cache-Control: + - no-cache + Content-Type: + - application/xml + Date: + - Thu, 08 Aug 2019 23:14:23 GMT + Server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + Transfer-Encoding: + - chunked + Vary: + - Origin + x-ms-request-id: + - 24c6e42d-4003-00ca-083f-4ef7cd000000 + x-ms-version: + - '2018-03-28' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) + content-type: + - application/xml; charset=utf-8 + x-ms-client-request-id: + - 42b067c0-ba32-11e9-9906-b831b5891408 + x-ms-date: + - Thu, 08 Aug 2019 23:14:24 GMT + x-ms-version: + - '2018-03-28' + method: GET + uri: https://storagename.queue.core.windows.net/messagequeue/messages + response: + body: + string: "\uFEFFa8ccfc6e-c4e9-4e45-ad33-1d88ee4a2aecThu, + 08 Aug 2019 23:14:21 GMTThu, 15 Aug 2019 23:14:21 + GMTAgAAAAMAAAAAAAAAq8xoFj9O1QE=Thu, + 08 Aug 2019 23:14:54 GMT1message5" + headers: + Cache-Control: + - no-cache + Content-Type: + - application/xml + Date: + - Thu, 08 Aug 2019 23:14:24 GMT + Server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + Transfer-Encoding: + - chunked + Vary: + - Origin + x-ms-request-id: + - 24c6e480-4003-00ca-533f-4ef7cd000000 + x-ms-version: + - '2018-03-28' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) + content-type: + - application/xml; charset=utf-8 + x-ms-client-request-id: + - 432228ee-ba32-11e9-836f-b831b5891408 + x-ms-date: + - Thu, 08 Aug 2019 23:14:24 GMT + x-ms-version: + - '2018-03-28' + method: GET + uri: https://storagename.queue.core.windows.net/messagequeue/messages + response: + body: + string: "\uFEFF" headers: Cache-Control: - no-cache Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:24 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: @@ -324,7 +501,7 @@ interactions: Vary: - Origin x-ms-request-id: - - 46026c9e-2003-003f-6d82-49d3dc000000 + - 24c6e4e5-4003-00ca-313f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -340,13 +517,13 @@ interactions: Connection: - keep-alive User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) content-type: - application/xml; charset=utf-8 x-ms-client-request-id: - - 988a789e-b575-11e9-bae2-2816a845e8c6 + - 436fbb9e-ba32-11e9-9a86-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:25 GMT x-ms-version: - '2018-03-28' method: GET @@ -361,7 +538,7 @@ interactions: Content-Type: - application/xml Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:25 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 Transfer-Encoding: @@ -369,7 +546,7 @@ interactions: Vary: - Origin x-ms-request-id: - - 46026ca1-2003-003f-7082-49d3dc000000 + - 24c6e549-4003-00ca-053f-4ef7cd000000 x-ms-version: - '2018-03-28' status: @@ -387,13 +564,13 @@ interactions: Content-Length: - '0' User-Agent: - - azsdk-python-storage-queue/12.0.0b1 Python/3.7.3 (Windows-10-10.0.17763-SP0) + - azsdk-python-storage-queue/12.0.0b2 Python/3.5.4 (Windows-10-10.0.17763-SP0) content-type: - application/xml; charset=utf-8 x-ms-client-request-id: - - 98965b8a-b575-11e9-ab00-2816a845e8c6 + - 43c85852-ba32-11e9-be64-b831b5891408 x-ms-date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:25 GMT x-ms-version: - '2018-03-28' method: DELETE @@ -405,11 +582,11 @@ interactions: Content-Length: - '0' Date: - - Fri, 02 Aug 2019 22:33:48 GMT + - Thu, 08 Aug 2019 23:14:25 GMT Server: - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 x-ms-request-id: - - 46026ca8-2003-003f-7782-49d3dc000000 + - 24c6e5f4-4003-00ca-1c3f-4ef7cd000000 x-ms-version: - '2018-03-28' status: diff --git a/sdk/storage/azure-storage-queue/tests/test_queue.py b/sdk/storage/azure-storage-queue/tests/test_queue.py index 6e7ddc739703..bff9879d1024 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue.py @@ -511,7 +511,8 @@ def test_account_sas(self): @record def test_token_credential(self): - pytest.skip("") + if TestMode.need_recording_file(self.test_mode): + return token_credential = self.generate_oauth_token() # Action 1: make sure token works diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_async.py index 4ef4b6e82624..3ae8bbd1081c 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_async.py @@ -648,7 +648,8 @@ def test_account_sas(self): loop.run_until_complete(self._test_account_sas()) async def _test_token_credential(self): - pytest.skip("") + if TestMode.need_recording_file(self.test_mode): + return token_credential = self.generate_oauth_token() # Action 1: make sure token works diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py index 5527b915d794..486e93a23cd0 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication.py @@ -61,8 +61,10 @@ def test_auth_shared_key(self): @record def test_auth_active_directory(self): - pytest.skip('pending azure identity') + if TestMode.need_recording_file(self.test_mode): + return + # [START create_queue_service_client_token] # Get a token credential for authentication from azure.identity import ClientSecretCredential token_credential = ClientSecretCredential( @@ -74,6 +76,7 @@ def test_auth_active_directory(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue import QueueServiceClient queue_service = QueueServiceClient(account_url=self.url, credential=token_credential) + # [END create_queue_service_client_token] # Get information for the Queue Service properties = queue_service.get_service_properties() diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication_async.py index 575e246ac909..871f8e99de27 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_authentication_async.py @@ -9,8 +9,6 @@ from datetime import datetime, timedelta import pytest import asyncio -from azure.core.pipeline.transport import AioHttpTransport -from multidict import CIMultiDict, CIMultiDictProxy try: import settings_real as settings except ImportError: @@ -23,16 +21,6 @@ ) -class AiohttpTestTransport(AioHttpTransport): - """Workaround to vcrpy bug: https://github.com/kevin1024/vcrpy/pull/461 - """ - async def send(self, request, **config): - response = await super(AiohttpTestTransport, self).send(request, **config) - if not isinstance(response.headers, CIMultiDictProxy): - response.headers = CIMultiDictProxy(CIMultiDict(response.internal_response.headers)) - response.content_type = response.headers.get("content-type") - return response - class TestQueueAuthSamplesAsync(QueueTestCase): url = "{}://{}.queue.core.windows.net".format( settings.PROTOCOL, @@ -47,41 +35,43 @@ class TestQueueAuthSamplesAsync(QueueTestCase): async def _test_auth_connection_string(self): # Instantiate a QueueServiceClient using a connection string - # [START auth_from_connection_string] + # [START async_auth_from_connection_string] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(self.connection_string, transport=AiohttpTestTransport()) - # [END auth_from_connection_string] + queue_service = QueueServiceClient.from_connection_string(self.connection_string) + # [END async_auth_from_connection_string] # Get information for the Queue Service properties = await queue_service.get_service_properties() assert properties is not None - @record def test_auth_connection_string(self): + if TestMode.need_recording_file(self.test_mode): + return loop = asyncio.get_event_loop() loop.run_until_complete(self._test_auth_connection_string()) async def _test_auth_shared_key(self): # Instantiate a QueueServiceClient using a shared access key - # [START create_queue_service_client] + # [START async_create_queue_service_client] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient(account_url=self.url, credential=self.shared_access_key, transport=AiohttpTestTransport()) - # [END create_queue_service_client] + queue_service = QueueServiceClient(account_url=self.url, credential=self.shared_access_key) + # [END async_create_queue_service_client] # Get information for the Queue Service properties = await queue_service.get_service_properties() assert properties is not None - @pytest.mark.skip def test_auth_shared_key(self): + if TestMode.need_recording_file(self.test_mode): + return loop = asyncio.get_event_loop() loop.run_until_complete(self._test_auth_shared_key()) async def _test_auth_active_directory(self): - pytest.skip('pending azure identity') + # [START async_create_queue_service_client_token] # Get a token credential for authentication from azure.identity import ClientSecretCredential token_credential = ClientSecretCredential( @@ -93,25 +83,24 @@ async def _test_auth_active_directory(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient(account_url=self.url, credential=token_credential) + # [END async_create_queue_service_client_token] # Get information for the Queue Service properties = await queue_service.get_service_properties() assert properties is not None - @record def test_auth_active_directory(self): + if TestMode.need_recording_file(self.test_mode): + return loop = asyncio.get_event_loop() loop.run_until_complete(self._test_auth_active_directory()) async def _test_auth_shared_access_signature(self): - # SAS URL is calculated from storage key, so this test runs live only - if TestMode.need_recording_file(self.test_mode): - return - + # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(self.connection_string, transport=AiohttpTestTransport()) + queue_service = QueueServiceClient.from_connection_string(self.connection_string) # Create a SAS token to use for authentication of a client sas_token = queue_service.generate_shared_access_signature( @@ -122,7 +111,8 @@ async def _test_auth_shared_access_signature(self): assert sas_token is not None - @record def test_auth_shared_access_signature(self): + if TestMode.need_recording_file(self.test_mode): + return loop = asyncio.get_event_loop() loop.run_until_complete(self._test_auth_shared_access_signature()) diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world_async.py index 6697c4110633..290572f42dad 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_hello_world_async.py @@ -13,7 +13,6 @@ import settings_real as settings except ImportError: import queue_settings_fake as settings -from azure.core.pipeline.transport import AioHttpTransport from multidict import CIMultiDict, CIMultiDictProxy from queuetestcase import ( QueueTestCase, @@ -22,16 +21,6 @@ ) -class AiohttpTestTransport(AioHttpTransport): - """Workaround to vcrpy bug: https://github.com/kevin1024/vcrpy/pull/461 - """ - async def send(self, request, **config): - response = await super(AiohttpTestTransport, self).send(request, **config) - if not isinstance(response.headers, CIMultiDictProxy): - response.headers = CIMultiDictProxy(CIMultiDict(response.internal_response.headers)) - response.content_type = response.headers.get("content-type") - return response - class TestQueueHelloWorldSamplesAsync(QueueTestCase): @@ -40,14 +29,49 @@ class TestQueueHelloWorldSamplesAsync(QueueTestCase): async def _test_create_client_with_connection_string(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(self.connection_string, transport=AiohttpTestTransport()) + queue_service = QueueServiceClient.from_connection_string(self.connection_string) # Get queue service properties properties = await queue_service.get_service_properties() assert properties is not None - @pytest.mark.skip def test_create_client_with_connection_string(self): + if TestMode.need_recording_file(self.test_mode): + return loop = asyncio.get_event_loop() loop.run_until_complete(self._test_create_client_with_connection_string()) + + async def _test_queue_and_messages_example(self): + # Instantiate the QueueClient from a connection string + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "myasyncqueue") + + # Create the queue + # [START async_create_queue] + await queue.create_queue() + # [END async_create_queue] + + try: + # Enqueue messages + await asyncio.gather( + queue.enqueue_message(u"I'm using queues!"), + queue.enqueue_message(u"This is my second message")) + + # Receive the messages + response = queue.receive_messages(messages_per_page=2) + + # Print the content of the messages + async for message in response: + print(message.content) + + finally: + # [START async_delete_queue] + await queue.delete_queue() + # [END async_delete_queue] + + def test_queue_and_messages_example(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_queue_and_messages_example()) \ No newline at end of file diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py index 1466551ce0d2..2db8ddf89875 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_message.py @@ -127,15 +127,17 @@ def test_enqueue_and_receive_messages(self): # [END enqueue_messages] # [START receive_messages] - # receive one message from the front of the queue - one_msg = queue.receive_messages() - - # Receive the last 5 messages - messages = queue.receive_messages(messages_per_page=5) - - # Print the messages + # Receive messages one-by-one + messages = queue.receive_messages() for msg in messages: print(msg.content) + + # Receive messages by batch + messages = queue.receive_messages(messages_per_page=5) + for msg_batch in messages.by_page(): + for msg in msg_batch: + print(msg.content) + queue.delete_message(msg) # [END receive_messages] # Only prints 4 messages because message 2 is not visible yet diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_message_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_message_async.py new file mode 100644 index 000000000000..41f58b3be007 --- /dev/null +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_message_async.py @@ -0,0 +1,282 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +from datetime import datetime, timedelta +from azure.core.exceptions import ResourceExistsError +import asyncio +try: + import settings_real as settings +except ImportError: + import queue_settings_fake as settings + +from queuetestcase import ( + QueueTestCase, + record, + TestMode +) + + +class TestMessageQueueSamples(QueueTestCase): + + connection_string = settings.CONNECTION_STRING + storage_url = "{}://{}.queue.core.windows.net".format( + settings.PROTOCOL, + settings.STORAGE_ACCOUNT_NAME + ) + + async def _test_set_access_policy(self): + + # [START async_create_queue_client_from_connection_string] + from azure.storage.queue.aio import QueueClient + queue_client = QueueClient.from_connection_string(self.connection_string, "asyncqueuetest") + # [END async_create_queue_client_from_connection_string] + + # Create the queue + try: + await queue_client.create_queue() + except ResourceExistsError: + pass + await queue_client.enqueue_message(u"hello world") + + try: + # [START async_set_access_policy] + # Create an access policy + from azure.storage.queue.aio import AccessPolicy, QueuePermissions + access_policy = AccessPolicy() + access_policy.start = datetime.utcnow() - timedelta(hours=1) + access_policy.expiry = datetime.utcnow() + timedelta(hours=1) + access_policy.permission = QueuePermissions.READ + identifiers = {'my-access-policy-id': access_policy} + + # Set the access policy + await queue_client.set_queue_access_policy(identifiers) + # [END async_set_access_policy] + + # Use the access policy to generate a SAS token + sas_token = queue_client.generate_shared_access_signature( + policy_id='my-access-policy-id' + ) + # [END async_set_access_policy] + + # Authenticate with the sas token + # [START async_create_queue_client] + from azure.storage.queue.aio import QueueClient + q = QueueClient( + queue_url=queue_client.url, + credential=sas_token + ) + # [END async_create_queue_client] + + # Use the newly authenticated client to receive messages + my_messages = q.receive_messages() + + finally: + # Delete the queue + await queue_client.delete_queue() + + def test_set_access_policy(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_set_access_policy()) + + async def _test_queue_metadata(self): + + # Instantiate a queue client + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "asyncmetaqueue") + + # Create the queue + await queue.create_queue() + + try: + # [START async_set_queue_metadata] + metadata = {'foo': 'val1', 'bar': 'val2', 'baz': 'val3'} + await queue.set_queue_metadata(metadata=metadata) + # [END async_set_queue_metadata] + + # [START async_get_queue_properties] + response = await queue.get_queue_properties() + # [END async_get_queue_properties] + assert response.metadata == metadata + + finally: + # Delete the queue + await queue.delete_queue() + + def test_queue_metadata(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_queue_metadata()) + + async def _test_enqueue_and_receive_messages(self): + + # Instantiate a queue client + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "asyncmessagequeue") + + # Create the queue + await queue.create_queue() + + try: + # [START async_enqueue_messages] + await asyncio.gather( + queue.enqueue_message(u"message1"), + queue.enqueue_message(u"message2", visibility_timeout=30), # wait 30s before becoming visible + queue.enqueue_message(u"message3"), + queue.enqueue_message(u"message4"), + queue.enqueue_message(u"message5")) + # [END async_enqueue_messages] + + # [START async_receive_messages] + # Receive messages one-by-one + messages = queue.receive_messages() + async for msg in messages: + print(msg.content) + + # Receive messages by batch + messages = queue.receive_messages(messages_per_page=5) + async for msg_batch in messages.by_page(): + for msg in msg_batch: + print(msg.content) + await queue.delete_message(msg) + # [END async_receive_messages] + + # Only prints 4 messages because message 2 is not visible yet + # >>message1 + # >>message3 + # >>message4 + # >>message5 + + finally: + # Delete the queue + await queue.delete_queue() + + def test_enqueue_and_receive_messages(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_enqueue_and_receive_messages()) + + async def _test_delete_and_clear_messages(self): + + # Instantiate a queue client + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "asyncdelqueue") + + # Create the queue + await queue.create_queue() + + try: + # Enqueue messages + await asyncio.gather( + queue.enqueue_message(u"message1"), + queue.enqueue_message(u"message2"), + queue.enqueue_message(u"message3"), + queue.enqueue_message(u"message4"), + queue.enqueue_message(u"message5")) + + # [START async_delete_message] + # Get the message at the front of the queue + messages = queue.receive_messages() + async for msg in messages: + + # Delete the specified message + await queue.delete_message(msg) + # [END async_delete_message] + + # [START async_clear_messages] + await queue.clear_messages() + # [END async_clear_messages] + + finally: + # Delete the queue + await queue.delete_queue() + + def test_delete_and_clear_messages(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_delete_and_clear_messages()) + + async def _test_peek_messages(self): + # Instantiate a queue client + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "asyncpeekqueue") + + # Create the queue + await queue.create_queue() + + try: + # Enqueue messages + await asyncio.gather( + queue.enqueue_message(u"message1"), + queue.enqueue_message(u"message2"), + queue.enqueue_message(u"message3"), + queue.enqueue_message(u"message4"), + queue.enqueue_message(u"message5")) + + # [START async_peek_message] + # Peek at one message at the front of the queue + msg = await queue.peek_messages() + + # Peek at the last 5 messages + messages = await queue.peek_messages(max_messages=5) + + # Print the last 5 messages + for message in messages: + print(message.content) + # [END async_peek_message] + + finally: + # Delete the queue + await queue.delete_queue() + + def test_peek_messages(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_peek_messages()) + + async def _test_update_message(self): + + # Instantiate a queue client + from azure.storage.queue.aio import QueueClient + queue = QueueClient.from_connection_string(self.connection_string, "asyncupdatequeue") + + # Create the queue + await queue.create_queue() + + try: + # [START async_update_message] + # Enqueue a message + await queue.enqueue_message(u"update me") + + # Receive the message + messages = queue.receive_messages() + + # Update the message + async for message in messages: + message = await queue.update_message( + message, + visibility_timeout=0, + content=u"updated") + # [END update_message] + assert message.content == "updated" + break + + finally: + # Delete the queue + await queue.delete_queue() + + def test_update_message(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_update_message()) diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py index 4acc8975222f..3b8425d2061b 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_service.py @@ -76,10 +76,14 @@ def test_queues_in_account(self): try: # [START qsc_list_queues] # List all the queues in the service - list_queues = next(queue_service.list_queues()) + list_queues = queue_service.list_queues() + for queue in list_queues: + print(queue) # List the queues in the service that start with the name "test" - list_test_queues = next(queue_service.list_queues(name_starts_with="test")) + list_test_queues = queue_service.list_queues(name_starts_with="test") + for queue in list_test_queues: + print(queue) # [END qsc_list_queues] finally: diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_samples_service_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_samples_service_async.py new file mode 100644 index 000000000000..97695cb53851 --- /dev/null +++ b/sdk/storage/azure-storage-queue/tests/test_queue_samples_service_async.py @@ -0,0 +1,121 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import asyncio + +try: + import settings_real as settings +except ImportError: + import queue_settings_fake as settings + +from queuetestcase import ( + QueueTestCase, + record, + TestMode +) + + +class TestQueueServiceSamples(QueueTestCase): + + connection_string = settings.CONNECTION_STRING + + async def _test_queue_service_properties(self): + # Instantiate the QueueServiceClient from a connection string + from azure.storage.queue.aio import QueueServiceClient + queue_service = QueueServiceClient.from_connection_string(self.connection_string) + + # [START async_set_queue_service_properties] + # Create service properties + from azure.storage.queue.aio import Logging, Metrics, CorsRule, RetentionPolicy + + # Create logging settings + logging = Logging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) + + # Create metrics for requests statistics + hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) + minute_metrics = Metrics(enabled=True, include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5)) + + # Create CORS rules + cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) + allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] + allowed_methods = ['GET', 'PUT'] + max_age_in_seconds = 500 + exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] + allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] + cors_rule2 = CorsRule( + allowed_origins, + allowed_methods, + max_age_in_seconds=max_age_in_seconds, + exposed_headers=exposed_headers, + allowed_headers=allowed_headers) + + cors = [cors_rule1, cors_rule2] + + # Set the service properties + await queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) + # [END async_set_queue_service_properties] + + # [START async_get_queue_service_properties] + properties = await queue_service.get_service_properties() + # [END async_get_queue_service_properties] + + def test_queue_service_properties(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_queue_service_properties()) + + async def _test_queues_in_account(self): + # Instantiate the QueueServiceClient from a connection string + from azure.storage.queue.aio import QueueServiceClient + queue_service = QueueServiceClient.from_connection_string(self.connection_string) + + # [START async_qsc_create_queue] + await queue_service.create_queue("asynctestqueue") + # [END async_qsc_create_queue] + + try: + # [START async_qsc_list_queues] + # List all the queues in the service + list_queues = queue_service.list_queues() + async for queue in list_queues: + print(queue) + + # List the queues in the service that start with the name "test" + list_test_queues = queue_service.list_queues(name_starts_with="test") + async for queue in list_test_queues: + print(queue) + # [END async_qsc_list_queues] + + finally: + # [START async_qsc_delete_queue] + await queue_service.delete_queue("asynctestqueue") + # [END async_qsc_delete_queue] + + def test_queues_in_account(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_queues_in_account()) + + async def _test_get_queue_client(self): + # Instantiate the QueueServiceClient from a connection string + from azure.storage.queue.aio import QueueServiceClient, QueueClient + queue_service = QueueServiceClient.from_connection_string(self.connection_string) + + # [START async_get_queue_client] + # Get the queue client to interact with a specific queue + queue = queue_service.get_queue_client("myasyncqueue") + # [END async_get_queue_client] + + def test_get_queue_client(self): + if TestMode.need_recording_file(self.test_mode): + return + loop = asyncio.get_event_loop() + loop.run_until_complete(self._test_get_queue_client())