Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)