def test_fail_on_missing_auth(self): """ Raise an exception when loading settings for GoogleCloudStorage and no authentication information is found """ settings = {"storage.bucket": "new_bucket", "storage.region_name": "us-east-1"} with self.assertRaises(Exception): GoogleCloudStorage.configure(settings)
def test_fail_on_missing_auth(self): """ Raise an exception when loading settings for GoogleCloudStorage and no authentication information is found """ settings = { "storage.bucket": "new_bucket", "storage.region_name": "us-east-1" } with self.assertRaises(Exception): GoogleCloudStorage.configure(settings)
def test_client_without_credentials(self): """Can create a client without passing in application credentials""" kwargs = GoogleCloudStorage.configure({ "storage.bucket": "new_bucket", "storage.region_name": "us-east-1" }) GoogleCloudStorage(MagicMock(), **kwargs)
def test_storage_class(self): """Can specify a storage class for GCS objects""" settings = dict(self.settings) settings["storage.storage_class"] = "COLDLINE" kwargs = GoogleCloudStorage.configure(settings) storage = GoogleCloudStorage(MagicMock(), **kwargs) package = make_package() storage.upload(package, BytesIO()) blob = self.bucket.list_blobs()[0] blob.update_storage_class.assert_called_with("COLDLINE")
def test_storage_class(self): """ Can specify a storage class for GCS objects """ settings = dict(self.settings) settings["storage.storage_class"] = "COLDLINE" kwargs = GoogleCloudStorage.configure(settings) storage = GoogleCloudStorage(MagicMock(), **kwargs) package = make_package() storage.upload(package, BytesIO()) blob = self.bucket.list_blobs()[0] blob.update_storage_class.assert_called_with("COLDLINE")
def test_create_bucket(self): """ If GCS bucket doesn't exist, create it """ settings = { "storage.bucket": "new_bucket", "storage.region_name": "us-east-1", "storage.gcp_service_account_json_filename": "my-filename.json", } storage = GoogleCloudStorage.configure(settings) self.gcs.bucket.assert_called_with("new_bucket") bucket = self.gcs.bucket("new_bucket") bucket.create.assert_called_once_with()
def test_object_acl(self): """Can specify an object ACL for GCS objects. Just test to make sure that the configured ACL is forwarded to the API client """ settings = dict(self.settings) settings["storage.object_acl"] = "authenticated-read" kwargs = GoogleCloudStorage.configure(settings) storage = GoogleCloudStorage(MagicMock(), **kwargs) package = make_package() storage.upload(package, BytesIO()) blob = self.bucket.list_blobs()[0] self.assertEqual(blob._acl, "authenticated-read")
def test_create_bucket(self): """If GCS bucket doesn't exist, create it""" settings = { "storage.bucket": "new_bucket", "storage.region_name": "us-east-1", "storage.gcp_service_account_json_filename": self._config_file, } arguments = GoogleCloudStorage.configure(settings) arguments["bucket_factory"]() self.gcs.bucket.assert_called_with("new_bucket") bucket = self.gcs.bucket("new_bucket") bucket.create.assert_called_once_with()
def setUp(self): super(TestGoogleCloudStorage, self).setUp() self.gcs = MockGCSClient() patch("google.cloud.storage.Client", self.gcs).start() self.settings = { "storage.bucket": "mybucket", "storage.gcp_service_account_json_filename": "my-filename.json", } self.bucket = self.gcs.bucket("mybucket") self.bucket._created = True patch.object(GoogleCloudStorage, "test", True).start() kwargs = GoogleCloudStorage.configure(self.settings) self.storage = GoogleCloudStorage(MagicMock(), **kwargs)
def test_object_acl(self): """ Can specify an object ACL for GCS objects. Just test to make sure that the configured ACL is forwarded to the API client """ settings = dict(self.settings) settings["storage.object_acl"] = "authenticated-read" kwargs = GoogleCloudStorage.configure(settings) storage = GoogleCloudStorage(MagicMock(), **kwargs) package = make_package() storage.upload(package, BytesIO()) blob = self.bucket.list_blobs()[0] self.assertEqual(blob._acl, "authenticated-read")
def setUp(self): super(TestGoogleCloudStorage, self).setUp() self.gcs = MockGCSClient() self._config_file = tempfile.mktemp() with open(self._config_file, "w") as ofile: json.dump({}, ofile) patch("google.cloud.storage.Client", self.gcs).start() self.settings = { "storage.bucket": "mybucket", "storage.gcp_service_account_json_filename": self._config_file, } self.bucket = self.gcs.bucket("mybucket") self.bucket._created = True patch.object(GoogleCloudStorage, "test", True).start() kwargs = GoogleCloudStorage.configure(self.settings) self.storage = GoogleCloudStorage(MagicMock(), **kwargs)