Skip to content

Commit c7ef504

Browse files
committed
Add simple system test for BigQuery Storage API (googleapis#473)
* Add simple system test for BigQuery Storage API For the system tests to run correctly, an unreleased version of api_core is required. Updates the setup.py file to indicate the minimum version. * Remove mock dependency and unnecessary imports. * Use -e for local deps.
1 parent a8b4453 commit c7ef504

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

bigquery_storage/noxfile.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def default(session):
3333
run the tests.
3434
"""
3535
# Install all test dependencies, then install this package in-place.
36-
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
36+
session.install('mock', 'pytest', 'pytest-cov')
37+
for local_dep in LOCAL_DEPS:
38+
session.install('-e', local_dep)
3739
session.install('-e', '.')
3840

3941
# Run py.test against the unit tests.
@@ -88,3 +90,22 @@ def cover(session):
8890
session.install('coverage', 'pytest-cov')
8991
session.run('coverage', 'report', '--show-missing', '--fail-under=100')
9092
session.run('coverage', 'erase')
93+
94+
@nox.session(python=['2.7', '3.6'])
95+
def system(session):
96+
"""Run the system test suite."""
97+
98+
# Sanity check: Only run system tests if the environment variable is set.
99+
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
100+
session.skip('Credentials must be set via environment variable.')
101+
102+
# Install all test dependencies, then install this package into the
103+
# virtualenv's dist-packages.
104+
session.install('pytest')
105+
session.install('-e', os.path.join('..', 'test_utils'))
106+
for local_dep in LOCAL_DEPS:
107+
session.install('-e', local_dep)
108+
session.install('.')
109+
110+
# Run py.test against the system tests.
111+
session.run('py.test', '--quiet', 'tests/system/')

bigquery_storage/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
version = '0.1.0'
2525
release_status = '3 - Alpha'
2626
dependencies = [
27-
'google-api-core[grpc] >= 1.1.0, < 2.0.0dev',
27+
'google-api-core[grpc] >= 1.5.1, < 2.0.0dev',
2828
'enum34; python_version < "3.4"',
2929
]
3030

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""System tests for reading rows from tables."""
17+
18+
import os
19+
20+
import pytest
21+
22+
from google.cloud import bigquery_storage_v1beta1
23+
24+
25+
@pytest.fixture()
26+
def project_id():
27+
return os.environ['PROJECT_ID']
28+
29+
30+
@pytest.fixture()
31+
def client():
32+
return bigquery_storage_v1beta1.BigQueryStorageClient()
33+
34+
35+
def test_read_rows(project_id, client):
36+
table_ref = bigquery_storage_v1beta1.types.TableReference()
37+
table_ref.project_id = 'bigquery-public-data'
38+
table_ref.dataset_id = 'usa_names'
39+
table_ref.table_id = 'usa_1910_2013'
40+
41+
session = client.create_read_session(
42+
table_ref,
43+
requested_streams=1,
44+
parent='projects/{}'.format(project_id))
45+
46+
stream_pos = bigquery_storage_v1beta1.types.StreamPosition(
47+
stream=session.streams[0])
48+
rowstream = client.read_rows(stream_pos)
49+
page = rowstream.next()
50+
51+
assert page.status.estimated_row_count > 0
52+
assert len(page.avro_rows.serialized_binary_rows) > 0

0 commit comments

Comments
 (0)