Skip to content

Commit ae5480c

Browse files
[Storage] Migrate test_queue_service_stats.py to test proxy (Azure#27286)
* JSON is invalid * Wip * Done
1 parent 653d77c commit ae5480c

10 files changed

+180
-220
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://storagename-secondary.queue.core.windows.net/?restype=service\u0026comp=stats",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/xml",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Connection": "keep-alive",
10+
"User-Agent": "azsdk-python-storage-queue/12.5.1 Python/3.10.2 (Windows-10-10.0.19044-SP0)",
11+
"x-ms-date": "Thu, 03 Nov 2022 23:07:59 GMT",
12+
"x-ms-version": "2020-08-04"
13+
},
14+
"RequestBody": null,
15+
"StatusCode": 200,
16+
"ResponseHeaders": {
17+
"Cache-Control": "no-cache",
18+
"Content-Type": "application/xml",
19+
"Date": "Thu, 03 Nov 2022 23:07:59 GMT",
20+
"Server": [
21+
"Windows-Azure-Queue/1.0",
22+
"Microsoft-HTTPAPI/2.0"
23+
],
24+
"Transfer-Encoding": "chunked",
25+
"x-ms-version": "2020-08-04"
26+
},
27+
"ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceStats\u003E\u003CGeoReplication\u003E\u003CStatus\u003Elive\u003C/Status\u003E\u003CLastSyncTime\u003EThu, 03 Nov 2022 23:03:09 GMT\u003C/LastSyncTime\u003E\u003C/GeoReplication\u003E\u003C/StorageServiceStats\u003E"
28+
}
29+
],
30+
"Variables": {}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://storagename-secondary.queue.core.windows.net/?restype=service\u0026comp=stats",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/xml",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Connection": "keep-alive",
10+
"User-Agent": "azsdk-python-storage-queue/12.5.1 Python/3.10.2 (Windows-10-10.0.19044-SP0)",
11+
"x-ms-date": "Thu, 03 Nov 2022 23:08:20 GMT",
12+
"x-ms-version": "2020-08-04"
13+
},
14+
"RequestBody": null,
15+
"StatusCode": 200,
16+
"ResponseHeaders": {
17+
"Cache-Control": "no-cache",
18+
"Content-Type": "application/xml",
19+
"Date": "Thu, 03 Nov 2022 23:08:21 GMT",
20+
"Server": [
21+
"Windows-Azure-Queue/1.0",
22+
"Microsoft-HTTPAPI/2.0"
23+
],
24+
"Transfer-Encoding": "chunked",
25+
"x-ms-version": "2020-08-04"
26+
},
27+
"ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceStats\u003E\u003CGeoReplication\u003E\u003CStatus\u003Eunavailable\u003C/Status\u003E\u003CLastSyncTime\u003E\u003C/LastSyncTime\u003E\u003C/GeoReplication\u003E\u003C/StorageServiceStats\u003E"
28+
}
29+
],
30+
"Variables": {}
31+
}

sdk/storage/azure-storage-queue/tests/recordings/test_queue_service_stats.test_queue_service_stats_f.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

sdk/storage/azure-storage-queue/tests/recordings/test_queue_service_stats.test_queue_service_stats_when_unavailable.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://storagename-secondary.queue.core.windows.net/?restype=service\u0026comp=stats",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/xml",
8+
"Accept-Encoding": "gzip, deflate",
9+
"User-Agent": "azsdk-python-storage-queue/12.5.1 Python/3.10.2 (Windows-10-10.0.19044-SP0)",
10+
"x-ms-date": "Thu, 03 Nov 2022 23:18:09 GMT",
11+
"x-ms-version": "2021-02-12"
12+
},
13+
"RequestBody": null,
14+
"StatusCode": 200,
15+
"ResponseHeaders": {
16+
"Cache-Control": "no-cache",
17+
"Content-Type": "application/xml",
18+
"Date": "Thu, 03 Nov 2022 23:18:10 GMT",
19+
"Server": [
20+
"Windows-Azure-Queue/1.0",
21+
"Microsoft-HTTPAPI/2.0"
22+
],
23+
"Transfer-Encoding": "chunked",
24+
"x-ms-version": "2021-02-12"
25+
},
26+
"ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceStats\u003E\u003CGeoReplication\u003E\u003CStatus\u003Elive\u003C/Status\u003E\u003CLastSyncTime\u003EThu, 03 Nov 2022 23:15:20 GMT\u003C/LastSyncTime\u003E\u003C/GeoReplication\u003E\u003C/StorageServiceStats\u003E"
27+
}
28+
],
29+
"Variables": {}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://storagename-secondary.queue.core.windows.net/?restype=service\u0026comp=stats",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/xml",
8+
"Accept-Encoding": "gzip, deflate",
9+
"User-Agent": "azsdk-python-storage-queue/12.5.1 Python/3.10.2 (Windows-10-10.0.19044-SP0)",
10+
"x-ms-date": "Thu, 03 Nov 2022 23:18:43 GMT",
11+
"x-ms-version": "2021-02-12"
12+
},
13+
"RequestBody": null,
14+
"StatusCode": 200,
15+
"ResponseHeaders": {
16+
"Cache-Control": "no-cache",
17+
"Content-Type": "application/xml",
18+
"Date": "Thu, 03 Nov 2022 23:18:44 GMT",
19+
"Server": [
20+
"Windows-Azure-Queue/1.0",
21+
"Microsoft-HTTPAPI/2.0"
22+
],
23+
"Transfer-Encoding": "chunked",
24+
"x-ms-version": "2021-02-12"
25+
},
26+
"ResponseBody": "\uFEFF\u003C?xml version=\u00221.0\u0022 encoding=\u0022utf-8\u0022?\u003E\u003CStorageServiceStats\u003E\u003CGeoReplication\u003E\u003CStatus\u003Eunavailable\u003C/Status\u003E\u003CLastSyncTime\u003E\u003C/LastSyncTime\u003E\u003C/GeoReplication\u003E\u003C/StorageServiceStats\u003E"
27+
}
28+
],
29+
"Variables": {}
30+
}

