def test_aad_create_table_tc(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() table_client = TableClient( credential=self.get_token_credential(), endpoint=account_url, table_name=table_name ) table_client.create_table() if table_name not in [t.name for t in ts.list_tables()]: raise AssertionError("Table could not be found") table_client.delete_table() 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_table_name_errors_bad_chars(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): endpoint = self.account_url(tables_cosmos_account_name, "cosmos") # cosmos table names must be a non-empty string without chars '\', '/', '#', '?', and less than 255 chars. invalid_table_names = ["\\", "//", "#", "?", "- "] for invalid_name in invalid_table_names: client = TableClient(endpoint=endpoint, credential=tables_primary_cosmos_account_key, table_name=invalid_name) with pytest.raises(ValueError) as error: client.create_table() assert "Cosmos table names must contain from 1-255 characters" in str( error.value) try: with pytest.raises(ValueError) as error: client.delete_table() assert "Cosmos table names must contain from 1-255 characters" in str( error.value) except HttpResponseError as error: # Delete table returns a MethodNotAllowed for tablename == "\" if error.error_code != 'MethodNotAllowed': raise with pytest.raises(ValueError) as error: client.create_entity({'PartitionKey': 'foo', 'RowKey': 'foo'}) assert "Cosmos table names must contain from 1-255 characters" in str( error.value) with pytest.raises(ValueError) as error: client.upsert_entity({'PartitionKey': 'foo', 'RowKey': 'foo'}) assert "Cosmos table names must contain from 1-255 characters" in str( error.value) with pytest.raises(ValueError) as error: client.delete_entity("PK", "RK") assert "Cosmos table names must contain from 1-255 characters" in str( error.value) with pytest.raises(ValueError) as error: batch = [] batch.append(('upsert', {'PartitionKey': 'A', 'RowKey': 'B'})) client.submit_transaction(batch) assert "Cosmos table names must contain from 1-255 characters" in str( error.value)
def test_table_name_errors_bad_length(self, tables_cosmos_account_name, tables_primary_cosmos_account_key): endpoint = self.account_url(tables_cosmos_account_name, "cosmos") # cosmos table names must be a non-empty string without chars '\', '/', '#', '?', and less than 255 chars. client = TableClient(endpoint=endpoint, credential=tables_primary_cosmos_account_key, table_name="-" * 255) with pytest.raises(ValueError) as error: client.create_table() assert "Cosmos table names must contain from 1-255 characters" in str( error.value) with pytest.raises(ResourceNotFoundError): client.create_entity({'PartitionKey': 'foo', 'RowKey': 'foo'}) with pytest.raises(ResourceNotFoundError): client.upsert_entity({'PartitionKey': 'foo', 'RowKey': 'foo'}) with pytest.raises(TableTransactionError) as error: batch = [] batch.append(('upsert', {'PartitionKey': 'A', 'RowKey': 'B'})) client.submit_transaction(batch) assert error.value.error_code == 'ResourceNotFound'
def test_table_name_errors(self, tables_storage_account_name, tables_primary_storage_account_key): endpoint = self.account_url(tables_storage_account_name, "table") # storage table names must be alphanumeric, cannot begin with a number, and must be between 3 and 63 chars long. invalid_table_names = ["1table", "a" * 2, "a" * 64, "a//", "my_table"] for invalid_name in invalid_table_names: client = TableClient(endpoint=endpoint, credential=tables_primary_storage_account_key, table_name=invalid_name) with pytest.raises(ValueError) as error: client.create_table() assert 'Storage table names must be alphanumeric' in str( error.value) with pytest.raises(ValueError) as error: client.create_entity({'PartitionKey': 'foo', 'RowKey': 'bar'}) assert 'Storage table names must be alphanumeric' in str( error.value) with pytest.raises(ValueError) as error: client.upsert_entity({'PartitionKey': 'foo', 'RowKey': 'foo'}) assert 'Storage table names must be alphanumeric' in str( error.value) with pytest.raises(ValueError) as error: client.delete_entity("PK", "RK") assert 'Storage table names must be alphanumeric' in str( error.value) with pytest.raises(ValueError) as error: client.get_table_access_policy() assert 'Storage table names must be alphanumeric' in str( error.value) with pytest.raises(ValueError): batch = [] batch.append(('upsert', {'PartitionKey': 'A', 'RowKey': 'B'})) client.submit_transaction(batch) assert 'Storage table names must be alphanumeric' in str( error.value)