-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding _DEFAULTS stubs in all tests that use it.
Introduces - concept of `implicit` for `_DefaultsContainer`. - testing module for datastore for patching Verified all test cases that would accidentally rely on _DEFAULTS implicit behavior by using a custom `_DefaultsContainer` that raises when the instance is implicit. Main delta for the custom properties: diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py index 3afc954..1d38562 100644 --- a/gcloud/datastore/_implicit_environ.py +++ b/gcloud/datastore/_implicit_environ.py @@ -38,9 +38,37 @@ class _DefaultsContainer(object): :param dataset_id: Persistent implied dataset ID from environment. """ - def __init__(self, connection=None, dataset_id=None): - self.connection = connection - self.dataset_id = dataset_id + class FooError(Exception): + pass + + @Property + def dataset_id(self): + if self.implicit: + raise self.FooError + return self._dataset_id + + @dataset_id.setter + def dataset_id(self, value): + if self.implicit: + raise self.FooError + self._dataset_id = value + + @Property + def connection(self): + if self.implicit: + raise self.FooError + return self._connection + + @connection.setter + def connection(self, value): + if self.implicit: + raise self.FooError + self._connection = value + + def __init__(self, connection=None, dataset_id=None, implicit=False): + self.implicit = implicit + self._connection = connection + self._dataset_id = dataset_id def app_engine_id():
- Loading branch information
Showing
11 changed files
with
158 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2014 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Shared datastore testing utilities.""" | ||
|
||
from gcloud._testing import _Monkey | ||
from gcloud.datastore import _implicit_environ | ||
from gcloud.datastore._implicit_environ import _DefaultsContainer | ||
|
||
|
||
def _monkey_defaults(*args, **kwargs): | ||
mock_defaults = _DefaultsContainer(*args, **kwargs) | ||
return _Monkey(_implicit_environ, _DEFAULTS=mock_defaults) | ||
|
||
|
||
def _setup_defaults(test_case): | ||
test_case._replaced_defaults = _implicit_environ._DEFAULTS | ||
_implicit_environ._DEFAULTS = _DefaultsContainer() | ||
|
||
|
||
def _tear_down_defaults(test_case): | ||
_implicit_environ._DEFAULTS = test_case._replaced_defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.