Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 726d76f

Browse files
Patching tables nightly failure (Azure#16758)
1 parent 5e94c0e commit 726d76f

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

sdk/tables/azure-data-tables/tests/test_table_client.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def callback(response):
4747
tables = list(service.list_tables(raw_response_hook=callback))
4848
assert isinstance(tables, list)
4949

50+
# The count doesn't matter, going through the PagedItem calls `callback`
5051
count = 0
5152
for table in tables:
5253
count += 1
53-
assert count == 0
5454

5555
def callback(response):
5656
assert 'User-Agent' in response.http_request.headers
@@ -62,11 +62,10 @@ def callback(response):
6262
tables = list(service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0"))
6363
assert isinstance(tables, list)
6464

65+
# The count doesn't matter, going through the PagedItem calls `callback`
6566
count = 0
6667
for table in tables:
6768
count += 1
68-
assert count == 0
69-
7069

7170
@TablesPreparer()
7271
def test_user_agent_append(self, tables_storage_account_name, tables_primary_storage_account_key):
@@ -79,10 +78,10 @@ def callback(response):
7978
custom_headers = {'User-Agent': 'customer_user_agent'}
8079
tables = service.list_tables(raw_response_hook=callback, headers=custom_headers)
8180

81+
# The count doesn't matter, going through the PagedItem calls `callback`
8282
count = 0
8383
for table in tables:
8484
count += 1
85-
assert count == 0
8685

8786
@TablesPreparer()
8887
def test_user_agent_default(self, tables_storage_account_name, tables_primary_storage_account_key):
@@ -98,10 +97,10 @@ def callback(response):
9897
tables = list(service.list_tables(raw_response_hook=callback))
9998
assert isinstance(tables, list)
10099

100+
# The count doesn't matter, going through the PagedItem calls `callback`
101101
count = 0
102102
for table in tables:
103103
count += 1
104-
assert count == 0
105104

106105

107106
class TestTableUnitTests(TableTestCase):
@@ -144,16 +143,17 @@ def test_create_service_with_sas(self):
144143
# Arrange
145144
url = self.account_url(self.tables_storage_account_name, "table")
146145
suffix = '.table.core.windows.net'
146+
token = self.generate_sas_token()
147147
for service_type in SERVICES:
148148
# Act
149149
service = service_type(
150-
self.account_url(self.tables_storage_account_name, "table"), credential=self.generate_sas_token(), table_name='foo')
150+
self.account_url(self.tables_storage_account_name, "table"), credential=token, table_name='foo')
151151

152152
# Assert
153153
assert service is not None
154154
assert service.account_name == self.tables_storage_account_name
155155
assert service.url.startswith('https://' + self.tables_storage_account_name + suffix)
156-
assert service.url.endswith(self.generate_sas_token())
156+
assert service.url.endswith(token)
157157
assert service.credential is None
158158

159159
def test_create_service_china(self):
@@ -230,7 +230,9 @@ def test_create_service_with_connection_string_key(self):
230230

231231
def test_create_service_with_connection_string_sas(self):
232232
# Arrange
233-
conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.tables_storage_account_name, self.generate_sas_token())
233+
token = self.generate_sas_token()
234+
conn_string = 'AccountName={};SharedAccessSignature={};'.format(
235+
self.tables_storage_account_name, token)
234236

235237
for service_type in SERVICES:
236238
# Act
@@ -239,8 +241,9 @@ def test_create_service_with_connection_string_sas(self):
239241
# Assert
240242
assert service is not None
241243
assert service.account_name == self.tables_storage_account_name
242-
assert service.url.startswith('https://' + self.tables_storage_account_name + '.table.core.windows.net')
243-
assert service.url.endswith(self.generate_sas_token())
244+
assert service.url.startswith(
245+
'https://' + self.tables_storage_account_name + '.table.core.windows.net')
246+
assert service.url.endswith(token)
244247
assert service.credential is None
245248

246249
def test_create_service_with_connection_string_cosmos(self):
@@ -369,7 +372,8 @@ def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self):
369372
assert service._primary_endpoint.startswith('https://www.mydomain.com')
370373

