def test_configure_client(self, mock_blob_service_factory): connection_timeout = 3 read_timeout = 11 self.app.conf.update({ 'azureblockblob_connection_timeout': connection_timeout, 'azureblockblob_read_timeout': read_timeout, }) mock_blob_service_client_instance = Mock() mock_blob_service_factory.from_connection_string.return_value = ( mock_blob_service_client_instance) base_url = "azureblockblob://" connection_string = "connection_string" backend = AzureBlockBlobBackend(app=self.app, url=f'{base_url}{connection_string}') client = backend._blob_service_client assert client is mock_blob_service_client_instance (mock_blob_service_factory.from_connection_string. assert_called_once_with(connection_string, connection_timeout=connection_timeout, read_timeout=read_timeout))
def setup(self): self.url = ("azureblockblob://" "DefaultEndpointsProtocol=protocol;" "AccountName=name;" "AccountKey=account_key;" "EndpointSuffix=suffix") self.backend = AzureBlockBlobBackend(app=self.app, url=self.url)
def test_base_path_conf(self, base_path): self.app.conf.azureblockblob_base_path = base_path backend = AzureBlockBlobBackend( app=self.app, url=self.url ) assert backend.base_path == base_path
def test_missing_third_party_sdk(self): azurestorage = azureblockblob.azurestorage try: azureblockblob.azurestorage = None with pytest.raises(ImproperlyConfigured): AzureBlockBlobBackend(app=self.app, url=self.url) finally: azureblockblob.azurestorage = azurestorage
def test_create_client(self, mock_blob_service_factory): mock_blob_service_client_instance = Mock() mock_blob_service_factory.from_connection_string.return_value = mock_blob_service_client_instance backend = AzureBlockBlobBackend(app=self.app, url=self.url) # ensure container gets created on client access... assert mock_blob_service_client_instance.create_container.call_count == 0 assert backend._blob_service_client is not None assert mock_blob_service_client_instance.create_container.call_count == 1 # ...but only once per backend instance assert backend._blob_service_client is not None assert mock_blob_service_client_instance.create_container.call_count == 1
def test_crud(self, manager): backend = AzureBlockBlobBackend(app=manager.app, url=os.environ["AZUREBLOCKBLOB_URL"]) key_values = {("akey%d" % i).encode(): "avalue%d" % i for i in range(5)} for key, value in key_values.items(): backend.set(key, value) actual_values = backend.mget(key_values.keys()) expected_values = list(key_values.values()) assert expected_values == actual_values for key in key_values: backend.delete(key)
def test_get_missing(self, manager): backend = AzureBlockBlobBackend(app=manager.app, url=os.environ["AZUREBLOCKBLOB_URL"]) assert backend.get(b"doesNotExist") is None
def test_base_path_conf_default(self): backend = AzureBlockBlobBackend(app=self.app, url=self.url) assert backend.base_path == ''