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

Remove cloud config fixture #887

Merged
merged 3 commits into from
Apr 4, 2017
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
8 changes: 6 additions & 2 deletions appengine/standard/background/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from mock import patch
import pytest
import webtest

import main

PROJECT = os.environ['GCLOUD_PROJECT']


@pytest.fixture
def app(cloud_config, testbed):
main.PROJECTID = cloud_config.project
def app(testbed):
main.PROJECTID = PROJECT
return webtest.TestApp(main.app)


Expand Down
7 changes: 5 additions & 2 deletions appengine/standard/bigquery/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from googleapiclient.http import HttpMock
Expand All @@ -21,10 +22,12 @@

import main

PROJECT = os.environ['GCLOUD_PROJECT']


@pytest.fixture
def app(cloud_config, testbed):
main.PROJECTID = cloud_config.project
def app(testbed):
main.PROJECTID = PROJECT
return webtest.TestApp(main.app)


Expand Down
7 changes: 5 additions & 2 deletions appengine/standard/storage/api-client/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

import webtest

import main

PROJECT = os.environ['GCLOUD_PROJECT']

def test_get(cloud_config):
main.BUCKET_NAME = cloud_config.project

def test_get():
main.BUCKET_NAME = PROJECT
app = webtest.TestApp(main.app)

response = app.get('/')
Expand Down
8 changes: 6 additions & 2 deletions appengine/standard/storage/appengine-client/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import webtest

import main

PROJECT = os.environ['GCLOUD_PROJECT']


def test_get(testbed, cloud_config):
main.BUCKET_NAME = cloud_config.project
def test_get(testbed):
main.BUCKET_NAME = PROJECT
app = webtest.TestApp(main.app)

response = app.get('/')
Expand Down
11 changes: 7 additions & 4 deletions bigquery/api/async_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
# limitations under the License.

import json
import os

from async_query import main

PROJECT = os.environ['GCLOUD_PROJECT']

def test_async_query(cloud_config, capsys):

def test_async_query(capsys):
query = (
'SELECT corpus FROM publicdata:samples.shakespeare '
'GROUP BY corpus;')

