Skip to content
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
3 changes: 2 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
19 changes: 18 additions & 1 deletion system_tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import time

import httplib2
import unittest2

from gcloud._helpers import UTC
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down
16 changes: 11 additions & 5 deletions system_tests/run_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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__':
Expand Down