def test_inferred_types(self):
        # Arrange
        # Act
        entity = TableEntity()
        entity.PartitionKey = '003'
        entity.RowKey = 'batch_all_operations_together-1'
        entity.test = EntityProperty(True)
        entity.test2 = EntityProperty(b'abcdef')
        entity.test3 = EntityProperty(u'c9da6455-213d-42c9-9a79-3e9149a57833')
        entity.test4 = EntityProperty(datetime(1973, 10, 4, tzinfo=tzutc()))
        entity.test5 = EntityProperty(u"stringystring")
        entity.test6 = EntityProperty(3.14159)
        entity.test7 = EntityProperty(100)
        entity.test8 = EntityProperty(10, EdmType.INT64)

        # Assert
        assert entity.test.type == EdmType.BOOLEAN
        assert entity.test2.type == EdmType.BINARY
        assert entity.test3.type == EdmType.GUID
        assert entity.test4.type == EdmType.DATETIME
        assert entity.test5.type == EdmType.STRING
        assert entity.test6.type == EdmType.DOUBLE
        assert entity.test7.type == EdmType.INT32
        assert entity.test8.type == EdmType.INT64
    async def test_batch_all_operations_together(
            self, tables_cosmos_account_name,
            tables_primary_cosmos_account_key):
        # Arrange
        await self._set_up(tables_cosmos_account_name,
                           tables_primary_cosmos_account_key)
        try:
            # Act
            entity = TableEntity()
            entity.PartitionKey = '003'
            entity.RowKey = 'batch_all_operations_together-1'
            entity.test = EntityProperty(True)
            entity.test2 = 'value'
            entity.test3 = 3
            entity.test4 = EntityProperty(1234567890)
            entity.test5 = datetime.utcnow()
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-2'
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-3'
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-4'
            await self.table.create_entity(entity)

            transaction_count = 0

            batch = self.table.create_batch()
            entity.RowKey = 'batch_all_operations_together'
            batch.create_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-1'
            batch.delete_entity(entity.PartitionKey, entity.RowKey)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-2'
            entity.test3 = 10
            batch.update_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-3'
            entity.test3 = 100
            batch.update_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-4'
            entity.test3 = 10
            batch.upsert_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-5'
            batch.upsert_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            transaction_result = await self.table.send_batch(batch)

            # Assert
            self._assert_valid_batch_transaction(transaction_result,
                                                 transaction_count)
            assert transaction_result.get_entity(
                'batch_all_operations_together') is not None
            assert transaction_result.get_entity(
                'batch_all_operations_together-1') is not None
            assert transaction_result.get_entity(
                'batch_all_operations_together-2') is not None
            assert transaction_result.get_entity(
                'batch_all_operations_together-3') is not None
            assert transaction_result.get_entity(
                'batch_all_operations_together-4') is not None
            assert transaction_result.get_entity(
                'batch_all_operations_together-5') is not None

            entities = self.table.query_entities("PartitionKey eq '003'")
            length = 0
            async for e in entities:
                length += 1
            assert 5 == length
        finally:
            await self._tear_down()
Beispiel #3
0
    async def test_batch_all_operations_together(
            self, tables_cosmos_account_name,
            tables_primary_cosmos_account_key):
        # Arrange
        await self._set_up(tables_cosmos_account_name,
                           tables_primary_cosmos_account_key)
        try:
            # Act
            entity = TableEntity()
            entity.PartitionKey = '003'
            entity.RowKey = 'batch_all_operations_together-1'
            entity.test = EntityProperty(True)
            entity.test2 = 'value'
            entity.test3 = 3
            entity.test4 = EntityProperty(1234567890)
            entity.test5 = datetime.utcnow()
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-2'
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-3'
            await self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-4'
            await self.table.create_entity(entity)

            transaction_count = 0

            batch = []
            entity.RowKey = 'batch_all_operations_together'
            batch.append((TransactionOperation.CREATE, entity.copy()))
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-1'
            batch.append((TransactionOperation.DELETE, entity.copy()))
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-2'
            entity.test3 = 10
            batch.append((TransactionOperation.UPDATE, entity.copy()))
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-3'
            entity.test3 = 100
            batch.append((TransactionOperation.UPDATE, entity.copy(), {
                'mode': UpdateMode.REPLACE
            }))
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-4'
            entity.test3 = 10
            batch.append((TransactionOperation.UPSERT, entity.copy()))
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-5'
            batch.append((TransactionOperation.UPSERT, entity.copy(), {
                'mode': UpdateMode.REPLACE
            }))
            transaction_count += 1

            transaction_result = await self.table.submit_transaction(batch)

            # Assert
            self._assert_valid_batch_transaction(transaction_result,
                                                 transaction_count)
            assert 'etag' in transaction_result[0]
            assert 'etag' not in transaction_result[1]
            assert 'etag' in transaction_result[2]
            assert 'etag' in transaction_result[3]
            assert 'etag' in transaction_result[4]
            assert 'etag' in transaction_result[5]

            entities = self.table.query_entities("PartitionKey eq '003'")
            length = 0
            async for e in entities:
                length += 1
            assert 5 == length
        finally:
            await self._tear_down()