371374
def test_create_service_with_custom_account_endpoint_path(self):
372-
custom_account_url = "http://local-machine:11002/custom/account/path/" + self.generate_sas_token()
375+
token = self.generate_sas_token()
376+
custom_account_url = "http://local-machine:11002/custom/account/path/" + token
373377
for service_type in SERVICES.items():
374378
conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format(
375379
self.tables_storage_account_name, self.tables_primary_storage_account_key, custom_account_url)
@@ -396,7 +400,7 @@ def test_create_service_with_custom_account_endpoint_path(self):
396400
assert service._primary_hostname == 'local-machine:11002/custom/account/path'
397401
assert service.url.startswith('http://local-machine:11002/custom/account/path')
398402

399-
service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + self.generate_sas_token())
403+
service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + token)
400404
assert service.account_name == None
401405
assert service.table_name == "foo"
402406
assert service.credential == None

sdk/tables/azure-data-tables/tests/test_table_client_async.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def callback(response):
4141
tables = service.list_tables(raw_response_hook=callback)
4242
assert tables is not None
4343

44+
# The count doesn't matter, going through the PagedItem calls `callback`
4445
count = 0
4546
async for table in tables:
4647
count += 1
47-
assert count == 0
4848

4949
@TablesPreparer()
5050
async def test_user_agent_custom_async(self, tables_storage_account_name, tables_primary_storage_account_key):
@@ -62,10 +62,10 @@ def callback(response):
6262
tables = service.list_tables(raw_response_hook=callback)
6363
assert tables is not None
6464

65+
# The count doesn't matter, going through the PagedItem calls `callback`
6566
count = 0
6667
async for table in tables:
6768
count += 1
68-
assert count == 0
6969

7070
def callback(response):
7171
assert 'User-Agent' in response.http_request.headers
@@ -77,10 +77,10 @@ def callback(response):
7777
tables = service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0")
7878
assert tables is not None
7979

80+
# The count doesn't matter, going through the PagedItem calls `callback`
8081
count = 0
8182
async for table in tables:
8283
count += 1
83-
assert count == 0
8484

8585
@TablesPreparer()
8686
async def test_user_agent_append(self, tables_storage_account_name, tables_primary_storage_account_key):
@@ -93,10 +93,10 @@ def callback(response):
9393
custom_headers = {'User-Agent': 'customer_user_agent'}
9494
tables = service.list_tables(raw_response_hook=callback, headers=custom_headers)
9595

96+
# The count doesn't matter, going through the PagedItem calls `callback`
9697
count = 0
9798
async for table in tables:
9899
count += 1
99-
assert count == 0
100100

101101

102102
class TestTableClientUnit(AsyncTableTestCase):
@@ -142,16 +142,17 @@ async def test_create_service_with_sas_async(self):
142142
# Arrange
143143
url = self.account_url(self.tables_storage_account_name, "table")
144144
suffix = '.table.core.windows.net'
145+
token = self.generate_sas_token()
145146
for service_type in SERVICES:
146147
# Act
147148
service = service_type(
148-
self.account_url(self.tables_storage_account_name, "table"), credential=self.generate_sas_token(), table_name='foo')
149+
self.account_url(self.tables_storage_account_name, "table"), credential=token, table_name='foo')
149150

150151
# Assert
151152
assert service is not None
152153
assert service.account_name == self.tables_storage_account_name
153154
assert service.url.startswith('https://' + self.tables_storage_account_name + suffix)
154-
assert service.url.endswith(self.generate_sas_token())
155+
assert service.url.endswith(token)
155156
assert service.credential is None
156157

157158
@pytest.mark.asyncio
@@ -256,7 +257,8 @@ async def test_create_service_with_connection_string_key_async(self):
256257
@pytest.mark.asyncio
257258
async def test_create_service_with_connection_string_sas_async(self):
258259
# Arrange
259-
conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.tables_storage_account_name, self.generate_sas_token())
260+
token = self.generate_sas_token()
261+
conn_string = 'AccountName={};SharedAccessSignature={};'.format(self.tables_storage_account_name, token)
260262

261263
for service_type in SERVICES:
262264
# Act
@@ -266,7 +268,7 @@ async def test_create_service_with_connection_string_sas_async(self):
266268
assert service is not None
267269
assert service.account_name == self.tables_storage_account_name
268270
assert service.url.startswith('https://' + self.tables_storage_account_name + '.table.core.windows.net')
269-
assert service.url.endswith(self.generate_sas_token())
271+
assert service.url.endswith(token)
270272
assert service.credential is None
271273

