Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making datastore system test use env. at runtime rather than import time. #1401

Merged
merged 1 commit into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions scripts/datastore_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

from gcloud.environment_vars import GCD_DATASET
from gcloud.environment_vars import GCD_HOST
from system_tests.run_system_test import run_module_tests


_START_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'start')
_ENV_INIT_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'env-init')
_HOST_VAR_NAME = 'DATASTORE_HOST'
_DATASET_PREFIX = 'export ' + GCD_DATASET + '='
_HOST_LINE_PREFIX = 'export ' + GCD_HOST + '='

Expand All @@ -50,8 +50,6 @@ def main():
os.environ[GCD_DATASET] = dataset
os.environ[GCD_HOST] = host
os.environ['GCLOUD_NO_PRINT'] = 'true'
# Delay import until after environment variables are set.
from system_tests.run_system_test import run_module_tests
run_module_tests('datastore',
ignore_requirements=True)
finally:
Expand Down
22 changes: 10 additions & 12 deletions system_tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
from system_tests.system_test_utils import EmulatorCreds


# Isolated namespace so concurrent test runs don't collide.
TEST_NAMESPACE = 'ns%d' % (1000 * time.time(),)
EMULATOR_DATASET = os.getenv(GCD_DATASET)


class Config(object):
"""Run-time configuration to be modified at set-up.

Expand All @@ -56,14 +51,17 @@ def clone_client(client):


def setUpModule():
if EMULATOR_DATASET is None:
emulator_dataset = os.getenv(GCD_DATASET)
# Isolated namespace so concurrent test runs don't collide.
test_namespace = 'ns%d' % (1000 * time.time(),)
if emulator_dataset is None:
client_mod.DATASET = TESTS_DATASET
Config.CLIENT = datastore.Client(namespace=TEST_NAMESPACE)
Config.CLIENT = datastore.Client(namespace=test_namespace)
else:
credentials = EmulatorCreds()
http = httplib2.Http() # Un-authorized.
Config.CLIENT = datastore.Client(project=EMULATOR_DATASET,
namespace=TEST_NAMESPACE,
Config.CLIENT = datastore.Client(project=emulator_dataset,
namespace=test_namespace,
credentials=credentials,
http=http)

Expand Down Expand Up @@ -209,11 +207,11 @@ def setUpClass(cls):
cls.CLIENT = clone_client(Config.CLIENT)
# Remove the namespace from the cloned client, since these
# query tests rely on the entities to be already stored and indexed,
# hence ``TEST_NAMESPACE`` set at runtime can't be used.
# hence ``test_namespace`` set at runtime can't be used.
cls.CLIENT.namespace = None

# In the emulator, re-populating the datastore is cheap.
if EMULATOR_DATASET is not None:
if os.getenv(GCD_DATASET) is not None:
# Populate the datastore with the cloned client.
populate_datastore.add_characters(client=cls.CLIENT)

Expand All @@ -224,7 +222,7 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
# In the emulator, destroy the query entities.
if EMULATOR_DATASET is not None:
if os.getenv(GCD_DATASET) is not None:
# Use the client for this test instead of the global.
clear_datastore.remove_all_entities(client=cls.CLIENT)

Expand Down