-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from GoogleCloudPlatform/webtestify
Switching app engine tests to webtest and consolidating testing utils…
- Loading branch information
Showing
14 changed files
with
63 additions
and
100 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
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 | ||
|