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

Quickstart tests #569

Merged
merged 3 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
- GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/testing/resources/service-account.json
- GOOGLE_CLIENT_SECRETS=${TRAVIS_BUILD_DIR}/testing/resources/client-secrets.json
- GAE_ROOT=${HOME}/.cache/
- secure: TQ0e6XKeFwVkoqgOJH9f/afyRouUSC6s7LC32C4JS+O2X4sXyXTPXACmzu5wCW0BXPc6HvITMLvkf7g6XXyGlCPkjM8Uw5Vg5F9+cwN1HMlI+gK6bMGTUfrwN5ruFT+KmEnD4F93NY3xkDbZd0fw23d/mVloTc6V0gUsxEUkuhM=
- secure: f3aU0nf8ZBV2QfZ03oeqvR0f/JM69P/7IH3IGoBcRUWVIXXhQ6Esh9SmCUILPtis1ZKu11I9c+NDebZio7PFgTqfvLbKzAkrg0ucx+Bsyx6379/S1trbLeKunERSGA3GqK6+OCoR5q/9sKxNvlm/c/e9h7xZmPfP5W0qwVR/K0M=
addons:
apt:
sources:
Expand Down
45 changes: 45 additions & 0 deletions bigquery/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

from google.cloud import bigquery
import pytest

import quickstart


# Must match the dataset listed in quickstart.py (there's no easy way to
# extract this).
DATASET_ID = 'my_new_dataset'


@pytest.fixture
def temporary_dataset():
"""Fixture that ensures the test dataset does not exist before or
after a test."""
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(DATASET_ID)

if dataset.exists():
dataset.delete()

yield

if dataset.exists():
dataset.delete()


def test_quickstart(capsys, temporary_dataset):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert DATASET_ID in out
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def cloud_config():
project=os.environ.get('GCLOUD_PROJECT'),
storage_bucket=os.environ.get('CLOUD_STORAGE_BUCKET'),
client_secrets=os.environ.get('GOOGLE_CLIENT_SECRETS'),
bigtable_instance=os.environ.get('BIGTABLE_CLUSTER'))
bigtable_instance=os.environ.get('BIGTABLE_CLUSTER'),
api_key=os.environ.get('API_KEY'))


def get_resource_path(resource, local_path):
Expand Down
21 changes: 21 additions & 0 deletions datastore/api/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

import quickstart


def test_quickstart(capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'Saved' in out
9 changes: 6 additions & 3 deletions datastore/api/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ def inequality_invalid(client):

return list(query.fetch())

except google.cloud.exceptions.BadRequest:
except (google.cloud.exceptions.BadRequest,
google.cloud.exceptions.GrpcRendezvous):
pass


Expand Down Expand Up @@ -579,7 +580,8 @@ def inequality_sort_invalid_not_same(client):

return list(query.fetch())

except google.cloud.exceptions.BadRequest:
except (google.cloud.exceptions.BadRequest,
google.cloud.exceptions.GrpcRendezvous):
pass


Expand All @@ -593,7 +595,8 @@ def inequality_sort_invalid_not_first(client):

return list(query.fetch())

except google.cloud.exceptions.BadRequest:
except (google.cloud.exceptions.BadRequest,
google.cloud.exceptions.GrpcRendezvous):
pass


Expand Down
22 changes: 22 additions & 0 deletions language/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.


import quickstart


def test_quickstart(capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'Sentiment' in out
22 changes: 22 additions & 0 deletions logging/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.


import quickstart


def test_quickstart(capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'Logged' in out
45 changes: 45 additions & 0 deletions pubsub/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

from google.cloud import pubsub
import pytest

import quickstart


# Must match the dataset listed in quickstart.py (there's no easy way to
# extract this).
TOPIC_NAME = 'my-new-topic'


@pytest.fixture
def temporary_topic():
"""Fixture that ensures the test dataset does not exist before or
after a test."""
pubsub_client = pubsub.Client()
topic = pubsub_client.topic(TOPIC_NAME)

if topic.exists():
topic.delete()

yield

if topic.exists():
topic.delete()


def test_quickstart(capsys, temporary_topic):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert TOPIC_NAME in out
Binary file modified secrets.tar.enc
Binary file not shown.
28 changes: 28 additions & 0 deletions storage/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

import mock

import quickstart


@mock.patch('google.cloud.storage.client.Client.create_bucket')
def test_quickstart(create_bucket_mock, capsys):
# Unlike other quickstart tests, this one mocks out the creation
# because buckets are expensive, globally-namespaced object.
create_bucket_mock.return_value = mock.sentinel.bucket

quickstart.run_quickstart()

create_bucket_mock.assert_called_with('my-new-bucket')
1 change: 1 addition & 0 deletions testing/resources/test-env.tmpl.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Environment variables for system tests.
export GCLOUD_PROJECT=your-project-id
export CLOUD_STORAGE_BUCKET=$GCLOUD_PROJECT
export API_KEY=
export BIGTABLE_CLUSTER=bigtable-test
export BIGTABLE_ZONE=us-central1-c

Expand Down
7 changes: 3 additions & 4 deletions translate/cloud-client/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ def run_quickstart():
translate_client = translate.Client(api_key)

# The text to translate
text = 'Hello, world!'
text = u'Hello, world!'
# The target language
target = 'ru'

# Translates some text into Russian
translation = translate_client.translate(text, target_language=target)

print('Text: {}'.format(text))
print('Translation: {}'.format(
translation['translatedText'].encode('utf-8')))
print(u'Text: {}'.format(text))
print(u'Translation: {}'.format(translation['translatedText']))
# [END translate_quickstart]


Expand Down
40 changes: 40 additions & 0 deletions translate/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

from google.cloud import translate
import mock
import pytest

import quickstart


@pytest.fixture
def mock_client(cloud_config):
original_client_ctor = translate.Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's a ctor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor.


def new_client_ctor(api_key):
# Strip api_key argument and replace with our api key.
return original_client_ctor(cloud_config.api_key)

with mock.patch(
'google.cloud.translate.Client',
side_effect=new_client_ctor):
yield


def test_quickstart(mock_client, capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert u'Привет мир!' in out
11 changes: 8 additions & 3 deletions vision/cloud-client/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
def run_quickstart():
# [START vision_quickstart]
import io
import os

# Imports the Google Cloud client library
from google.cloud import vision
Expand All @@ -26,11 +27,15 @@ def run_quickstart():
vision_client = vision.Client()

# The name of the image file to annotate
fileName = './resources/wakeupcat.jpg'
file_name = os.path.join(
os.path.dirname(__file__),
'resources/wakeupcat.jpg')

# Loads the image into memory
with io.open(fileName, 'rb') as image_file:
image = vision_client.image(content=image_file.read())
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision_client.image(
content=content)

# Performs label detection on the image file
labels = image.detect_labels()
Expand Down
21 changes: 21 additions & 0 deletions vision/cloud-client/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# 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.

import quickstart


def test_quickstart(capsys):
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'Labels' in out