Skip to content

Commit fdbe26d

Browse files
author
Jon Wayne Parrott
committed
Merge pull request GoogleCloudPlatform#202 from GoogleCloudPlatform/repo-tools-reorg
Moving common testing tools to gcp-repo-tools.
2 parents 200fe87 + 7e92231 commit fdbe26d

32 files changed

+139
-418
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ managed_vms/django_tutorial/static/*
1212
lib
1313
testing/resources/test-env.sh
1414
testing/resources/service-account.json
15+
testing/resources/client-secrets.json
1516
secrets.tar
1617
.cache
1718
junit.xml

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
sudo: false
22
language: python
33
services:
4-
- memcached
5-
- mysql
4+
- memcached
5+
- mysql
66
branches:
77
only:
88
- master
@@ -13,15 +13,15 @@ env:
1313
global:
1414
- PATH=${PATH}:${HOME}/gcloud/google-cloud-sdk/bin
1515
- GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/testing/resources/service-account.json
16+
- GOOGLE_CLIENT_SECRETS=${TRAVIS_BUILD_DIR}/testing/resources/client-secrets.json
1617
- GAE_PYTHONPATH=${HOME}/.cache/google_appengine
17-
- secure: YIowCOMJ97rTcehKVT6Gi3u0Etm8s9+TBRGsNPJLgSF2zZdsh9IHcIc+tMDUMR3lpOe8y2a060RuODQcRsW1W1LIHej+ZE/gv6vATT6qNA3eKfKmZ9AyrpBO0fTOHlHrGBuU9ktBPR+iqvnq8MLWjnUozPFMJbuNBFITU7JP8jc=
18+
- GAE_ROOT=${HOME}/.cache/
19+
- secure: Orp9Et2TIwCG/Hf59aa0NUDF1pNcwcS4TFulXX175918cFREOzf/cNZNg+Ui585ZRFjbifZdc858tVuCVd8XlxQPXQgp7bwB7nXs3lby3LYg4+HD83Gaz7KOWxRLWVor6IVn8OxeCzwl6fJkdmffsTTO9csC4yZ7izHr+u7hiO4=
1820
before_install:
1921
- openssl aes-256-cbc -k "$secrets_password" -in secrets.tar.enc -out secrets.tar -d
2022
- tar xvf secrets.tar
2123
install:
2224
- pip install tox coverage
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}"`
2525
script:
2626
- source ${TRAVIS_BUILD_DIR}/testing/resources/test-env.sh
2727
- tox

appengine/bigquery/main_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import re
1616

17-
from apiclient.http import HttpMock
17+
from googleapiclient.http import HttpMock
1818
import main
1919
import mock
2020
import pytest
@@ -23,7 +23,7 @@
2323

2424
@pytest.fixture
2525
def app(cloud_config, testbed):
26-
main.PROJECTID = cloud_config.GCLOUD_PROJECT
26+
main.PROJECTID = cloud_config.project
2727
return webtest.TestApp(main.app)
2828

2929

appengine/conftest.py

+27-35
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import pytest
2-
import testing.appengine
3-
4-
5-
def pytest_configure(config):
6-
testing.appengine.setup_sdk_imports()
7-
8-
9-
def pytest_runtest_call(item):
10-
testing.appengine.import_appengine_config()
11-
12-
13-
@pytest.yield_fixture
14-
def testbed():
15-
testbed = testing.appengine.setup_testbed()
16-
yield testbed
17-
testbed.deactivate()
18-
19-
20-
@pytest.fixture
21-
def login(testbed):
22-
def _login(email='[email protected]', id='123', is_admin=False):
23-
testbed.setup_env(
24-
user_email=email,
25-
user_id=id,
26-
user_is_admin='1' if is_admin else '0',
27-
overwrite=True)
28-
return _login
29-
30-
31-
@pytest.fixture
32-
def run_tasks(testbed):
33-
def _run_tasks(app):
34-
testing.appengine.run_tasks(testbed, app)
35-
return _run_tasks
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Import py.test hooks and fixtures for App Engine
16+
from gcp.testing.appengine import (
17+
login,
18+
pytest_configure,
19+
pytest_runtest_call,
20+
run_tasks,
21+
testbed)
22+
23+
(login)
24+
(pytest_configure)
25+
(pytest_runtest_call)
26+
(run_tasks)
27+
(testbed)

appengine/mailgun/main_test.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from googleapiclient.http import HttpMockSequence
16+
import httplib2
1517
import main
18+
import mock
1619
import pytest
17-
from testing import Http2Mock
1820
import webtest
1921

2022

23+
class HttpMockSequenceWithCredentials(HttpMockSequence):
24+
def add_credentials(self, *args):
25+
pass
26+
27+
2128
@pytest.fixture
2229
def app():
2330
return webtest.TestApp(main.app)
@@ -29,27 +36,31 @@ def test_get(app):
2936

3037

3138
def test_post(app):
32-
http = Http2Mock(responses=[{}])
39+
http = HttpMockSequenceWithCredentials([
40+
({'status': '200'}, '')])
41+
patch_http = mock.patch.object(httplib2, 'Http', lambda: http)
3342

34-
with http:
43+
with patch_http:
3544
response = app.post('/', {
3645
'recipient': '[email protected]',
3746
'submit': 'Send simple email'})
3847

3948
assert response.status_int == 200
4049

41-
http = Http2Mock(responses=[{}])
50+
http = HttpMockSequenceWithCredentials([
51+
({'status': '200'}, '')])
4252

43-
with http:
53+
with patch_http:
4454
response = app.post('/', {
4555
'recipient': '[email protected]',
4656
'submit': 'Send complex email'})
4757

4858
assert response.status_int == 200
4959

50-
http = Http2Mock(responses=[{'status': 500, 'body': 'Test error'}])
60+
http = HttpMockSequenceWithCredentials([
61+
({'status': '500'}, 'Test error')])
5162

52-
with http, pytest.raises(Exception):
63+
with patch_http, pytest.raises(Exception):
5364
app.post('/', {
5465
'recipient': '[email protected]',
5566
'submit': 'Send simple email'})

appengine/storage/main_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def test_get(cloud_config):
21-
main.BUCKET_NAME = cloud_config.GCLOUD_PROJECT
21+
main.BUCKET_NAME = cloud_config.project
2222
app = webtest.TestApp(main.app)
2323

2424
response = app.get('/')

bigquery/api/async_query_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_async_query(cloud_config, capsys):
2222
'GROUP BY corpus;')
2323

2424
main(
25-
project_id=cloud_config.GCLOUD_PROJECT,
25+
project_id=cloud_config.project,
2626
query_string=query,
2727
batch=False,
2828
num_retries=5,

bigquery/api/export_data_to_cloud_storage_test.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@
1212
# limitations under the License.
1313

1414
from export_data_to_cloud_storage import main
15-
from testing import mark_flaky
15+
from gcp.testing.flaky import flaky
1616

1717
DATASET_ID = 'test_dataset'
1818
TABLE_ID = 'test_table'
1919

2020

21-
@mark_flaky
21+
@flaky
2222
def test_export_table_csv(cloud_config):
2323
cloud_storage_output_uri = \
24-
'gs://{}/output.csv'.format(cloud_config.CLOUD_STORAGE_BUCKET)
24+
'gs://{}/output.csv'.format(cloud_config.storage_bucket)
2525
main(
2626
cloud_storage_output_uri,
27-
cloud_config.GCLOUD_PROJECT,
27+
cloud_config.project,
2828
DATASET_ID,
2929
TABLE_ID,
3030
num_retries=5,
3131
interval=1,
3232
export_format="CSV")
3333

3434

35-
@mark_flaky
35+
@flaky
3636
def test_export_table_json(cloud_config):
3737
cloud_storage_output_uri = \
38-
'gs://{}/output.json'.format(cloud_config.CLOUD_STORAGE_BUCKET)
38+
'gs://{}/output.json'.format(cloud_config.storage_bucket)
3939
main(
4040
cloud_storage_output_uri,
41-
cloud_config.GCLOUD_PROJECT,
41+
cloud_config.project,
4242
DATASET_ID,
4343
TABLE_ID,
4444
num_retries=5,
4545
interval=1,
4646
export_format="NEWLINE_DELIMITED_JSON")
4747

4848

49-
@mark_flaky
49+
@flaky
5050
def test_export_table_avro(cloud_config):
5151
cloud_storage_output_uri = \
52-
'gs://{}/output.avro'.format(cloud_config.CLOUD_STORAGE_BUCKET)
52+
'gs://{}/output.avro'.format(cloud_config.storage_bucket)
5353
main(
5454
cloud_storage_output_uri,
55-
cloud_config.GCLOUD_PROJECT,
55+
cloud_config.project,
5656
DATASET_ID,
5757
TABLE_ID,
5858
num_retries=5,

bigquery/api/getting_started_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
def test_main(cloud_config, capsys):
20-
main(cloud_config.GCLOUD_PROJECT)
20+
main(cloud_config.project)
2121

2222
out, _ = capsys.readouterr()
2323

bigquery/api/list_datasets_projects_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
def test_main(cloud_config, capsys):
20-
main(cloud_config.GCLOUD_PROJECT)
20+
main(cloud_config.project)
2121

2222
out, _ = capsys.readouterr()
2323

bigquery/api/load_data_by_post_test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313

1414
import re
1515

16+
from gcp.testing.flaky import flaky
1617
from load_data_by_post import load_data
17-
from testing import mark_flaky
1818

1919
DATASET_ID = 'ephemeral_test_dataset'
2020
TABLE_ID = 'load_data_by_post'
2121

2222

23-
@mark_flaky
23+
@flaky
2424
def test_load_csv_data(cloud_config, resource, capsys):
2525
schema_path = resource('schema.json')
2626
data_path = resource('data.csv')
2727

2828
load_data(
2929
schema_path,
3030
data_path,
31-
cloud_config.GCLOUD_PROJECT,
31+
cloud_config.project,
3232
DATASET_ID,
3333
TABLE_ID
3434
)
@@ -39,15 +39,15 @@ def test_load_csv_data(cloud_config, resource, capsys):
3939
r'Waiting for job to finish.*Job complete.', re.DOTALL), out)
4040

4141

42-
@mark_flaky
42+
@flaky
4343
def test_load_json_data(cloud_config, resource, capsys):
4444
schema_path = resource('schema.json')
4545
data_path = resource('data.json')
4646

4747
load_data(
4848
schema_path,
4949
data_path,
50-
cloud_config.GCLOUD_PROJECT,
50+
cloud_config.project,
5151
DATASET_ID,
5252
TABLE_ID
5353
)

bigquery/api/load_data_from_csv_test.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
14+
from gcp.testing.flaky import flaky
1515
from load_data_from_csv import main
16-
from testing import mark_flaky
1716

1817
DATASET_ID = 'test_dataset'
1918
TABLE_ID = 'test_import_table'
2019

2120

22-
@mark_flaky
21+
@flaky
2322
def test_load_table(cloud_config, resource):
2423
cloud_storage_input_uri = 'gs://{}/data.csv'.format(
25-
cloud_config.CLOUD_STORAGE_BUCKET)
24+
cloud_config.storage_bucket)
2625
schema_file = resource('schema.json')
2726

2827
main(
29-
cloud_config.GCLOUD_PROJECT,
28+
cloud_config.project,
3029
DATASET_ID,
3130
TABLE_ID,
3231
schema_file=schema_file,

bigquery/api/streaming_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_stream_row_to_bigquery(cloud_config, resource, capsys):
2727
streaming.get_rows = lambda: rows
2828

2929
streaming.main(
30-
cloud_config.GCLOUD_PROJECT,
30+
cloud_config.project,
3131
DATASET_ID,
3232
TABLE_ID,
3333
num_retries=5)

bigquery/api/sync_query_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_sync_query(cloud_config, capsys):
2222
'GROUP BY corpus;')
2323

2424
main(
25-
project_id=cloud_config.GCLOUD_PROJECT,
25+
project_id=cloud_config.project,
2626
query=query,
2727
timeout=30,
2828
num_retries=5)

blog/introduction_to_data_models_in_cloud_datastore/blog_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# limitations under the License.
1313

1414
from blog import main
15-
from testing import mark_flaky
15+
from gcp.testing.flaky import flaky
1616

1717

18-
@mark_flaky
18+
@flaky
1919
def test_main(cloud_config):
20-
main(cloud_config.GCLOUD_PROJECT)
20+
main(cloud_config.project)

blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
from testing import mark_flaky
14+
from gcp.testing.flaky import flaky
1515
from wiki import main
1616

1717

18-
@mark_flaky
18+
@flaky
1919
def test_main(cloud_config):
20-
main(cloud_config.GCLOUD_PROJECT)
20+
main(cloud_config.project)

cloud_logging/api/list_logs_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818

1919
def test_main(cloud_config, capsys):
20-
list_logs.main(cloud_config.GCLOUD_PROJECT)
20+
list_logs.main(cloud_config.project)
2121
out, _ = capsys.readouterr()
2222
assert re.search(re.compile(r'.*', re.S), out)

0 commit comments

Comments
 (0)