Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a1ad83b

Browse filesBrowse files
author
Jon Wayne Parrott
committed
gigantic re-organization of tests.
* /testing/resources have been moved to their respective samples. * /testing/utils.py has been broken up into several files, many of which will be moved to gcp-python-repo-tools. * Managed VMs tests have been re-written and enabled. * /scripts/check_requirements.py and /scripts/update_requirements.txt have been removed in favor of gcp-python-repo tools. * /lib has been removed, the tox environment for gae will just create it when needed. * Switched to using manual encryption and a secrets.tar file so that we can store both the service account and the environment variables needed. * Moved the testing section in CONTRIBUTING.md to its own file. * Changed the way that environment variables are used in tests. See testing.cloud.config.
1 parent 90f71c2 commit a1ad83b
Copy full SHA for a1ad83b

File tree

Expand file treeCollapse file tree

108 files changed

+766
-848
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

108 files changed

+766
-848
lines changed

‎.coveragerc

Copy file name to clipboardExpand all lines: .coveragerc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include =
88
monitoring/*
99
storage/*
1010
cloud_logging/*
11+
managed_vms/*
1112
[report]
1213
exclude_lines =
1314
pragma: NO COVER

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ coverage-gae.json
55
.tox
66
coverage.xml
77
nosetests.xml
8+
nosetests-*.xml
89
python-docs-samples.json
10+
service-account.json
911
__pycache__
1012
*db\.sqlite3
1113
managed_vms/django_tutorial/static/*
1214
**/migrations/*
15+
lib
16+
testing/resources/test-env.sh
17+
testing/resources/service-account.json
18+
secrets.tar

‎.travis.yml

Copy file name to clipboard
+11-19Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
sudo: false
2-
#add language, etc. here
32
language: python
4-
3+
services:
4+
- memcached
5+
- mysql
56
branches:
67
only:
7-
- master
8-
8+
- master
99
cache:
1010
directories:
1111
- $HOME/.cache
12-
1312
env:
1413
global:
1514
- 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
1716
- 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=
2118
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
2421
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
2722
- 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}"`
2925
script:
26+
- source ${TRAVIS_BUILD_DIR}/testing/resources/test-env.sh
3027
- 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

‎CONTRIBUTING.md

Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-99Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -36,102 +36,4 @@ be able to accept your pull requests.
3636

3737
## Testing
3838

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).

‎TESTING.md

Copy file name to clipboard
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

‎appengine/app_identity/signing/main_test.py

Copy file name to clipboardExpand all lines: appengine/app_identity/signing/main_test.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from tests import AppEngineTestbedCase
15+
from testing import AppEngineTest
1616
import webtest
1717

1818
from . import main
1919

2020

21-
class TestAppIdentityHandler(AppEngineTestbedCase):
21+
class TestAppIdentityHandler(AppEngineTest):
2222
def setUp(self):
2323
super(TestAppIdentityHandler, self).setUp()
2424

‎appengine/bigquery/main_test.py

Copy file name to clipboardExpand all lines: appengine/bigquery/main_test.py
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
1615
import re
1716

1817
from apiclient.http import HttpMock
1918
import mock
20-
import tests
19+
import testing
2120
import webtest
2221

2322
from . import main
2423

2524

26-
class TestAuthSample(tests.AppEngineTestbedCase):
25+
class TestAuthSample(testing.AppEngineTest):
2726

2827
def setUp(self):
2928
super(TestAuthSample, self).setUp()
3029
self.app = webtest.TestApp(main.app)
31-
main.PROJECTID = self.project_id
30+
main.PROJECTID = self.config.GCLOUD_PROJECT
3231

3332
def test_anonymous_get(self):
3433
response = self.app.get('/')
@@ -39,7 +38,7 @@ def test_anonymous_get(self):
3938
r'.*accounts.*Login.*')
4039

4140
def test_loggedin_get(self):
42-
self.loginUser()
41+
self.login_user()
4342

4443
response = self.app.get('/')
4544

@@ -49,10 +48,10 @@ def test_loggedin_get(self):
4948

5049
@mock.patch.object(main.decorator, 'has_credentials', return_value=True)
5150
def test_oauthed_get(self, *args):
52-
self.loginUser()
51+
self.login_user()
5352

5453
mock_http = HttpMock(
55-
os.path.join(self.resource_path, 'datasets-list.json'),
54+
self.resource_path('datasets-list.json'),
5655
{'status': '200'})
5756

5857
with mock.patch.object(main.decorator, 'http', return_value=mock_http):

‎appengine/blobstore/main_test.py

Copy file name to clipboardExpand all lines: appengine/blobstore/main_test.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import tests
15+
import testing
1616
import webtest
1717

1818
from . import main
1919

2020

21-
class TestBlobstoreSample(tests.AppEngineTestbedCase):
21+
class TestBlobstoreSample(testing.AppEngineTest):
2222

2323
def setUp(self):
2424
super(TestBlobstoreSample, self).setUp()
2525
self.app = webtest.TestApp(main.app)
2626

2727
def test_form(self):
28-
self.loginUser()
28+
self.login_user()
2929
response = self.app.get('/')
3030

3131
self.assertTrue('/_ah/upload' in response)

‎appengine/cloudsql/main_test.py

Copy file name to clipboardExpand all lines: appengine/cloudsql/main_test.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import re
1717
from unittest.case import SkipTest
1818

19-
import tests
19+
import testing
2020
import webtest
2121

2222
from . import main
2323

2424

25-
class TestMySQLSample(tests.AppEngineTestbedCase):
25+
class TestMySQLSample(testing.AppEngineTest):
2626

2727
def setUp(self):
2828
if not os.path.exists('/var/run/mysqld/mysqld.sock'):

‎appengine/images/main_test.py

Copy file name to clipboardExpand all lines: appengine/images/main_test.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
# limitations under the License.
1414

1515
import mock
16-
from tests import AppEngineTestbedCase
16+
from testing import AppEngineTest
1717
import webtest
1818

1919
from . import main
2020

2121

22-
class TestHandlers(AppEngineTestbedCase):
22+
class TestHandlers(AppEngineTest):
2323
def setUp(self):
2424
super(TestHandlers, self).setUp()
2525

‎appengine/localtesting/test_task_queue.py

Copy file name to clipboardExpand all lines: appengine/localtesting/test_task_queue.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import operator
1615
# [START taskqueue]
16+
import operator
17+
import os
1718
import unittest
1819

1920
from google.appengine.api import taskqueue
@@ -28,7 +29,8 @@ def setUp(self):
2829

2930
# root_path must be set the the location of queue.yaml.
3031
# Otherwise, only the 'default' queue will be available.
31-
self.testbed.init_taskqueue_stub(root_path='tests/resources')
32+
self.testbed.init_taskqueue_stub(
33+
root_path=os.path.join(os.path.dirname(__file__), 'resources'))
3234
self.taskqueue_stub = self.testbed.get_stub(
3335
testbed.TASKQUEUE_SERVICE_NAME)
3436

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.