sdk/storage/azure-storage-queue/tests/recordings/test_queue_service_stats_async.test_queue_service_stats_f.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

sdk/storage/azure-storage-queue/tests/recordings/test_queue_service_stats_async.test_queue_service_stats_when_unavailable.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,59 @@
55
# --------------------------------------------------------------------------
66
import unittest
77

8+
import pytest
89
from azure.storage.queue import QueueServiceClient
9-
from settings.testcase import QueuePreparer
10-
from devtools_testutils.storage import StorageTestCase
11-
12-
SERVICE_UNAVAILABLE_RESP_BODY = '<?xml version="1.0" encoding="utf-8"?><StorageServiceStats><GeoReplication><Status' \
13-
'>unavailable</Status><LastSyncTime></LastSyncTime></GeoReplication' \
14-
'></StorageServiceStats> '
1510

16-
SERVICE_LIVE_RESP_BODY = '<?xml version="1.0" encoding="utf-8"?><StorageServiceStats><GeoReplication><Status' \
17-
'>live</Status><LastSyncTime>Wed, 19 Jan 2021 22:28:43 GMT</LastSyncTime></GeoReplication' \
18-
'></StorageServiceStats> '
11+
from devtools_testutils import recorded_by_proxy
12+
from devtools_testutils.storage import StorageRecordedTestCase
13+
from settings.testcase import QueuePreparer
1914

2015
# --Test Class -----------------------------------------------------------------
21-
class QueueServiceStatsTest(StorageTestCase):
16+
class TestQueueServiceStats(StorageRecordedTestCase):
17+
2218
# --Helpers-----------------------------------------------------------------
2319
def _assert_stats_default(self, stats):
24-
self.assertIsNotNone(stats)
25-
self.assertIsNotNone(stats['geo_replication'])
20+
assert stats is not None
21+
assert stats['geo_replication'] is not None
2622

27-
self.assertEqual(stats['geo_replication']['status'], 'live')
28-
self.assertIsNotNone(stats['geo_replication']['last_sync_time'])
23+
assert stats['geo_replication']['status'] == 'live'
24+
assert stats['geo_replication']['last_sync_time'] is not None
2925

3026
def _assert_stats_unavailable(self, stats):
31-
self.assertIsNotNone(stats)
32-
self.assertIsNotNone(stats['geo_replication'])
33-
34-
self.assertEqual(stats['geo_replication']['status'], 'unavailable')
35-
self.assertIsNone(stats['geo_replication']['last_sync_time'])
27+
assert stats is not None
28+
assert stats['geo_replication'] is not None
3629

37-
@staticmethod
38-
def override_response_body_with_unavailable_status(response):
39-
response.http_response.text = lambda encoding=None: SERVICE_UNAVAILABLE_RESP_BODY
40-
41-
@staticmethod
42-
def override_response_body_with_live_status(response):
43-
response.http_response.text = lambda encoding=None: SERVICE_LIVE_RESP_BODY
30+
assert stats['geo_replication']['status'] == 'unavailable'
31+
assert stats['geo_replication']['last_sync_time'] is None
4432

4533
# --Test cases per service ---------------------------------------
46-
34+
@pytest.mark.playback_test_only
4735
@QueuePreparer()
48-
def test_queue_service_stats_f(self, storage_account_name, storage_account_key):
36+
@recorded_by_proxy
37+
def test_queue_service_stats(self, **kwargs):
38+
storage_account_name = kwargs.pop("storage_account_name")
39+
storage_account_key = kwargs.pop("storage_account_key")
40+
4941
# Arrange
5042
qsc = self.create_storage_client(QueueServiceClient, self.account_url(storage_account_name, "queue"), storage_account_key)
5143

5244
# Act
53-
stats = qsc.get_service_stats(raw_response_hook=self.override_response_body_with_live_status)
45+
stats = qsc.get_service_stats()
5446
# Assert
5547
self._assert_stats_default(stats)
5648

49+
@pytest.mark.playback_test_only
5750
@QueuePreparer()
58-
def test_queue_service_stats_when_unavailable(self, storage_account_name, storage_account_key):
51+
@recorded_by_proxy
52+
def test_queue_service_stats_when_unavailable(self, **kwargs):
53+
storage_account_name = kwargs.pop("storage_account_name")
54+
storage_account_key = kwargs.pop("storage_account_key")
55+
5956
# Arrange
6057
qsc = self.create_storage_client(QueueServiceClient, self.account_url(storage_account_name, "queue"), storage_account_key)
6158

6259
# Act
63-
stats = qsc.get_service_stats(raw_response_hook=self.override_response_body_with_unavailable_status)
60+
stats = qsc.get_service_stats()
6461

6562
# Assert
6663
self._assert_stats_unavailable(stats)

0 commit comments

Comments
 (0)