コード例 #1
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
 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)
コード例 #2
0
ファイル: test_storage.py プロジェクト: wycttb/pypicloud
 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)
コード例 #3
0
ファイル: test_storage.py プロジェクト: 418sec/pypicloud
 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)
コード例 #4
0
ファイル: test_storage.py プロジェクト: 418sec/pypicloud
    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")
コード例 #5
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
    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")
コード例 #6
0
ファイル: test_storage.py プロジェクト: wycttb/pypicloud
    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()
コード例 #7
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
    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()
コード例 #8
0
ファイル: test_storage.py プロジェクト: 418sec/pypicloud
    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")
コード例 #9
0
ファイル: test_storage.py プロジェクト: 418sec/pypicloud
    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()
コード例 #10
0
ファイル: test_storage.py プロジェクト: wycttb/pypicloud
 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)
コード例 #11
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
    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")
コード例 #12
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
 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)
コード例 #13
0
ファイル: test_storage.py プロジェクト: 418sec/pypicloud
 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)