forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving common testing tools to gcp-repo-tools.
* Updating travis.yml for new GAE tool. * Updating tox.ini to use new tools. * Updating imports in various tests to use new tools. * Updating root conftest.py to provide configuration. * Updating secrets.tar with client-secrets, needed for incoming bigquery tests.
- Loading branch information
Jon Wayne Parrott
committed
Feb 23, 2016
1 parent
b0947ad
commit 7e92231
Showing
32 changed files
with
139 additions
and
418 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
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 |
---|---|---|
@@ -1,35 +1,27 @@ | ||
import pytest | ||
import testing.appengine | ||
|
||
|
||
def pytest_configure(config): | ||
testing.appengine.setup_sdk_imports() | ||
|
||
|
||
def pytest_runtest_call(item): | ||
testing.appengine.import_appengine_config() | ||
|
||
|
||
@pytest.yield_fixture | ||
def testbed(): | ||
testbed = testing.appengine.setup_testbed() | ||
yield testbed | ||
testbed.deactivate() | ||
|
||
|
||
@pytest.fixture | ||
def login(testbed): | ||
def _login(email='[email protected]', id='123', is_admin=False): | ||
testbed.setup_env( | ||
user_email=email, | ||
user_id=id, | ||
user_is_admin='1' if is_admin else '0', | ||
overwrite=True) | ||
return _login | ||
|
||
|
||
@pytest.fixture | ||
def run_tasks(testbed): | ||
def _run_tasks(app): | ||
testing.appengine.run_tasks(testbed, app) | ||
return _run_tasks | ||
# Copyright 2015 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. | ||
|
||
# Import py.test hooks and fixtures for App Engine | ||
from gcp.testing.appengine import ( | ||
login, | ||
pytest_configure, | ||
pytest_runtest_call, | ||
run_tasks, | ||
testbed) | ||
|
||
(login) | ||
(pytest_configure) | ||
(pytest_runtest_call) | ||
(run_tasks) | ||
(testbed) |
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,12 +12,19 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from googleapiclient.http import HttpMockSequence | ||
import httplib2 | ||
import main | ||
import mock | ||
import pytest | ||
from testing import Http2Mock | ||
import webtest | ||
|
||
|
||
class HttpMockSequenceWithCredentials(HttpMockSequence): | ||
def add_credentials(self, *args): | ||
pass | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
return webtest.TestApp(main.app) | ||
|
@@ -29,27 +36,31 @@ def test_get(app): | |
|
||
|
||
def test_post(app): | ||
http = Http2Mock(responses=[{}]) | ||
http = HttpMockSequenceWithCredentials([ | ||
({'status': '200'}, '')]) | ||
patch_http = mock.patch.object(httplib2, 'Http', lambda: http) | ||
|
||
with http: | ||
with patch_http: | ||
response = app.post('/', { | ||
'recipient': '[email protected]', | ||
'submit': 'Send simple email'}) | ||
|
||
assert response.status_int == 200 | ||
|
||
http = Http2Mock(responses=[{}]) | ||
http = HttpMockSequenceWithCredentials([ | ||
({'status': '200'}, '')]) | ||
|
||
with http: | ||
with patch_http: | ||
response = app.post('/', { | ||
'recipient': '[email protected]', | ||
'submit': 'Send complex email'}) | ||
|
||
assert response.status_int == 200 | ||
|
||
http = Http2Mock(responses=[{'status': 500, 'body': 'Test error'}]) | ||
http = HttpMockSequenceWithCredentials([ | ||
({'status': '500'}, 'Test error')]) | ||
|
||
with http, pytest.raises(Exception): | ||
with patch_http, pytest.raises(Exception): | ||
app.post('/', { | ||
'recipient': '[email protected]', | ||
'submit': 'Send simple email'}) |
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
Oops, something went wrong.