| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 90f71c2 commit a1ad83b
108 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ include = | |||
| 8 | 8 | monitoring/* | |
| 9 | 9 | storage/* | |
| 10 | 10 | cloud_logging/* | |
| 11 | + managed_vms/* | ||
| 11 | 12 | [report] | |
| 12 | 13 | exclude_lines = | |
| 13 | 14 | pragma: NO COVER | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,14 @@ coverage-gae.json | |||
| 5 | 5 | .tox | |
| 6 | 6 | coverage.xml | |
| 7 | 7 | nosetests.xml | |
| 8 | + nosetests-*.xml | ||
| 8 | 9 | python-docs-samples.json | |
| 10 | + service-account.json | ||
| 9 | 11 | __pycache__ | |
| 10 | 12 | *db\.sqlite3 | |
| 11 | 13 | managed_vms/django_tutorial/static/* | |
| 12 | 14 | **/migrations/* | |
| 15 | + lib | ||
| 16 | + testing/resources/test-env.sh | ||
| 17 | + testing/resources/service-account.json | ||
| 18 | + secrets.tar | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,35 +1,27 @@ | |||
| 1 | 1 | sudo: false | |
| 2 | - #add language, etc. here | ||
| 3 | 2 | language: python | |
| 4 | - | ||
| 3 | + services: | ||
| 4 | + - memcached | ||
| 5 | + - mysql | ||
| 5 | 6 | branches: | |
| 6 | 7 | only: | |
| 7 | - - master | ||
| 8 | - | ||
| 8 | + - master | ||
| 9 | 9 | cache: | |
| 10 | 10 | directories: | |
| 11 | 11 | - $HOME/.cache | |
| 12 | - | ||
| 13 | 12 | env: | |
| 14 | 13 | global: | |
| 15 | 14 | - PATH=${PATH}:${HOME}/gcloud/google-cloud-sdk/bin | |
| 16 | - - GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/python-docs-samples.json | ||
| 15 | + - GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/testing/resources/service-account.json | ||
| 17 | 16 | - GAE_PYTHONPATH=${HOME}/.cache/google_appengine | |
| 18 | - - TEST_BUCKET_NAME=bigquery-devrel-samples-bucket | ||
| 19 | - - TEST_PROJECT_ID=bigquery-devrel-samples | ||
| 20 | - | ||
| 17 | + - secure: YIowCOMJ97rTcehKVT6Gi3u0Etm8s9+TBRGsNPJLgSF2zZdsh9IHcIc+tMDUMR3lpOe8y2a060RuODQcRsW1W1LIHej+ZE/gv6vATT6qNA3eKfKmZ9AyrpBO0fTOHlHrGBuU9ktBPR+iqvnq8MLWjnUozPFMJbuNBFITU7JP8jc= | ||
| 21 | 18 | before_install: | |
| 22 | - - tests/scripts/travis-before-install.sh | ||
| 23 | - | ||
| 19 | + - openssl aes-256-cbc -k "$secrets_password" -in secrets.tar.enc -out secrets.tar -d | ||
| 20 | + - tar xvf secrets.tar | ||
| 24 | 21 | install: | |
| 25 | - # TODO: unpin tox when the following issue is fixed | ||
| 26 | - # https://bitbucket.org/hpk42/tox/issues/285/tox-220-breaks-some-toxini-config-files | ||
| 27 | 22 | - pip install tox | |
| 28 | - | ||
| 23 | + - pip install -e git+https://github.com/GoogleCloudPlatform/python-repo-tools#egg=python-repo-tools | ||
| 24 | + - gcp-python-repo-tools download-appengine-sdk `dirname "${GAE_PYTHONPATH}"` | ||
| 29 | 25 | script: | |
| 26 | + - source ${TRAVIS_BUILD_DIR}/testing/resources/test-env.sh | ||
| 30 | 27 | - tox | |
| 31 | - | ||
| 32 | - # Coveralls is disabled in travis because travis does not run all of our | ||
| 33 | - # tests. The full suite of tests is run on an internal Jenkins instance. | ||
| 34 | - # after_success: | ||
| 35 | - # - coveralls | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,102 +36,4 @@ be able to accept your pull requests. | |||
| 36 | 36 | ||
| 37 | 37 | ## Testing | |
| 38 | 38 | ||
| 39 | - The tests in this repository run against live services, therefore, it | ||
| 40 | - takes a bit of configuration to run all of the tests locally. | ||
| 41 | - | ||
| 42 | - ### Local setup | ||
| 43 | - | ||
| 44 | - Before you can run tests locally you must have: | ||
| 45 | - | ||
| 46 | - * The latest [tox](https://tox.readthedocs.org/en/latest/) and | ||
| 47 | - [pip](https://pypi.python.org/pypi/pip) installed. | ||
| 48 | - | ||
| 49 | - $ sudo pip install --upgrade tox pip | ||
| 50 | - | ||
| 51 | - * The [Google Cloud SDK](https://cloud.google.com/sdk/) installed. You | ||
| 52 | - can do so with the following command: | ||
| 53 | - | ||
| 54 | - $ curl https://sdk.cloud.google.com | bash | ||
| 55 | - | ||
| 56 | - * Most tests require you to have an active, billing-enabled project on | ||
| 57 | - the | ||
| 58 | - [Google Developers Console](https://console.developers.google.com). | ||
| 59 | - | ||
| 60 | - * You will need a set of | ||
| 61 | - [Service Account Credentials](https://console.developers.google.com/project/_/apiui/credential) | ||
| 62 | - for your project in ``json`` form. | ||
| 63 | - | ||
| 64 | - * Set the environment variables appropriately for your project. | ||
| 65 | - | ||
| 66 | - $ export GOOGLE_APPLICATION_CREDENTIALS=your-service-account-json-file | ||
| 67 | - $ export TEST_PROJECT_ID=your-project-id | ||
| 68 | - $ export TEST_BUCKET_NAME=your-bucket-name | ||
| 69 | - | ||
| 70 | - If you want to run the Google App Engine tests, you will need: | ||
| 71 | - | ||
| 72 | - * The App Engine Python SDK. You can install this by downloading it [here] | ||
| 73 | - (https://cloud.google.com/appengine/downloads?hl=en) | ||
| 74 | - | ||
| 75 | - * You can also download it programatically with the | ||
| 76 | - tests/scripts/fetch_gae_sdk.py | ||
| 77 | - | ||
| 78 | - $ test/scripts/fetch_gae_sdk.py <dest dir> | ||
| 79 | - | ||
| 80 | - * You will need to set an additional environment variable: | ||
| 81 | - | ||
| 82 | - $ export GAE_PYTHONPATH=<path your AppeEngine sdk> | ||
| 83 | - | ||
| 84 | - To run the bigquery tests: | ||
| 85 | - | ||
| 86 | - * Create a dataset in your project named `test_dataset`. | ||
| 87 | - | ||
| 88 | - gcloud alpha bigquery datasets create test_dataset | ||
| 89 | - | ||
| 90 | - * Load sample data into google cloud storage (for import tests): | ||
| 91 | - | ||
| 92 | - gsutil cp tests/resources/data.csv gs://$TEST_BUCKET_NAME/data.csv | ||
| 93 | - | ||
| 94 | - * Load the sample data into a table named `test_table` (for export and streaming tests): | ||
| 95 | - | ||
| 96 | - gcloud alpha bigquery import \ | ||
| 97 | - gs://$TEST_BUCKET_NAME/data.csv \ | ||
| 98 | - test_dataset/test_table \ | ||
| 99 | - --schema-file tests/resources/schema.json | ||
| 100 | - | ||
| 101 | - ### Test environments | ||
| 102 | - | ||
| 103 | - We use [tox](https://tox.readthedocs.org/en/latest/) to configure | ||
| 104 | - multiple python environments: | ||
| 105 | - | ||
| 106 | - * ``py27`` contains tests for samples that run in a normal Python 2.7 | ||
| 107 | - environment. This is (mostly) everything outside of the | ||
| 108 | - ``appengine`` directory. | ||
| 109 | - * ``gae`` contains tests for samples that run only in Google App | ||
| 110 | - Engine. This is (mostly) everything in the ``appengine`` directory. | ||
| 111 | - * ``pep8`` just runs the linter. | ||
| 112 | - | ||
| 113 | - To run tests for a particular environment, invoke tox with the ``-e`` | ||
| 114 | - flag: | ||
| 115 | - | ||
| 116 | - tox -e py27 | ||
| 117 | - | ||
| 118 | - To run one particular test suite or provide additional parameters to | ||
| 119 | - ``nose``, invoke tox like this: | ||
| 120 | - | ||
| 121 | - toxe -e py27 -- storage/tests/test_list_objects.py | ||
| 122 | - | ||
| 123 | - *Note*: The ``gae`` environment can't be told to run one particular | ||
| 124 | - test at this time. | ||
| 125 | - | ||
| 126 | - ### Adding new tests | ||
| 127 | - | ||
| 128 | - There are a handful of common testing utilities are located under | ||
| 129 | - ``tests``, see existing tests for example usage. | ||
| 130 | - | ||
| 131 | - When adding a new top-level directory, be sure to edit ``.coveragerc`` | ||
| 132 | - to include it in coveralls. | ||
| 133 | - | ||
| 134 | - To add new tests that require Google App Engine, please place them in | ||
| 135 | - the ``appengine`` directory if possible. If you place them elsewhere, | ||
| 136 | - you will need to modify ``tox.ini`` to make the environments | ||
| 137 | - appropriately run or ignore your test. | ||
| 39 | + See [TESTING.md](TESTING.md). | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,79 @@ | |||
| 1 | + # Testing | ||
| 2 | + | ||
| 3 | + The tests in this repository are system tests and run against live services, therefore, it takes a bit of configuration to run all of the tests locally. | ||
| 4 | + | ||
| 5 | + Before you can run tests locally you must have: | ||
| 6 | + | ||
| 7 | + * The latest [tox](https://tox.readthedocs.org/en/latest/), | ||
| 8 | + [pip](https://pypi.python.org/pypi/pip), and [gcp-python-repo-tools](https://pypi.python.org/pypi/gcp-python-repo-tools) installed. | ||
| 9 | + | ||
| 10 | + $ sudo pip install --upgrade tox pip gcp-python-repo-tools | ||
| 11 | + | ||
| 12 | + * The [Google Cloud SDK](https://cloud.google.com/sdk/) installed. You | ||
| 13 | + can do so with the following command: | ||
| 14 | + | ||
| 15 | + $ curl https://sdk.cloud.google.com | bash | ||
| 16 | + | ||
| 17 | + ## Preparing a project for testing | ||
| 18 | + | ||
| 19 | + Most tests require you to have an active, billing-enabled project on the | ||
| 20 | + [Google Cloud Console](https://console.cloud.google.com). | ||
| 21 | + | ||
| 22 | + ### Creating resources | ||
| 23 | + | ||
| 24 | + Some resources need to be created in a project ahead of time before testing. We have a script that can create everything needed: | ||
| 25 | + | ||
| 26 | + gcloud config set project <your-project-id> | ||
| 27 | + scripts/prepare-testing-project.sh | ||
| 28 | + | ||
| 29 | + The script will also instruct you to follow a URL to enable APIs. You will need to do that. | ||
| 30 | + | ||
| 31 | + ### Getting a service account key | ||
| 32 | + | ||
| 33 | + From the Cloud Console, create a new Service Account and download its json key. Place this file in `testing/resources/service-account.json`. | ||
| 34 | + | ||
| 35 | + ## Environment variables | ||
| 36 | + | ||
| 37 | + * Copy `testing/resources/test-env.tmpl.sh` to `testing/resources/test-env.sh`, and updated it with your configuration. | ||
| 38 | + * Run `source testing/resources/test-env.sh`. | ||
| 39 | + * Run `export GOOGLE_APPLICATION_CREDENTIALS=testing/resources/service-account.json`. | ||
| 40 | + | ||
| 41 | + If you want to run the Google App Engine tests, you will need: | ||
| 42 | + | ||
| 43 | + * The App Engine Python SDK. You can also download it programatically with `gcp-python-repo-tools`: | ||
| 44 | + | ||
| 45 | + $ gcp-python-repo-tools download-appengine-sdk <dest> | ||
| 46 | + | ||
| 47 | + * Set the `GAE_PYTHONPATH` variable: | ||
| 48 | + | ||
| 49 | + $ export GAE_PYTHONPATH=<path your AppeEngine sdk> | ||
| 50 | + | ||
| 51 | + ### Test environments | ||
| 52 | + | ||
| 53 | + We use [tox](https://tox.readthedocs.org/en/latest/) to configure | ||
| 54 | + multiple python environments: | ||
| 55 | + | ||
| 56 | + * ``py27`` and ``py34`` contains tests for samples that run in a normal Python 2.7 pr 3.4 environment. This is everything outside of the ``appengine`` directory that isn't slow or flaky. | ||
| 57 | + * ``py27-all`` and ``py34-all`` runs all tests except for App Engine tests. This can time some time and some tests are flaky. | ||
| 58 | + * ``gae`` contains tests for samples that run only in Google App Engine. This is (mostly) everything in the ``appengine`` directory. | ||
| 59 | + * ``pep8`` just runs the linter. | ||
| 60 | + | ||
| 61 | + To run tests for a particular environment, invoke tox with the ``-e`` | ||
| 62 | + flag: | ||
| 63 | + | ||
| 64 | + tox -e py27 | ||
| 65 | + | ||
| 66 | + To run one particular test suite or provide additional parameters to | ||
| 67 | + ``nose``, invoke tox like this: | ||
| 68 | + | ||
| 69 | + toxe -e py27 -- storage/tests/test_list_objects.py | ||
| 70 | + | ||
| 71 | + ### Adding new tests | ||
| 72 | + | ||
| 73 | + When adding a new top-level directory, be sure to edit ``.coveragerc`` | ||
| 74 | + to include it in coveralls. | ||
| 75 | + | ||
| 76 | + To add new tests that require Google App Engine, please place them in | ||
| 77 | + the ``appengine`` directory if possible. If you place them elsewhere, | ||
| 78 | + you will need to modify ``tox.ini`` to make the environments | ||
| 79 | + appropriately run or ignore your test. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,13 +12,13 @@ | |||
| 12 | 12 | # See the License for the specific language governing permissions and | |
| 13 | 13 | # limitations under the License. | |
| 14 | 14 | ||
| 15 | - from tests import AppEngineTestbedCase | ||
| 15 | + from testing import AppEngineTest | ||
| 16 | 16 | import webtest | |
| 17 | 17 | ||
| 18 | 18 | from . import main | |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | - class TestAppIdentityHandler(AppEngineTestbedCase): | ||
| 21 | + class TestAppIdentityHandler(AppEngineTest): | ||
| 22 | 22 | def setUp(self): | |
| 23 | 23 | super(TestAppIdentityHandler, self).setUp() | |
| 24 | 24 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,23 +12,22 @@ | |||
| 12 | 12 | # See the License for the specific language governing permissions and | |
| 13 | 13 | # limitations under the License. | |
| 14 | 14 | ||
| 15 | - import os | ||
| 16 | 15 | import re | |
| 17 | 16 | ||
| 18 | 17 | from apiclient.http import HttpMock | |
| 19 | 18 | import mock | |
| 20 | - import tests | ||
| 19 | + import testing | ||
| 21 | 20 | import webtest | |
| 22 | 21 | ||
| 23 | 22 | from . import main | |
| 24 | 23 | ||
| 25 | 24 | ||
| 26 | - class TestAuthSample(tests.AppEngineTestbedCase): | ||
| 25 | + class TestAuthSample(testing.AppEngineTest): | ||
| 27 | 26 | ||
| 28 | 27 | def setUp(self): | |
| 29 | 28 | super(TestAuthSample, self).setUp() | |
| 30 | 29 | self.app = webtest.TestApp(main.app) | |
| 31 | - main.PROJECTID = self.project_id | ||
| 30 | + main.PROJECTID = self.config.GCLOUD_PROJECT | ||
| 32 | 31 | ||
| 33 | 32 | def test_anonymous_get(self): | |
| 34 | 33 | response = self.app.get('/') | |
@@ -39,7 +38,7 @@ def test_anonymous_get(self): | |||
| 39 | 38 | r'.*accounts.*Login.*') | |
| 40 | 39 | ||
| 41 | 40 | def test_loggedin_get(self): | |
| 42 | - self.loginUser() | ||
| 41 | + self.login_user() | ||
| 43 | 42 | ||
| 44 | 43 | response = self.app.get('/') | |
| 45 | 44 | ||
@@ -49,10 +48,10 @@ def test_loggedin_get(self): | |||
| 49 | 48 | ||
| 50 | 49 | @mock.patch.object(main.decorator, 'has_credentials', return_value=True) | |
| 51 | 50 | def test_oauthed_get(self, *args): | |
| 52 | - self.loginUser() | ||
| 51 | + self.login_user() | ||
| 53 | 52 | ||
| 54 | 53 | mock_http = HttpMock( | |
| 55 | - os.path.join(self.resource_path, 'datasets-list.json'), | ||
| 54 | + self.resource_path('datasets-list.json'), | ||
| 56 | 55 | {'status': '200'}) | |
| 57 | 56 | ||
| 58 | 57 | with mock.patch.object(main.decorator, 'http', return_value=mock_http): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,20 +12,20 @@ | |||
| 12 | 12 | # See the License for the specific language governing permissions and | |
| 13 | 13 | # limitations under the License. | |
| 14 | 14 | ||
| 15 | - import tests | ||
| 15 | + import testing | ||
| 16 | 16 | import webtest | |
| 17 | 17 | ||
| 18 | 18 | from . import main | |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | - class TestBlobstoreSample(tests.AppEngineTestbedCase): | ||
| 21 | + class TestBlobstoreSample(testing.AppEngineTest): | ||
| 22 | 22 | ||
| 23 | 23 | def setUp(self): | |
| 24 | 24 | super(TestBlobstoreSample, self).setUp() | |
| 25 | 25 | self.app = webtest.TestApp(main.app) | |
| 26 | 26 | ||
| 27 | 27 | def test_form(self): | |
| 28 | - self.loginUser() | ||
| 28 | + self.login_user() | ||
| 29 | 29 | response = self.app.get('/') | |
| 30 | 30 | ||
| 31 | 31 | self.assertTrue('/_ah/upload' in response) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,13 +16,13 @@ | |||
| 16 | 16 | import re | |
| 17 | 17 | from unittest.case import SkipTest | |
| 18 | 18 | ||
| 19 | - import tests | ||
| 19 | + import testing | ||
| 20 | 20 | import webtest | |
| 21 | 21 | ||
| 22 | 22 | from . import main | |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | - class TestMySQLSample(tests.AppEngineTestbedCase): | ||
| 25 | + class TestMySQLSample(testing.AppEngineTest): | ||
| 26 | 26 | ||
| 27 | 27 | def setUp(self): | |
| 28 | 28 | if not os.path.exists('/var/run/mysqld/mysqld.sock'): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments