-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Switching app engine tests to webtest and consolidating testing utils… #83
Merged
+63
−100
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,34 +16,20 @@ | |
import re | ||
|
||
from apiclient.http import HttpMock | ||
|
||
from appengine.bigquery import main | ||
|
||
import mock | ||
|
||
import tests | ||
|
||
import webapp2 | ||
import webtest | ||
|
||
|
||
class TestAuthSample(tests.DatastoreTestbedCase, tests.CloudBaseTest): | ||
class TestAuthSample(tests.AppEngineTestbedCase): | ||
|
||
def setUp(self): | ||
tests.DatastoreTestbedCase.setUp(self) | ||
tests.CloudBaseTest.setUp(self) | ||
|
||
self.testbed.init_user_stub() | ||
|
||
def loginUser(self, email='[email protected]', id='123', is_admin=False): | ||
self.testbed.setup_env( | ||
user_email=email, | ||
user_id=id, | ||
user_is_admin='1' if is_admin else '0', | ||
overwrite=True) | ||
super(TestAuthSample, self).setUp() | ||
self.app = webtest.TestApp(main.app) | ||
|
||
def test_anonymous_get(self): | ||
request = webapp2.Request.blank('/') | ||
response = request.get_response(main.app) | ||
response = self.app.get('/') | ||
|
||
# Should redirect to login | ||
self.assertEqual(response.status_int, 302) | ||
|
@@ -53,8 +39,7 @@ def test_anonymous_get(self): | |
def test_loggedin_get(self): | ||
self.loginUser() | ||
|
||
request = webapp2.Request.blank('/') | ||
response = request.get_response(main.app) | ||
response = self.app.get('/') | ||
|
||
# Should redirect to login | ||
self.assertEqual(response.status_int, 302) | ||
|
@@ -64,16 +49,15 @@ def test_loggedin_get(self): | |
def test_oauthed_get(self, *args): | ||
self.loginUser() | ||
|
||
request = webapp2.Request.blank('/') | ||
|
||
mock_http = HttpMock( | ||
os.path.join(self.resource_path, 'datasets-list.json'), | ||
{'status': '200'}) | ||
|
||
with mock.patch.object(main.decorator, 'http', return_value=mock_http): | ||
original_projectid = main.PROJECTID | ||
try: | ||
main.PROJECTID = self.constants['projectId'] | ||
response = request.get_response(main.app) | ||
response = self.app.get('/') | ||
finally: | ||
main.PROJECTID = original_projectid | ||
|
||
|
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
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
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 |
---|---|---|
|
@@ -96,13 +96,15 @@ def tearDown(self): | |
os.environ['SERVER_SOFTWARE'] = self._server_software_org | ||
|
||
|
||
class DatastoreTestbedCase(unittest.TestCase): | ||
class AppEngineTestbedCase(CloudBaseTest): | ||
"""A base test case for common setup/teardown tasks for test.""" | ||
def setUp(self): | ||
super(AppEngineTestbedCase, self).setUp() | ||
|
||
if not APPENGINE_AVAILABLE: | ||
raise SkipTest() | ||
|
||
"""Setup the datastore and memcache stub.""" | ||
# Setup the datastore and memcache stub. | ||
# First, create an instance of the Testbed class. | ||
self.testbed = testbed.Testbed() | ||
# Then activate the testbed, which prepares the service stubs for | ||
|
@@ -118,9 +120,21 @@ def setUp(self): | |
consistency_policy=self.policy) | ||
self.testbed.init_memcache_stub() | ||
|
||
# Setup remaining stubs. | ||
self.testbed.init_user_stub() | ||
self.testbed.init_taskqueue_stub() | ||
|
||
def tearDown(self): | ||
super(AppEngineTestbedCase, self).tearDown() | ||
self.testbed.deactivate() | ||
|
||
def loginUser(self, email='[email protected]', id='123', is_admin=False): | ||
self.testbed.setup_env( | ||
user_email=email, | ||
user_id=id, | ||
user_is_admin='1' if is_admin else '0', | ||
overwrite=True) | ||
|
||
|
||
@contextlib.contextmanager | ||
def capture_stdout(): | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ deps = | |
mock | ||
nose | ||
coverage | ||
webtest | ||
nose-exclude | ||
coverargs = | ||
--with-coverage | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to do with your commit, but we might want to use named constants for HTTP codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not feel strongly about this, but if you do, feel free to file a bug and we'll follow up with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, /issues/85