Skip to content
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
55 changes: 55 additions & 0 deletions bigquery/unit_tests/test__helpers.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions bigquery/unit_tests/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestConnection(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.bigquery._http import Connection

return Connection

def _make_one(self, *args, **kw):
Expand All @@ -38,6 +39,7 @@ def test_build_api_url_no_extra_query_params(self):
def test_build_api_url_w_extra_query_params(self):
from six.moves.urllib.parse import parse_qsl
from six.moves.urllib.parse import urlsplit

conn = self._make_one()
uri = conn.build_api_url('/foo', {'bar': 'baz'})
scheme, netloc, path, qs, _ = urlsplit(uri)
Expand Down
18 changes: 18 additions & 0 deletions bigquery/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

def _make_credentials():
import google.auth.credentials

return mock.Mock(spec=google.auth.credentials.Credentials)


Expand All @@ -27,13 +28,15 @@ class TestClient(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.client import Client

return Client

def _make_one(self, *args, **kw):
return self._get_target_class()(*args, **kw)

def test_ctor(self):
from google.cloud.bigquery._http import Connection

PROJECT = 'PROJECT'
creds = _make_credentials()
http = object()
Expand All @@ -45,6 +48,7 @@ def test_ctor(self):
def test_list_projects_defaults(self):
import six
from google.cloud.bigquery.client import Project

PROJECT_1 = 'PROJECT_ONE'
PROJECT_2 = 'PROJECT_TWO'
PATH = 'projects'
Expand Down Expand Up @@ -115,6 +119,7 @@ def test_list_projects_explicit_response_missing_projects_key(self):
def test_list_datasets_defaults(self):
import six
from google.cloud.bigquery.dataset import Dataset

PROJECT = 'PROJECT'
DATASET_1 = 'dataset_one'
DATASET_2 = 'dataset_two'
Expand Down Expand Up @@ -185,6 +190,7 @@ def test_list_datasets_explicit_response_missing_datasets_key(self):

def test_dataset(self):
from google.cloud.bigquery.dataset import Dataset

PROJECT = 'PROJECT'
DATASET = 'dataset_name'
creds = _make_credentials()
Expand All @@ -208,6 +214,7 @@ def test_list_jobs_defaults(self):
from google.cloud.bigquery.job import CopyJob
from google.cloud.bigquery.job import ExtractTableToStorageJob
from google.cloud.bigquery.job import QueryJob

PROJECT = 'PROJECT'
DATASET = 'test_dataset'
SOURCE_TABLE = 'source_table'
Expand Down Expand Up @@ -336,6 +343,7 @@ def test_list_jobs_defaults(self):
def test_list_jobs_load_job_wo_sourceUris(self):
import six
from google.cloud.bigquery.job import LoadTableFromStorageJob

PROJECT = 'PROJECT'
DATASET = 'test_dataset'
SOURCE_TABLE = 'source_table'
Expand Down Expand Up @@ -391,6 +399,7 @@ def test_list_jobs_load_job_wo_sourceUris(self):

def test_list_jobs_explicit_missing(self):
import six

PROJECT = 'PROJECT'
PATH = 'projects/%s/jobs' % PROJECT
DATA = {}
Expand Down Expand Up @@ -421,6 +430,7 @@ def test_list_jobs_explicit_missing(self):

def test_load_table_from_storage(self):
from google.cloud.bigquery.job import LoadTableFromStorageJob

PROJECT = 'PROJECT'
JOB = 'job_name'
DATASET = 'dataset_name'
Expand All @@ -440,6 +450,7 @@ def test_load_table_from_storage(self):

def test_copy_table(self):
from google.cloud.bigquery.job import CopyJob

PROJECT = 'PROJECT'
JOB = 'job_name'
DATASET = 'dataset_name'
Expand All @@ -460,6 +471,7 @@ def test_copy_table(self):

def test_extract_table_to_storage(self):
from google.cloud.bigquery.job import ExtractTableToStorageJob

PROJECT = 'PROJECT'
JOB = 'job_name'
DATASET = 'dataset_name'
Expand All @@ -479,6 +491,7 @@ def test_extract_table_to_storage(self):

def test_run_async_query_defaults(self):
from google.cloud.bigquery.job import QueryJob

PROJECT = 'PROJECT'
JOB = 'job_name'
QUERY = 'select count(*) from persons'
Expand All @@ -496,6 +509,7 @@ def test_run_async_query_defaults(self):
def test_run_async_w_udf_resources(self):
from google.cloud.bigquery._helpers import UDFResource
from google.cloud.bigquery.job import QueryJob

RESOURCE_URI = 'gs://some-bucket/js/lib.js'
PROJECT = 'PROJECT'
JOB = 'job_name'
Expand All @@ -515,6 +529,7 @@ def test_run_async_w_udf_resources(self):
def test_run_async_w_query_parameters(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter
from google.cloud.bigquery.job import QueryJob

PROJECT = 'PROJECT'
JOB = 'job_name'
QUERY = 'select count(*) from persons'
Expand All @@ -533,6 +548,7 @@ def test_run_async_w_query_parameters(self):

def test_run_sync_query_defaults(self):
from google.cloud.bigquery.query import QueryResults

PROJECT = 'PROJECT'
QUERY = 'select count(*) from persons'
creds = _make_credentials()
Expand All @@ -549,6 +565,7 @@ def test_run_sync_query_defaults(self):
def test_run_sync_query_w_udf_resources(self):
from google.cloud.bigquery._helpers import UDFResource
from google.cloud.bigquery.query import QueryResults

RESOURCE_URI = 'gs://some-bucket/js/lib.js'
PROJECT = 'PROJECT'
QUERY = 'select count(*) from persons'
Expand All @@ -567,6 +584,7 @@ def test_run_sync_query_w_udf_resources(self):
def test_run_sync_query_w_query_parameters(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter
from google.cloud.bigquery.query import QueryResults

PROJECT = 'PROJECT'
QUERY = 'select count(*) from persons'
creds = _make_credentials()
Expand Down
9 changes: 9 additions & 0 deletions bigquery/unit_tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestAccessGrant(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.dataset import AccessGrant

return AccessGrant

def _make_one(self, *args, **kw):
Expand Down Expand Up @@ -84,6 +85,7 @@ class TestDataset(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.dataset import Dataset

return Dataset

def _make_one(self, *args, **kw):
Expand Down Expand Up @@ -198,6 +200,7 @@ def test_ctor_defaults(self):

def test_ctor_explicit(self):
from google.cloud.bigquery.dataset import AccessGrant

phred = AccessGrant('OWNER', 'userByEmail', '[email protected]')
bharney = AccessGrant('OWNER', 'userByEmail', '[email protected]')
grants = [phred, bharney]
Expand Down Expand Up @@ -233,6 +236,7 @@ def test_access_grants_setter_non_list(self):

def test_access_grants_setter_invalid_field(self):
from google.cloud.bigquery.dataset import AccessGrant

client = _Client(self.PROJECT)
dataset = self._make_one(self.DS_NAME, client)
phred = AccessGrant('OWNER', 'userByEmail', '[email protected]')
Expand All @@ -241,6 +245,7 @@ def test_access_grants_setter_invalid_field(self):

def test_access_grants_setter(self):
from google.cloud.bigquery.dataset import AccessGrant

client = _Client(self.PROJECT)
dataset = self._make_one(self.DS_NAME, client)
phred = AccessGrant('OWNER', 'userByEmail', '[email protected]')
Expand Down Expand Up @@ -372,6 +377,7 @@ def test_create_w_bound_client(self):

def test_create_w_alternate_client(self):
from google.cloud.bigquery.dataset import AccessGrant

PATH = 'projects/%s/datasets' % self.PROJECT
USER_EMAIL = '[email protected]'
GROUP_EMAIL = '[email protected]'
Expand Down Expand Up @@ -786,6 +792,7 @@ def test_list_tables_explicit(self):

def test_table_wo_schema(self):
from google.cloud.bigquery.table import Table

conn = _Connection({})
client = _Client(project=self.PROJECT, connection=conn)
dataset = self._make_one(self.DS_NAME, client=client)
Expand All @@ -798,6 +805,7 @@ def test_table_wo_schema(self):
def test_table_w_schema(self):
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.table import Table

conn = _Connection({})
client = _Client(project=self.PROJECT, connection=conn)
dataset = self._make_one(self.DS_NAME, client=client)
Expand Down Expand Up @@ -825,6 +833,7 @@ def __init__(self, *responses):

def api_request(self, **kw):
from google.cloud.exceptions import NotFound

self._requested.append(kw)

try:
Expand Down
18 changes: 18 additions & 0 deletions bigquery/unit_tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class TestLoadTableFromStorageJob(unittest.TestCase, _Base):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.job import LoadTableFromStorageJob

return LoadTableFromStorageJob

def _setUpConstants(self):
Expand Down Expand Up @@ -264,6 +265,7 @@ def test_ctor(self):

def test_ctor_w_schema(self):
from google.cloud.bigquery.schema import SchemaField

client = _Client(self.PROJECT)
table = _Table()
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
Expand All @@ -281,6 +283,7 @@ def test_schema_setter_non_list(self):

def test_schema_setter_invalid_field(self):
from google.cloud.bigquery.schema import SchemaField

client = _Client(self.PROJECT)
table = _Table()
job = self._make_one(self.JOB_NAME, table, [self.SOURCE1], client)
Expand All @@ -290,6 +293,7 @@ def test_schema_setter_invalid_field(self):

def test_schema_setter(self):
from google.cloud.bigquery.schema import SchemaField

client = _Client(self.PROJECT)
table = _Table()
job = self._make_one(self.JOB_NAME, table, [self.SOURCE1], client)
Expand Down Expand Up @@ -465,6 +469,7 @@ def test_begin_w_bound_client(self):

def test_begin_w_alternate_client(self):
from google.cloud.bigquery.schema import SchemaField

PATH = '/projects/%s/jobs' % (self.PROJECT,)
RESOURCE = self._makeResource(ended=True)
LOAD_CONFIGURATION = {
Expand Down Expand Up @@ -646,6 +651,7 @@ class TestCopyJob(unittest.TestCase, _Base):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.job import CopyJob

return CopyJob

def _makeResource(self, started=False, ended=False):
Expand Down Expand Up @@ -998,6 +1004,7 @@ class TestExtractTableToStorageJob(unittest.TestCase, _Base):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.job import ExtractTableToStorageJob

return ExtractTableToStorageJob

def _makeResource(self, started=False, ended=False):
Expand Down Expand Up @@ -1292,6 +1299,7 @@ class TestQueryJob(unittest.TestCase, _Base):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.job import QueryJob

return QueryJob

def _makeResource(self, started=False, ended=False):
Expand Down Expand Up @@ -1431,6 +1439,7 @@ def test_ctor_defaults(self):

def test_ctor_w_udf_resources(self):
from google.cloud.bigquery._helpers import UDFResource

RESOURCE_URI = 'gs://some-bucket/js/lib.js'
udf_resources = [UDFResource("resourceUri", RESOURCE_URI)]
client = _Client(self.PROJECT)
Expand All @@ -1440,6 +1449,7 @@ def test_ctor_w_udf_resources(self):

def test_ctor_w_query_parameters(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter

query_parameters = [ScalarQueryParameter("foo", 'INT64', 123)]
client = _Client(self.PROJECT)
job = self._make_one(self.JOB_NAME, self.QUERY, client,
Expand Down Expand Up @@ -1501,6 +1511,7 @@ def test_from_api_repr_w_properties(self):

def test_results(self):
from google.cloud.bigquery.query import QueryResults

client = _Client(self.PROJECT)
job = self._make_one(self.JOB_NAME, self.QUERY, client)
results = job.results()
Expand Down Expand Up @@ -1542,6 +1553,7 @@ def test_begin_w_bound_client(self):
def test_begin_w_alternate_client(self):
from google.cloud.bigquery.dataset import Dataset
from google.cloud.bigquery.dataset import Table

PATH = '/projects/%s/jobs' % (self.PROJECT,)
TABLE = 'TABLE'
DS_NAME = 'DATASET'
Expand Down Expand Up @@ -1612,6 +1624,7 @@ def test_begin_w_alternate_client(self):

def test_begin_w_udf(self):
from google.cloud.bigquery._helpers import UDFResource

RESOURCE_URI = 'gs://some-bucket/js/lib.js'
INLINE_UDF_CODE = 'var someCode = "here";'
PATH = '/projects/%s/jobs' % (self.PROJECT,)
Expand Down Expand Up @@ -1661,6 +1674,7 @@ def test_begin_w_udf(self):

def test_begin_w_named_query_parameter(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter

query_parameters = [ScalarQueryParameter('foo', 'INT64', 123)]
PATH = '/projects/%s/jobs' % (self.PROJECT,)
RESOURCE = self._makeResource()
Expand Down Expand Up @@ -1712,6 +1726,7 @@ def test_begin_w_named_query_parameter(self):

def test_begin_w_positional_query_parameter(self):
from google.cloud.bigquery._helpers import ScalarQueryParameter

query_parameters = [ScalarQueryParameter.positional('INT64', 123)]
PATH = '/projects/%s/jobs' % (self.PROJECT,)
RESOURCE = self._makeResource()
Expand Down Expand Up @@ -1794,6 +1809,7 @@ def test_exists_hit_w_alternate_client(self):
def test_reload_w_bound_client(self):
from google.cloud.bigquery.dataset import Dataset
from google.cloud.bigquery.dataset import Table

PATH = '/projects/%s/jobs/%s' % (self.PROJECT, self.JOB_NAME)
DS_NAME = 'DATASET'
DEST_TABLE = 'dest_table'
Expand Down Expand Up @@ -1851,6 +1867,7 @@ def __init__(self, project='project', connection=None):

def dataset(self, name):
from google.cloud.bigquery.dataset import Dataset

return Dataset(name, client=self)


Expand Down Expand Up @@ -1882,6 +1899,7 @@ def __init__(self, *responses):

def api_request(self, **kw):
from google.cloud.exceptions import NotFound

self._requested.append(kw)

try:
Expand Down
Loading