Skip to content

Commit 675e11d

Browse files
author
IlyaFaer
committed
Copy tests from bucket test to client.
1 parent 2cd2321 commit 675e11d

2 files changed

Lines changed: 119 additions & 21 deletions

File tree

storage/noxfile.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def lint(session):
4040
session.run("flake8", "google", "tests")
4141

4242

43-
@nox.session(python="3.6")
43+
@nox.session(python="3.7")
4444
def blacken(session):
4545
"""Run black.
4646
@@ -97,31 +97,31 @@ def unit(session):
9797
default(session)
9898

9999

100-
@nox.session(python=["2.7", "3.6"])
101-
def system(session):
102-
"""Run the system test suite."""
100+
# @nox.session(python=["2.7", "3.6"])
101+
# def system(session):
102+
# """Run the system test suite."""
103103

104-
# Sanity check: Only run system tests if the environment variable is set.
105-
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
106-
session.skip("Credentials must be set via environment variable.")
104+
# # Sanity check: Only run system tests if the environment variable is set.
105+
# if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
106+
# session.skip("Credentials must be set via environment variable.")
107107

108-
# Use pre-release gRPC for system tests.
109-
session.install("--pre", "grpcio")
108+
# # Use pre-release gRPC for system tests.
109+
# session.install("--pre", "grpcio")
110110

111-
# Install all test dependencies, then install local packages in-place.
112-
session.install("mock", "pytest")
113-
for local_dep in LOCAL_DEPS:
114-
session.install("-e", local_dep)
115-
systest_deps = ["../test_utils/", "../pubsub", "../kms"]
116-
for systest_dep in systest_deps:
117-
session.install("-e", systest_dep)
118-
session.install("-e", ".")
111+
# # Install all test dependencies, then install local packages in-place.
112+
# session.install("mock", "pytest")
113+
# for local_dep in LOCAL_DEPS:
114+
# session.install("-e", local_dep)
115+
# systest_deps = ["../test_utils/", "../pubsub", "../kms"]
116+
# for systest_dep in systest_deps:
117+
# session.install("-e", systest_dep)
118+
# session.install("-e", ".")
119119

120-
# Run py.test against the system tests.
121-
session.run("py.test", "--quiet", "tests/system.py", *session.posargs)
120+
# # Run py.test against the system tests.
121+
# session.run("py.test", "--quiet", "tests/system.py", *session.posargs)
122122

123123

124-
@nox.session(python="3.6")
124+
@nox.session(python="3.7")
125125
def cover(session):
126126
"""Run the final coverage report.
127127

storage/tests/unit/test_client.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ def test_create_bucket_with_string_conflict(self):
543543
client._http_internal = http
544544

545545
with self.assertRaises(Conflict):
546-
client.create_bucket(bucket_name, project=other_project, user_project=user_project)
546+
client.create_bucket(
547+
bucket_name, project=other_project, user_project=user_project
548+
)
547549

548550
http.request.assert_called_once_with(
549551
method="POST", url=URI, data=mock.ANY, headers=mock.ANY
@@ -586,6 +588,102 @@ def test_create_bucket_with_object_conflict(self):
586588
json_sent = http.request.call_args_list[0][1]["data"]
587589
self.assertEqual(json_expected, json.loads(json_sent))
588590

591+
def test_create_w_missing_client_project(self):
592+
client = self._make_one(project=None)
593+
594+
with self.assertRaises(ValueError):
595+
client.create_bucket("bucket")
596+
597+
def test_create_w_predefined_acl_invalid(self):
598+
PROJECT = "PROJECT"
599+
BUCKET_NAME = "bucket-name"
600+
credentials = _make_credentials()
601+
client = self._make_one(project=PROJECT, credentials=credentials)
602+
603+
with self.assertRaises(ValueError):
604+
client.create_bucket(BUCKET_NAME, predefined_acl="bogus")
605+
606+
def test_create_w_predefined_acl_valid(self):
607+
from google.cloud.storage.client import Client
608+
609+
PROJECT = "PROJECT"
610+
BUCKET_NAME = "bucket-name"
611+
DATA = {"name": BUCKET_NAME}
612+
613+
client = Client(project=PROJECT)
614+
connection = _make_connection(DATA)
615+
client._base_connection = connection
616+
bucket = client.create_bucket(BUCKET_NAME, predefined_acl="publicRead")
617+
618+
connection.api_request.assert_called_once_with(
619+
method="POST",
620+
path="/b",
621+
query_params={"project": PROJECT, "predefinedAcl": "publicRead"},
622+
data=DATA,
623+
_target_object=bucket,
624+
)
625+
626+
def test_create_w_predefined_default_object_acl_invalid(self):
627+
PROJECT = "PROJECT"
628+
BUCKET_NAME = "bucket-name"
629+
630+
credentials = _make_credentials()
631+
client = self._make_one(project=PROJECT, credentials=credentials)
632+
633+
with self.assertRaises(ValueError):
634+
client.create_bucket(BUCKET_NAME, predefined_default_object_acl="bogus")
635+
636+
def test_create_w_predefined_default_object_acl_valid(self):
637+
from google.cloud.storage.client import Client
638+
639+
PROJECT = "PROJECT"
640+
BUCKET_NAME = "bucket-name"
641+
DATA = {"name": BUCKET_NAME}
642+
643+
client = Client(project=PROJECT)
644+
connection = _make_connection(DATA)
645+
client._base_connection = connection
646+
bucket = client.create_bucket(
647+
BUCKET_NAME, predefined_default_object_acl="publicRead"
648+
)
649+
650+
connection.api_request.assert_called_once_with(
651+
method="POST",
652+
path="/b",
653+
query_params={
654+
"project": PROJECT,
655+
"predefinedDefaultObjectAcl": "publicRead",
656+
},
657+
data=DATA,
658+
_target_object=bucket,
659+
)
660+
661+
def test_create_w_explicit_location(self):
662+
from google.cloud.storage.client import Client
663+
664+
PROJECT = "PROJECT"
665+
BUCKET_NAME = "bucket-name"
666+
LOCATION = "us-central1"
667+
DATA = {"location": LOCATION, "name": BUCKET_NAME}
668+
669+
connection = _make_connection(
670+
DATA, "{'location': 'us-central1', 'name': 'bucket-name'}"
671+
)
672+
673+
client = Client(project=PROJECT)
674+
client._base_connection = connection
675+
676+
bucket = client.create_bucket(BUCKET_NAME, location=LOCATION)
677+
678+
connection.api_request.assert_called_once_with(
679+
method="POST",
680+
path="/b",
681+
data=DATA,
682+
_target_object=bucket,
683+
query_params={"project": "PROJECT"},
684+
)
685+
self.assertEqual(bucket.location, LOCATION)
686+
589687
def test_create_bucket_with_string_success(self):
590688
from google.cloud.storage.bucket import Bucket
591689

0 commit comments

Comments
 (0)