8000 test: Use named db in system tests · googleapis/python-datastore@29555fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 29555fe

Browse files
committed
test: Use named db in system tests
1 parent 9f2893f commit 29555fe

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

CONTRIBUTING.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ Running System Tests
174174

175175
- You'll also need stored data in your dataset. To populate this data, run::
176176

177+
$ export SYSTEM_TESTS_DATABASE=test-db
177178
$ python tests/system/utils/populate_datastore.py
178179

179180
- If you make a mistake during development (i.e. a failing test that

noxfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def install_systemtest_dependencies(session, *constraints):
230230

231231
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
232232
@nox.parametrize("disable_grpc", [False, True])
233-
def system(session, disable_grpc):
233+
@nox.parametrize("use_named_db", [False, True])
234+
def system(session, disable_grpc, use_named_db):
234235
"""Run the system test suite."""
235236
constraints_path = str(
236237
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
@@ -256,6 +257,7 @@ def system(session, disable_grpc):
256257
env = {}
257258
if disable_grpc:
258259
env["GOOGLE_CLOUD_DISABLE_GRPC"] = "True"
260+
env["SYSTEM_TESTS_DATABASE"] = "test-db" if use_named_db else ""
259261

260262
# Run py.test against the system tests.
261263
if system_test_exists:

owlbot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def system\(session\):
120120
"""\
121121
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
122122
@nox.parametrize("disable_grpc", [False, True])
123-
def system(session, disable_grpc):
123+
@nox.parametrize("use_named_db", [False, True])
124+
def system(session, disable_grpc, use_named_db):
124125
""",
125126
)
126127

@@ -133,6 +134,7 @@ def system(session, disable_grpc):
133134
env = {}
134135
if disable_grpc:
135136
env["GOOGLE_CLOUD_DISABLE_GRPC"] = "True"
137+
env["SYSTEM_TESTS_DATABASE"] = "system-tests-named-db" if use_named_db else ""
136138
137139
# Run py.test against the system tests.
138140
""",

tests/system/_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from google.cloud.datastore.client import DATASTORE_DATASET
1919
from test_utils.system import unique_resource_id
2020

21+
_DATASTORE_DATABASE = "SYSTEM_TESTS_DATABASE"
2122
EMULATOR_DATASET = os.getenv(DATASTORE_DATASET)
23+
EMULATOR_DATABASE = 10000 os.getenv(_DATASTORE_DATABASE)
2224

2325

2426
def unique_id(prefix, separator="-"):

tests/system/utils/clear_datastore.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ def remove_all_entities(client):
8585
client.delete_multi(keys)
8686

8787

88-
def main():
89-
client = datastore.Client()
88+
def run(database):
89+
client = datastore.Client(database=database)
9090
kinds = sys.argv[1:]
9191

9292
if len(kinds) == 0:
9393
kinds = ALL_KINDS
9494

95-
print_func("This command will remove all entities for " "the following kinds:")
95+
print_func(
96+
"This command will remove all entities from the database"
97+
+ database
98+
+ " for the following kinds:"
99+
)
96100
print_func("\n".join("- " + val for val in kinds))
97101
response = input("Is this OK [y/n]? ")
98102

@@ -105,5 +109,10 @@ def main():
105109
print_func("Doing nothing.")
106110

107111

112+
def main():
113+
for database in ["", "test-db"]:
114+
run(database)
115+
116+
108117
if __name__ == "__main__":
109118
main()

tests/system/utils/populate_datastore.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def add_timestamp_keys(client=None):
175175
batch.put(entity)
176176

177177

178-
def main():
179-
client = datastore.Client()
178+
def run(database):
179+
client = datastore.Client(database=database)
180180
flags = sys.argv[1:]
181181

182182
if len(flags) == 0:
@@ -192,5 +192,10 @@ def main():
192192
add_timestamp_keys(client)
193193

194194

195+
def main():
196+
for database in ["", "test-db"]:
197+
run(database)
198+
199+
195200
if __name__ == "__main__":
196201
main()

0 commit comments

Comments
 (0)
0