272274
@pytest.mark.asyncio
@@ -402,7 +404,8 @@ async def test_create_service_with_conn_str_succeeds_if_sec_with_primary_async(s
402404

403405
@pytest.mark.asyncio
404406
async def test_create_service_with_custom_account_endpoint_path_async(self):
405-
custom_account_url = "http://local-machine:11002/custom/account/path/" + self.generate_sas_token()
407+
token = self.generate_sas_token()
408+
custom_account_url = "http://local-machine:11002/custom/account/path/" + token
406409
for service_type in SERVICES.items():
407410
conn_string = 'DefaultEndpointsProtocol=http;AccountName={};AccountKey={};TableEndpoint={};'.format(
408411
self.tables_storage_account_name, self.tables_primary_storage_account_key, custom_account_url)
@@ -429,7 +432,7 @@ async def test_create_service_with_custom_account_endpoint_path_async(self):
429432
assert service._primary_hostname == 'local-machine:11002/custom/account/path'
430433
assert service.url.startswith('http://local-machine:11002/custom/account/path')
431434

432-
service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + self.generate_sas_token())
435+
service = TableClient.from_table_url("http://local-machine:11002/custom/account/path/foo" + token)
433436
assert service.account_name == None
434437
assert service.table_name == "foo"
435438
assert service.credential == None

sdk/tables/azure-data-tables/tests/test_table_client_cosmos.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def callback(response):
4949
count = 0
5050
for table in tables:
5151
count += 1
52-
assert count == 0
5352

5453
if self.is_live:
5554
sleep(SLEEP_DELAY)
@@ -71,10 +70,10 @@ def callback(response):
7170
tables = list(service.list_tables(raw_response_hook=callback))
7271
assert isinstance(tables, list)
7372

73+
# The count doesn't matter, going through the PagedItem calls `callback`
7474
count = 0
7575
for table in tables:
7676
count += 1
77-
assert count == 0
7877

7978
def callback(response):
8079
assert 'User-Agent' in response.http_request.headers
@@ -86,10 +85,10 @@ def callback(response):
8685
tables = list(service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0"))
8786
assert isinstance(tables, list)
8887

88+
# The count doesn't matter, going through the PagedItem calls `callback`
8989
count = 0
9090
for table in tables:
9191
count += 1
92-
assert count == 0
9392

9493
if self.is_live:
9594
sleep(SLEEP_DELAY)
@@ -108,10 +107,10 @@ def callback(response):
108107
custom_headers = {'User-Agent': 'customer_user_agent'}
109108
tables = service.list_tables(raw_response_hook=callback, headers=custom_headers)
110109

110+
# The count doesn't matter, going through the PagedItem calls `callback`
111111
count = 0
112112
for table in tables:
113113
count += 1
114-
assert count == 0
115114

116115
if self.is_live:
117116
sleep(SLEEP_DELAY)

sdk/tables/azure-data-tables/tests/test_table_client_cosmos_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def callback(response):
4444
tables = service.list_tables(raw_response_hook=callback)
4545
assert tables is not None
4646

47+
# The count doesn't matter, going through the PagedItem calls `callback`
4748
count = 0
4849
async for table in tables:
4950
count += 1
50-
assert count == 0
5151

5252
if self.is_live:
5353
sleep(SLEEP_DELAY)
@@ -68,10 +68,10 @@ def callback(response):
6868
tables = service.list_tables(raw_response_hook=callback)
6969
assert tables is not None
7070

71+
# The count doesn't matter, going through the PagedItem calls `callback`
7172
count = 0
7273
async for table in tables:
7374
count += 1
74-
assert count == 0
7575

7676
def callback(response):
7777
assert 'User-Agent' in response.http_request.headers
@@ -80,10 +80,10 @@ def callback(response):
8080
platform.python_version(),
8181
platform.platform()) in response.http_request.headers['User-Agent']
8282

83+
# The count doesn't matter, going through the PagedItem calls `callback`
8384
count = 0
8485
async for table in tables:
8586
count += 1
86-
assert count == 0
8787

8888
if self.is_live:
8989
sleep(SLEEP_DELAY)
@@ -99,10 +99,10 @@ def callback(response):
9999
custom_headers = {'User-Agent': 'customer_user_agent'}
100100
tables = service.list_tables(raw_response_hook=callback, headers=custom_headers)
101101

102+
# The count doesn't matter, going through the PagedItem calls `callback`
102103
count = 0
103104
async for table in tables:
104105
count += 1
105-
assert count == 0
106106

107107
if self.is_live:
108108
sleep(SLEEP_DELAY)

0 commit comments

Comments
 (0)