def test_delete_blob(self): file_name = 'delete_me.txt' # Upload a file tmp_file_path = files.string_to_temp_file('A little string', suffix='.txt') self.cloud.put_blob(TEMP_BUCKET_NAME, file_name, tmp_file_path) # Check that it was deleted. self.cloud.delete_blob(TEMP_BUCKET_NAME, file_name) self.assertFalse(self.cloud.blob_exists(TEMP_BUCKET_NAME, file_name))
def setUp(self): self.cloud = GoogleCloudStorage() # Running into some issues creating and delete too many buckets, so # will check to see if it already exists if not self.cloud.bucket_exists(TEMP_BUCKET_NAME): self.cloud.create_bucket(TEMP_BUCKET_NAME) # Upload a file tmp_file_path = files.string_to_temp_file('A little string', suffix='.txt') self.cloud.put_blob(TEMP_BUCKET_NAME, TEMP_FILE_NAME, tmp_file_path)
def test_put_blob(self): # Assert that put_blob returns a BlobClient object put_blob_name = 'tmp_file_put.txt' tmp_file_path = files.string_to_temp_file('Test', suffix='.txt') put_blob_client = self.azure_blob.put_blob(TEST_CONTAINER_NAME, put_blob_name, tmp_file_path) self.assertIsInstance(put_blob_client, BlobClient) self.azure_blob.delete_blob(TEST_CONTAINER_NAME, put_blob_name)
def setup_google_application_credentials(app_creds, env_var_name='GOOGLE_APPLICATION_CREDENTIALS'): # Detect if the app_creds string is a path or json and if it is a # json string, then convert it to a temporary file. Then set the # environmental variable. credentials = check_env.check(env_var_name, app_creds) try: json.loads(credentials) creds_path = files.string_to_temp_file(credentials, suffix='.json') except ValueError: creds_path = credentials os.environ[env_var_name] = creds_path
def setUp(self): self.azure_blob = AzureBlobStorage(account_name=TEST_ACCOUNT_NAME, credential=TEST_CREDENTIAL) # Create the container if it does not exist already if not self.azure_blob.container_exists(TEST_CONTAINER_NAME): self.azure_blob.create_container(TEST_CONTAINER_NAME) # Create blob if it doesn't exist already if not self.azure_blob.blob_exists(TEST_CONTAINER_NAME, TEST_FILE_NAME): tmp_file_path = files.string_to_temp_file(TEST_FILE_CONTENTS, suffix='.txt') self.azure_blob.put_blob(TEST_CONTAINER_NAME, TEST_FILE_NAME, tmp_file_path)
def test_delete_blob(self): delete_blob_name = 'delete_blob.txt' # Upload a blob, assert that it exists tmp_file_path = files.string_to_temp_file(TEST_FILE_CONTENTS, suffix='.txt') self.azure_blob.put_blob(TEST_CONTAINER_NAME, delete_blob_name, tmp_file_path) self.assertTrue( self.azure_blob.blob_exists(TEST_CONTAINER_NAME, delete_blob_name)) # Delete the blob, assert that it no longer exists self.azure_blob.delete_blob(TEST_CONTAINER_NAME, delete_blob_name) self.assertFalse( self.azure_blob.blob_exists(TEST_CONTAINER_NAME, delete_blob_name))