diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index be5c50583a64..9cf55e562724 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -233,7 +233,8 @@ Running System Tests $ DATASTORE_HOST=http://localhost:8471 \ > DATASTORE_DATASET=gcloud-settings-app-id \ > GCLOUD_NO_PRINT=true \ - > python system_tests/run_system_test.py --package=datastore + > python system_tests/run_system_test.py \ + > --package=datastore --ignore-requirements and after completion stop the emulator:: diff --git a/system_tests/datastore.py b/system_tests/datastore.py index a099e600beb2..dbd20dcc87a9 100644 --- a/system_tests/datastore.py +++ b/system_tests/datastore.py @@ -16,6 +16,7 @@ import os import time +import httplib2 import unittest2 from gcloud._helpers import UTC @@ -44,6 +45,18 @@ class Config(object): CLIENT = None +class _EmulatorCreds(object): + """A mock credential object. + + Used to avoid unnecessary token refreshing or reliance on the network + while an emulator is running. + """ + + @staticmethod + def create_scoped_required(): + return False + + def clone_client(client): # Fool the Client constructor to avoid creating a new connection. cloned_client = datastore.Client(project=client.project, @@ -58,8 +71,12 @@ def setUpModule(): client_mod.DATASET = TESTS_DATASET 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) + namespace=TEST_NAMESPACE, + credentials=credentials, + http=http) class TestDatastore(unittest2.TestCase): diff --git a/system_tests/run_system_test.py b/system_tests/run_system_test.py index ea2373c1400d..171a0d1c85f2 100644 --- a/system_tests/run_system_test.py +++ b/system_tests/run_system_test.py @@ -45,13 +45,18 @@ def get_parser(): parser.add_argument('--package', dest='package', choices=REQUIREMENTS.keys(), default='datastore', help='Package to be tested.') + parser.add_argument( + '--ignore-requirements', + dest='ignore_requirements', action='store_true', + help='Ignore the credentials requirement for the test.') return parser -def run_module_tests(module_name): - # Make sure environ is set before running test. - requirements = REQUIREMENTS[module_name] - system_test_utils.check_environ(*requirements) +def run_module_tests(module_name, ignore_requirements=False): + if not ignore_requirements: + # Make sure environ is set before running test. + requirements = REQUIREMENTS[module_name] + system_test_utils.check_environ(*requirements) suite = unittest2.TestSuite() test_mod = TEST_MODULES[module_name] @@ -68,7 +73,8 @@ def run_module_tests(module_name): def main(): parser = get_parser() args = parser.parse_args() - run_module_tests(args.package) + run_module_tests(args.package, + ignore_requirements=args.ignore_requirements) if __name__ == '__main__':