Beispiel #4
0
    def test_batch_all_operations_together(self, resource_group, location,
                                           storage_account,
                                           storage_account_key):
        # Arrange
        self._set_up(storage_account, storage_account_key)
        try:
            # Act
            entity = TableEntity()
            entity.PartitionKey = '003'
            entity.RowKey = 'batch_all_operations_together-1'
            entity.test = EntityProperty(True)
            entity.test2 = 'value'
            entity.test3 = 3
            entity.test4 = EntityProperty(1234567890)
            entity.test5 = datetime.utcnow()
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-2'
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-3'
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-4'
            self.table.create_entity(entity)
            transaction_count = 0

            batch = self.table.create_batch()
            entity.RowKey = 'batch_all_operations_together'
            batch.create_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-1'
            batch.delete_entity(entity.PartitionKey, entity.RowKey)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-2'
            entity.test3 = 10
            batch.update_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-3'
            entity.test3 = 100
            batch.update_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-4'
            entity.test3 = 10
            batch.upsert_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-5'
            batch.upsert_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            transaction_result = self.table.send_batch(batch)

            # Assert
            self._assert_valid_batch_transaction(transaction_result,
                                                 transaction_count)
            self.assertIsNotNone(
                transaction_result.get_entity('batch_all_operations_together'))
            self.assertIsNotNone(
                transaction_result.get_entity(
                    'batch_all_operations_together-1'))
            self.assertIsNotNone(
                transaction_result.get_entity(
                    'batch_all_operations_together-2'))
            self.assertIsNotNone(
                transaction_result.get_entity(
                    'batch_all_operations_together-3'))
            self.assertIsNotNone(
                transaction_result.get_entity(
                    'batch_all_operations_together-4'))
            self.assertIsNotNone(
                transaction_result.get_entity(
                    'batch_all_operations_together-5'))

            # Assert
            entities = list(self.table.query_entities("PartitionKey eq '003'"))
            self.assertEqual(5, len(entities))
        finally:
            self._tear_down()
Beispiel #5
0
    def test_batch_all_operations_together(self, tables_cosmos_account_name,
                                           tables_primary_cosmos_account_key):
        # Arrange
        self._set_up(tables_cosmos_account_name,
                     tables_primary_cosmos_account_key)
        try:
            # Act
            entity = TableEntity()
            entity.PartitionKey = '003'
            entity.RowKey = 'batch_all_operations_together-1'
            entity.test = EntityProperty(True)
            entity.test2 = 'value'
            entity.test3 = 3
            entity.test4 = EntityProperty(1234567890)
            entity.test5 = datetime.utcnow()
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-2'
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-3'
            self.table.create_entity(entity)
            entity.RowKey = 'batch_all_operations_together-4'
            self.table.create_entity(entity)
            transaction_count = 0

            batch = self.table.create_batch()
            entity.RowKey = 'batch_all_operations_together'
            batch.create_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-1'
            batch.delete_entity(entity.PartitionKey, entity.RowKey)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-2'
            entity.test3 = 10
            batch.update_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-3'
            entity.test3 = 100
            batch.update_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-4'
            entity.test3 = 10
            batch.upsert_entity(entity)
            transaction_count += 1

            entity.RowKey = 'batch_all_operations_together-5'
            batch.upsert_entity(entity, mode=UpdateMode.MERGE)
            transaction_count += 1

            transaction_result = self.table.send_batch(batch)

            # Assert
            self._assert_valid_batch_transaction(transaction_result,
                                                 transaction_count)
            assert transaction_result[0][0][
                'RowKey'] == u'batch_all_operations_together'
            assert 'etag' in transaction_result[0][1]
            assert transaction_result[1][0][
                'RowKey'] == u'batch_all_operations_together-1'
            assert 'etag' not in transaction_result[1][1]
            assert transaction_result[2][0][
                'RowKey'] == u'batch_all_operations_together-2'
            assert 'etag' in transaction_result[2][1]
            assert transaction_result[3][0][
                'RowKey'] == u'batch_all_operations_together-3'
            assert 'etag' in transaction_result[3][1]
            assert transaction_result[4][0][
                'RowKey'] == u'batch_all_operations_together-4'
            assert 'etag' in transaction_result[4][1]
            assert transaction_result[5][0][
                'RowKey'] == u'batch_all_operations_together-5'
            assert 'etag' in transaction_result[5][1]

            # Assert
            entities = list(self.table.query_entities("PartitionKey eq '003'"))
            assert 5 == len(entities)
        finally:
            self._tear_down()