main(
project_id=cloud_config.project,
project_id=PROJECT,
query_string=query,
batch=False,
num_retries=5,
Expand All @@ -35,11 +38,11 @@ def test_async_query(cloud_config, capsys):
assert json.loads(value) is not None


def test_async_query_standard_sql(cloud_config, capsys):
def test_async_query_standard_sql(capsys):
query = 'SELECT [1, 2, 3] AS arr;' # Only valid in standard SQL

main(
project_id=cloud_config.project,
project_id=PROJECT,
query_string=query,
batch=False,
num_retries=5,
Expand Down
25 changes: 13 additions & 12 deletions bigquery/api/export_data_to_cloud_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from gcp.testing.flaky import flaky

from export_data_to_cloud_storage import main

PROJECT = os.environ['GCLOUD_PROJECT']
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
DATASET_ID = 'test_dataset'
TABLE_ID = 'test_table'


@flaky
def test_export_table_csv(cloud_config):
cloud_storage_output_uri = \
'gs://{}/output.csv'.format(cloud_config.storage_bucket)
def test_export_table_csv():
cloud_storage_output_uri = 'gs://{}/output.csv'.format(BUCKET)
main(
cloud_storage_output_uri,
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID,
num_retries=5,
Expand All @@ -34,12 +37,11 @@ def test_export_table_csv(cloud_config):


@flaky
def test_export_table_json(cloud_config):
cloud_storage_output_uri = \
'gs://{}/output.json'.format(cloud_config.storage_bucket)
def test_export_table_json():
cloud_storage_output_uri = 'gs://{}/output.json'.format(BUCKET)
main(
cloud_storage_output_uri,
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID,
num_retries=5,
Expand All @@ -48,12 +50,11 @@ def test_export_table_json(cloud_config):


@flaky
def test_export_table_avro(cloud_config):
cloud_storage_output_uri = \
'gs://{}/output.avro'.format(cloud_config.storage_bucket)
def test_export_table_avro():
cloud_storage_output_uri = 'gs://{}/output.avro'.format(BUCKET)
main(
cloud_storage_output_uri,
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID,
num_retries=5,
Expand Down
7 changes: 5 additions & 2 deletions bigquery/api/getting_started_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from getting_started import main

PROJECT = os.environ['GCLOUD_PROJECT']

def test_main(cloud_config, capsys):
main(cloud_config.project)

def test_main(capsys):
main(PROJECT)

out, _ = capsys.readouterr()

Expand Down
10 changes: 7 additions & 3 deletions bigquery/api/installed_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from oauth2client.client import GoogleCredentials

import installed_app

PROJECT = os.environ['GCLOUD_PROJECT']
CLIENT_SECRETS = os.environ['GOOGLE_CLIENT_SECRETS']


class Namespace(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)


def test_main(cloud_config, monkeypatch, capsys):
installed_app.CLIENT_SECRETS = cloud_config.client_secrets
def test_main(monkeypatch, capsys):
installed_app.CLIENT_SECRETS = CLIENT_SECRETS

# Replace the user credentials flow with Application Default Credentials.
# Unfortunately, there's no easy way to fully test the user flow.
Expand All @@ -34,7 +38,7 @@ def mock_run_flow(flow, storage, args):
monkeypatch.setattr(installed_app.tools, 'run_flow', mock_run_flow)

args = Namespace(
project_id=cloud_config.project,
project_id=PROJECT,
logging_level='INFO',
noauth_local_webserver=True)

Expand Down
7 changes: 5 additions & 2 deletions bigquery/api/list_datasets_projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from list_datasets_projects import main

PROJECT = os.environ['GCLOUD_PROJECT']

def test_main(cloud_config, capsys):
main(cloud_config.project)

def test_main(capsys):
main(PROJECT)

out, _ = capsys.readouterr()

Expand Down
10 changes: 6 additions & 4 deletions bigquery/api/load_data_by_post_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from gcp.testing.flaky import flaky

from load_data_by_post import load_data

PROJECT = os.environ['GCLOUD_PROJECT']
DATASET_ID = 'ephemeral_test_dataset'
TABLE_ID = 'load_data_by_post'


@flaky
def test_load_csv_data(cloud_config, resource, capsys):
def test_load_csv_data(resource, capsys):
schema_path = resource('schema.json')
data_path = resource('data.csv')

load_data(
schema_path,
data_path,
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID
)
Expand All @@ -41,14 +43,14 @@ def test_load_csv_data(cloud_config, resource, capsys):


@flaky
def test_load_json_data(cloud_config, resource, capsys):
def test_load_json_data(resource, capsys):
schema_path = resource('schema.json')
data_path = resource('data.json')

load_data(
schema_path,
data_path,
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID
)
Expand Down
11 changes: 7 additions & 4 deletions bigquery/api/load_data_from_csv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from gcp.testing.flaky import flaky

from load_data_from_csv import main

PROJECT = os.environ['GCLOUD_PROJECT']
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
DATASET_ID = 'test_dataset'
TABLE_ID = 'test_import_table'


@flaky
def test_load_table(cloud_config, resource):
cloud_storage_input_uri = 'gs://{}/data.csv'.format(
cloud_config.storage_bucket)
def test_load_table(resource):
cloud_storage_input_uri = 'gs://{}/data.csv'.format(BUCKET)
schema_file = resource('schema.json')

main(
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID,
schema_file=schema_file,
Expand Down
7 changes: 4 additions & 3 deletions bigquery/api/streaming_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
# limitations under the License.

import json
import os

import streaming


PROJECT = os.environ['GCLOUD_PROJECT']
DATASET_ID = 'test_dataset'
TABLE_ID = 'test_table'


def test_stream_row_to_bigquery(cloud_config, resource, capsys):
def test_stream_row_to_bigquery(resource, capsys):
with open(resource('streamrows.json'), 'r') as rows_file:
rows = json.load(rows_file)

streaming.get_rows = lambda: rows

streaming.main(
cloud_config.project,
PROJECT,
DATASET_ID,
TABLE_ID,
num_retries=5)
Expand Down
11 changes: 7 additions & 4 deletions bigquery/api/sync_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
# limitations under the License.

import json
import os

from sync_query import main

PROJECT = os.environ['GCLOUD_PROJECT']

def test_sync_query(cloud_config, capsys):

def test_sync_query(capsys):
query = (
'SELECT corpus FROM publicdata:samples.shakespeare '
'GROUP BY corpus;')

main(
project_id=cloud_config.project,
project_id=PROJECT,
query=query,
timeout=30,
num_retries=5,
Expand All @@ -34,11 +37,11 @@ def test_sync_query(cloud_config, capsys):
assert json.loads(result) is not None


def test_sync_query_standard_sql(cloud_config, capsys):
def test_sync_query_standard_sql(capsys):
query = 'SELECT [1, 2, 3] AS arr;' # Only valid in standard SQL

main(
project_id=cloud_config.project,
project_id=PROJECT,
query=query,
timeout=30,
num_retries=5,
Expand Down
Loading