Esempio n. 1
0
    def test_write_blob_consistency_size(self, create_mock,
                                         put_blob_from_path_mock,
                                         get_blob_properties_mock):
        from azure.storage.blob.models import Blob, BlobProperties

        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        fake_properties = BlobProperties()
        fake_properties.content_length = 999
        get_blob_properties_mock.return_value = Blob(props=fake_properties)

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState,
                                     'has unexpected size'):
            writer.finish_writing()
    def test_write_blob(self, create_mock, put_block_blob_mock):

        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        # then:
        self.assertEqual(writer.get_metadata('items_count'), 2)
Esempio n. 3
0
    def test_write_blob(self, create_mock, put_block_blob_mock):

        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        # then:
        self.assertEqual(writer.get_metadata('items_count'), 2)
    def test_write_blob_consistency_present(self, create_mock, create_blob_from_path_mock,
                                            get_blob_properties_mock):
        from azure.common import AzureMissingResourceHttpError
        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        get_blob_properties_mock.side_effect = AzureMissingResourceHttpError('', 404)

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'Missing blob'):
            writer.finish_writing()
Esempio n. 5
0
    def test_write_blob_consistency_present(self, create_mock,
                                            create_blob_from_path_mock,
                                            get_blob_properties_mock):
        from azure.common import AzureMissingResourceHttpError
        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        get_blob_properties_mock.side_effect = AzureMissingResourceHttpError(
            '', 404)

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'Missing blob'):
            writer.finish_writing()
    def test_write_blob_consistency_size(self, create_mock, put_blob_from_path_mock,
                                         get_blob_properties_mock):
        from azure.storage.blob.models import Blob, BlobProperties

        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        fake_properties = BlobProperties()
        fake_properties.content_length = 999
        get_blob_properties_mock.return_value = Blob(props=fake_properties)

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'has unexpected size'):
            writer.finish_writing()