Skip to content

Commit

Permalink
Move in adminconsole quickstart samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerjou Cheng committed Jul 8, 2015
1 parent 4368528 commit 7c5d5f8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
Empty file.
Empty file.
53 changes: 53 additions & 0 deletions appengine/adminconsole/samples/quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2013 Google Inc. All Rights Reserved.

"""Demo client for the Google App Engine Administration API.
This sample client demonstrates how to use the API and manipulate
apps deployed on Google App Engine.
"""

__author__ = 'sarmad@google.com (Sarmad Gilani)'

from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build


def main():
# Authenticate and construct service.
service = build('appengine', 'v1beta2',
credentials=GoogleCredentials.get_application_default())

# Get a list of your applications.
response = service.apps().list().execute()
apps_list = response.get('apps', [])

for app in apps_list:
print 'App Title: ', app['title']
print 'App ID: ', app['appId']

# List all modules on the application.
response = service.apps().modules().list(
appId=app['appId']).execute()
modules_list = response.get('modules', [])

print ' Modules for this app:'
for module in modules_list:
print ' Module ID: ', module['moduleId']

# List all versions on this module.
response = service.apps().modules().versions().list(
appId=app['appId'],
moduleId=module['moduleId']).execute()
versions_list = response.get('versions', [])

print ' Versions on this module: '
for version in versions_list:
print ' Version ID: ', version['versionId']
print ' Runtime: ', version['runtime']
print ' Deployment Timestamp: ', version['deployedTimestamp']
if version['isDefault']:
print ' ** This is the default version. **'


if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions appengine/adminconsole/tests/test_quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2015, Google, Inc.
# 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.
#
"""Tests for appengine admin console api quickstart."""

import re
import sys
import unittest

from appengine.adminconsole.samples import quickstart
from tests import CloudBaseTest


class TestQuickstart(unittest.TestCase):

@classmethod
def setUpClass(cls):
if not hasattr(sys.stdout, 'getvalue'):
cls.skipTest('Test must be in buffered mode to run.')

def test_main(self):
quickstart.main()
output = sys.stdout.getvalue().strip()
self.assertRegexpMatches(
output, re.compile(r'App Title:\s*\w.*App ID:\s*\w', re.S))


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ deps =
mock
nose
nosegae
commands =
commands =
nosetests --with-gae {posargs}

[testenv:pep8]
deps =
deps =
flake8
flake8-import-order
commands =
flake8 --max-complexity=10 --import-order-style=google {posargs}

[testenv:cover]
deps =
deps =
{[testenv:py27]deps}
coverage
coveralls
Expand Down

0 comments on commit 7c5d5f8

Please sign in to comment.