Skip to content
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

Add App Engine system tests #59

Merged
merged 3 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 32 additions & 13 deletions system_tests/app_engine/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""App Engine standard application that runs basic system tests for
google.auth.app_engine.

This application has to run tests manually instead of using py.test because
py.test currently doesn't work on App Engine standard.
"""

import contextlib
import json
import sys
Expand Down Expand Up @@ -43,7 +50,7 @@ def test_credentials():

# Get token info and verify scope
url = _helpers.update_query(TOKEN_INFO_URL, {
'access_token': scoped_credentials.token
'access_token': scoped_credentials.token,
})
response = HTTP_REQUEST(url=url, method='GET')
token_info = json.loads(response.data.decode('utf-8'))
Expand All @@ -70,26 +77,38 @@ def capture():
sys.stdout, sys.stderr = oldout, olderr


def run_test_func(func):
with capture() as capsys:
try:
func()
return True, ''
except Exception as exc:
output = (
'Test {} failed: {}\n\n'
'Stacktrace:\n{}\n\n'
'Captured output:\n{}').format(

This comment was marked as spam.

This comment was marked as spam.

func.func_name, exc, traceback.format_exc(),
capsys.getvalue())
return False, output


def run_tests():
"""Runs all tests.

Returns:
Tuple[bool, str]: A tuple containing True if all tests pass, False
otherwise, and any captured output from the tests.
"""
status = False
status = True
output = ''

with capture() as capsys:
try:
test_credentials()
test_default()
status = True
except Exception:
status = False
output = 'Stacktrace:\n{}\n'.format(traceback.format_exc())

output += 'Captured output:\n{}'.format(capsys.getvalue())
tests = (test_credentials, test_default)

for test in tests:

This comment was marked as spam.

This comment was marked as spam.

test_status, test_output = run_test_func(test)
status = status and test_status
output += test_output

return status, output


Expand All @@ -106,5 +125,5 @@ def get(self):


app = webapp2.WSGIApplication([
('/', MainHandler)
('/', MainHandler),
], debug=True)
6 changes: 3 additions & 3 deletions system_tests/app_engine/test_app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from google.auth import _cloud_sdk
import pytest


SKIP_TEST_ENV = 'SKIP_APP_ENGINE_SYSTEM_TEST'
HERE = os.path.dirname(__file__)
TEST_APP_DIR = os.path.join(HERE, 'app')
TEST_APP_SERVICE = 'google-auth-system-tests'
Expand All @@ -27,7 +27,7 @@
def vendor_app_dependencies():
"""Vendors in the test application's third-party dependencies."""
subprocess.check_call(
['pip', 'install', '-t', 'lib', '-r', 'requirements.txt'])
['pip', 'install', '--target', 'lib', '-r', 'requirements.txt'])


def deploy_app():
Expand All @@ -51,7 +51,7 @@ def app(monkeypatch):


@pytest.mark.skipif(
'SKIP_APP_ENGINE_SYSTEM_TEST' in os.environ,
SKIP_TEST_ENV in os.environ,
reason='Explicitly skipping App Engine system tests.')
def test_live_application(app, http_request):
response = http_request(method='GET', url=app)
Expand Down