def test_user_agent_custom(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): custom_app = "TestApp/v1.0" service = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), credential=tables_primary_cosmos_account_key, user_agent=custom_app) def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback)) assert isinstance(tables, list) def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v2.0 TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0")) assert isinstance(tables, list) if self.is_live: sleep(SLEEP_DELAY)
def test_query_tables_with_num_results(self, resource_group, location, cosmos_account, cosmos_account_key): # Arrange prefix = 'listtable' ts = TableServiceClient(self.account_url(cosmos_account, "cosmos"), cosmos_account_key) table_list = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_list) # Act small_page = [] big_page = [] for s in next(ts.list_tables(results_per_page=3).by_page()): small_page.append(s) assert s.table_name.startswith(prefix) for t in next(ts.list_tables().by_page()): big_page.append(t) assert t.table_name.startswith(prefix) # Assert self.assertEqual(len(small_page), 3) self.assertGreaterEqual(len(big_page), 4) self._delete_all_tables(ts) if self.is_live: sleep(SLEEP_DELAY)
def test_query_tables_with_marker(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=tables_primary_storage_account_key, endpoint=account_url) prefix = 'listtable' table_names = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_names) # Act generator1 = ts.list_tables(results_per_page=2).by_page() next(generator1) generator2 = ts.list_tables(results_per_page=2).by_page( continuation_token=generator1.continuation_token) next(generator2) tables1 = generator1._current_page tables2 = generator2._current_page # Assert assert len(tables1) == 2 assert len(tables2) == 2 assert tables1 != tables2 self._delete_all_tables(ts)
def test_query_tables_with_num_results(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange prefix = 'listtable' ts = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) table_list = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_list) # Act small_page = [] big_page = [] for s in next(ts.list_tables(results_per_page=3).by_page()): small_page.append(s) assert s.name.startswith(prefix) for t in next(ts.list_tables().by_page()): big_page.append(t) assert t.name.startswith(prefix) # Assert assert len(small_page) == 3 assert len(big_page) >= 4 self._delete_all_tables(ts) if self.is_live: sleep(SLEEP_DELAY)
def test_user_agent_custom(self, resource_group, location, storage_account, storage_account_key): custom_app = "TestApp/v1.0" service = TableServiceClient(self.account_url(storage_account, "table"), credential=storage_account_key, user_agent=custom_app) def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform() ) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback)) assert isinstance(tables, list) def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v2.0 TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform() ) in response.http_request.headers['User-Agent'] tables = list( service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0")) assert isinstance(tables, list)
def test_query_tables_with_marker(self, resource_group, location, storage_account, storage_account_key): # Arrange ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) prefix = 'listtable' table_names = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_names) # table_names.sort() # Act generator1 = ts.list_tables(results_per_page=2).by_page() next(generator1) generator2 = ts.list_tables(results_per_page=2).by_page( continuation_token=generator1.continuation_token) next(generator2) tables1 = generator1._current_page tables2 = generator2._current_page # Assert self.assertEqual(len(tables1), 2) self.assertEqual(len(tables2), 2) self.assertNotEqual(tables1, tables2)
def test_query_tables_with_marker(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange ts = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) prefix = 'listtable' table_names = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_names) # table_names.sort() # Act generator1 = ts.list_tables(results_per_page=2).by_page() next(generator1) generator2 = ts.list_tables(results_per_page=2).by_page( continuation_token=generator1.continuation_token) next(generator2) tables1 = generator1._current_page tables2 = generator2._current_page # Assert assert len(tables1) == 2 assert len(tables2) == 2 assert tables1 != tables2 self._delete_all_tables(ts) if self.is_live: sleep(SLEEP_DELAY)
def test_user_agent_custom(self, resource_group, location, cosmos_account, cosmos_account_key): custom_app = "TestApp/v1.0" service = TableServiceClient(self.account_url(cosmos_account, "cosmos"), credential=cosmos_account_key, user_agent=custom_app) def callback(response): self.assertTrue('User-Agent' in response.http_request.headers) self.assertIn( "TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})". format(VERSION, platform.python_version(), platform.platform()), response.http_request.headers['User-Agent']) tables = list(service.list_tables(raw_response_hook=callback)) self.assertIsInstance(tables, list) def callback(response): self.assertTrue('User-Agent' in response.http_request.headers) self.assertIn( "TestApp/v2.0 TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})" .format(VERSION, platform.python_version(), platform.platform()), response.http_request.headers['User-Agent']) tables = list( service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0")) self.assertIsInstance(tables, list) if self.is_live: sleep(SLEEP_DELAY)
def test_query_tables_with_num_results(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange prefix = 'listtable' account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=tables_primary_storage_account_key, endpoint=account_url) table_list = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_list) # Act small_page = [] big_page = [] for s in next(ts.list_tables(results_per_page=3).by_page()): small_page.append(s) assert s.name.startswith(prefix) for t in next(ts.list_tables().by_page()): big_page.append(t) assert t.name.startswith(prefix) # Assert assert len(small_page) == 3 assert len(big_page) >= 4 self._delete_all_tables(ts)
def test_user_agent_custom(self, tables_storage_account_name, tables_primary_storage_account_key): custom_app = "TestApp/v1.0" service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), credential=tables_primary_storage_account_key, user_agent=custom_app) def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback)) assert isinstance(tables, list) # The count doesn't matter, going through the PagedItem calls `callback` count = 0 for table in tables: count += 1 def callback(response): assert 'User-Agent' in response.http_request.headers assert "TestApp/v2.0 TestApp/v1.0 azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback, user_agent="TestApp/v2.0")) assert isinstance(tables, list) # The count doesn't matter, going through the PagedItem calls `callback` count = 0 for table in tables: count += 1
def test_aad_query_list_tables(self, tables_storage_account_name): try: account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=self.get_token_credential(), endpoint=account_url) table_name1 = self._get_table_reference(prefix="table1") table_name2 = self._get_table_reference(prefix="table2") table_name3 = self._get_table_reference(prefix="table3") table_name4 = self._get_table_reference(prefix="table4") ts.create_table(table_name1) ts.create_table(table_name2) ts.create_table(table_name3) ts.create_table(table_name4) count = 0 for table in ts.list_tables(): count += 1 assert count == 4 query_filter = "TableName eq '{}'".format(table_name2) count = 0 for table in ts.query_tables(query_filter): count += 1 assert table.name == table_name2 assert count == 1 finally: for table in ts.list_tables(): ts.delete_table(table.name)
def test_locale(self, resource_group, location, storage_account, storage_account_key): # Arrange ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) table = (self._get_table_reference()) init_locale = locale.getlocale() if os.name == "nt": culture = "Spanish_Spain" elif os.name == 'posix': culture = 'es_ES.UTF-8' else: culture = 'es_ES.utf8' locale.setlocale(locale.LC_ALL, culture) e = None # Act ts.create_table(table) resp = ts.list_tables() e = sys.exc_info()[0] # Assert self.assertIsNone(e) ts.delete_table(table) locale.setlocale(locale.LC_ALL, init_locale[0] or 'en_US')
def test_locale(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange ts = TableServiceClient( self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) table = (self._get_table_reference()) init_locale = locale.getlocale() if os.name == "nt": culture = "Spanish_Spain" elif os.name == 'posix': culture = 'es_ES.UTF-8' else: culture = 'es_ES.utf8' locale.setlocale(locale.LC_ALL, culture) e = None # Act ts.create_table(table) resp = ts.list_tables() e = sys.exc_info()[0] # Assert assert e is None ts.delete_table(table) locale.setlocale(locale.LC_ALL, init_locale[0] or 'en_US') if self.is_live: sleep(SLEEP_DELAY)
async def _delete_all_tables(self, account_name, key): client = TableServiceClient(self.account_url(account_name, "cosmos"), key) async for table in client.list_tables(): await client.delete_table(table.name) if self.is_live: self.sleep(10)
def test_aad_create_table(self, tables_storage_account_name): try: account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=self.get_token_credential(), endpoint=account_url) table_name = self._get_table_reference() ts.create_table(table_name) if table_name not in [t.name for t in ts.list_tables()]: raise AssertionError("Table could not be found") ts.delete_table(table_name) if table_name in [t.name for t in ts.list_tables()]: raise AssertionError("Table was not deleted") finally: ts.delete_table(table_name)
def test_query_tables_with_num_results(self, resource_group, location, storage_account, storage_account_key): # Arrange prefix = 'listtable' ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) table_list = [] for i in range(0, 4): self._create_table(ts, prefix + str(i), table_list) # Act small_page = [] big_page = [] for s in next(ts.list_tables(results_per_page=3).by_page()): small_page.append(s) for t in next(ts.list_tables().by_page()): big_page.append(t) # Assert self.assertEqual(len(small_page), 3) self.assertGreaterEqual(len(big_page), 4)
def test_user_agent_append(self, resource_group, location, storage_account, storage_account_key): service = TableServiceClient(self.account_url(storage_account, "table"), credential=storage_account_key) def callback(response): assert 'User-Agent' in response.http_request.headers assert response.http_request.headers['User-Agent'] == "azsdk-python-data-tables/{} Python/{} ({}) customer_user_agent".format( VERSION, platform.python_version(), platform.platform()) custom_headers = {'User-Agent': 'customer_user_agent'} tables = service.list_tables(raw_response_hook=callback, headers=custom_headers)
def test_user_agent_default(self, resource_group, location, storage_account, storage_account_key): service = TableServiceClient(self.account_url(storage_account, "table"), credential=storage_account_key) def callback(response): self.assertTrue('User-Agent' in response.http_request.headers) self.assertIn("azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()), response.http_request.headers['User-Agent']) tables = list(service.list_tables(raw_response_hook=callback)) self.assertIsInstance(tables, list)
def test_user_agent_append(self, tables_storage_account_name, tables_primary_storage_account_key): service = TableServiceClient(self.account_url(tables_storage_account_name, "table"), credential=tables_primary_storage_account_key) def callback(response): assert 'User-Agent' in response.http_request.headers assert response.http_request.headers['User-Agent'] == 'customer_user_agent' custom_headers = {'User-Agent': 'customer_user_agent'} tables = service.list_tables(raw_response_hook=callback, headers=custom_headers) # The count doesn't matter, going through the PagedItem calls `callback` count = 0 for table in tables: count += 1
def test_query_tables(self, resource_group, location, storage_account, storage_account_key): # Arrange ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) table = self._create_table(ts) # Act tables = list(ts.list_tables()) # Assert self.assertIsNotNone(tables) self.assertGreaterEqual(len(tables), 1) self.assertIsNotNone(tables[0]) # self.assertNamedItemInContainer(tables, table.table_name) ts.delete_table(table.table_name)
def test_user_agent_default(self, tables_storage_account_name, tables_primary_storage_account_key): service = TableServiceClient( self.account_url(tables_storage_account_name, "table"), credential=tables_primary_storage_account_key) def callback(response): assert 'User-Agent' in response.http_request.headers assert "azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform() ) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback)) assert isinstance(tables, list)
def test_user_agent_default(self, cosmos_account, cosmos_account_key): service = TableServiceClient(self.account_url(cosmos_account, "cosmos"), credential=cosmos_account_key) def callback(response): assert 'User-Agent' in response.http_request.headers assert "azsdk-python-data-tables/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform()) in response.http_request.headers['User-Agent'] tables = list(service.list_tables(raw_response_hook=callback)) assert isinstance(tables, list) if self.is_live: sleep(SLEEP_DELAY)
def test_query_tables(self, resource_group, location, cosmos_account, cosmos_account_key): # Arrange ts = TableServiceClient(self.account_url(cosmos_account, "cosmos"), cosmos_account_key) table = self._create_table(ts) # Act tables = list(ts.list_tables()) # Assert self.assertIsNotNone(tables) self.assertGreaterEqual(len(tables), 1) self.assertIsNotNone(tables[0]) ts.delete_table(table.table_name) if self.is_live: sleep(SLEEP_DELAY)
def test_list_tables(self, resource_group, location, storage_account, storage_account_key): # Arrange ts = TableServiceClient(self.account_url(storage_account, "table"), storage_account_key) t = self._create_table(ts) # Act tables = list(ts.list_tables()) # Assert for table_item in tables: self.assertIsInstance(table_item, TableItem) self.assertIsNotNone(tables) self.assertGreaterEqual(len(tables), 1) self.assertIsNotNone(tables[0]) ts.delete_table(t.table_name)
def test_query_tables(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): # Arrange ts = TableServiceClient(self.account_url(tables_cosmos_account_name, "cosmos"), tables_primary_cosmos_account_key) table = self._create_table(ts) # Act tables = list(ts.list_tables()) # Assert assert tables is not None assert len(tables) >= 1 assert tables[0] is not None ts.delete_table(table.table_name) if self.is_live: sleep(SLEEP_DELAY)
def test_user_agent_default(self, resource_group, location, cosmos_account, cosmos_account_key): service = TableServiceClient(self.account_url(cosmos_account, "cosmos"), credential=cosmos_account_key) def callback(response): self.assertTrue('User-Agent' in response.http_request.headers) self.assertEqual( response.http_request.headers['User-Agent'], "azsdk-python-storage-table/{} Python/{} ({})".format( VERSION, platform.python_version(), platform.platform())) tables = list(service.list_tables(raw_response_hook=callback)) self.assertIsInstance(tables, list) if self.is_live: sleep(SLEEP_DELAY)
def test_query_tables(self, tables_storage_account_name, tables_primary_storage_account_key): # Arrange account_url = self.account_url(tables_storage_account_name, "table") ts = TableServiceClient(credential=tables_primary_storage_account_key, endpoint=account_url) t = self._create_table(ts) # Act tables = list(ts.list_tables()) # Assert for table_item in tables: assert isinstance(table_item, TableItem) assert tables is not None assert len(tables) >= 1 assert tables[0] is not None self._delete_all_tables(ts)
def test_user_agent_append(self, resource_group, location, cosmos_account, cosmos_account_key): service = TableServiceClient(self.account_url(cosmos_account, "cosmos"), credential=cosmos_account_key) def callback(response): self.assertTrue('User-Agent' in response.http_request.headers) self.assertEqual( response.http_request.headers['User-Agent'], "azsdk-python-storage-tables/{} Python/{} ({}) customer_user_agent" .format(VERSION, platform.python_version(), platform.platform())) custom_headers = {'User-Agent': 'customer_user_agent'} tables = service.list_tables(raw_response_hook=callback, headers=custom_headers) if self.is_live: sleep(SLEEP_DELAY)