Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/python-bigquery-sqlalchemy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.0
Choose a base ref
...
head repository: googleapis/python-bigquery-sqlalchemy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.1
Choose a head ref
  • 4 commits
  • 10 files changed
  • 3 contributors

Commits on Apr 7, 2021

  1. chore: Add license headers for python config files (#117)

    Source-Author: Anthonios Partheniou <partheniou@google.com>
    Source-Date: Tue Apr 6 11:32:03 2021 -0400
    Source-Repo: googleapis/synthtool
    Source-Sha: 5b5bf6d519b2d658d9f2e483d9f6f3d0ba8ee6bc
    Source-Link: googleapis/synthtool@5b5bf6d
    yoshi-automation authored Apr 7, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b3b0a0a View commit details
  2. test: use random suffix in DML test table (#114)

    This should avoid flakes. Also, adds a table expiration so that
    if cleanup fails, BigQuery will still eventually remove the
    table.
    
    Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
    - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-sqlalchemy/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
    - [ ] Ensure the tests and linter pass
    - [ ] Code coverage does not decrease (if any source code was changed)
    - [ ] Appropriate docs were updated (if necessary)
    
    Fixes #111  🦕
    tswast authored Apr 7, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    29c7fb0 View commit details

Commits on Apr 12, 2021

  1. fix: use project_id property from service account credentials (#120)

    * fix: use `project_id` property from service account credentials
    
    * fix typo in test
    
    * more test typos
    tswast authored Apr 12, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab2051d View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    75a6458 View commit details
Showing with 155 additions and 19 deletions.
  1. +14 −0 .pre-commit-config.yaml
  2. +7 −0 CHANGELOG.md
  3. +13 −0 docs/conf.py
  4. +2 −2 pybigquery/_helpers.py
  5. +1 −1 setup.py
  6. +2 −2 synth.metadata
  7. +36 −4 tests/system/conftest.py
  8. +74 −0 tests/system/test_helpers.py
  9. +5 −9 tests/system/test_sqlalchemy_bigquery.py
  10. +1 −1 tests/unit/test_helpers.py
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google LLC
#
# 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.
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,13 @@

[1]: https://pypi.org/project/pybigquery/#history

### [0.6.1](https://www.github.com/googleapis/python-bigquery-sqlalchemy/compare/v0.6.0...v0.6.1) (2021-04-12)


### Bug Fixes

* use `project_id` property from service account credentials ([#120](https://www.github.com/googleapis/python-bigquery-sqlalchemy/issues/120)) ([ab2051d](https://www.github.com/googleapis/python-bigquery-sqlalchemy/commit/ab2051de3097adb68503c01a87f9a91092711d2a))

## [0.6.0](https://www.github.com/googleapis/python-bigquery-sqlalchemy/compare/v0.5.1...v0.6.0) (2021-04-06)


13 changes: 13 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2021 Google LLC
#
# 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.
#
# pybigquery documentation build configuration file
#
4 changes: 2 additions & 2 deletions pybigquery/_helpers.py
Original file line number Diff line number Diff line change
@@ -38,13 +38,13 @@ def create_bigquery_client(
credentials_path
)
credentials = credentials.with_scopes(SCOPES)
default_project = credentials.project
default_project = credentials.project_id
elif credentials_info:
credentials = service_account.Credentials.from_service_account_info(
credentials_info
)
credentials = credentials.with_scopes(SCOPES)
default_project = credentials.project
default_project = credentials.project_id
else:
credentials, default_project = google.auth.default(scopes=SCOPES)

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
# Package metadata.

name = "pybigquery"
version = "0.6.0"
version = "0.6.1"
description = "SQLAlchemy dialect for BigQuery"

# Should be one of:
4 changes: 2 additions & 2 deletions synth.metadata
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-bigquery-sqlalchemy.git",
"sha": "b7c9d6f3151520a20239df197a151aa80c3ebdcd"
"sha": "101153a14706ae325893f3ddf6dbd934c4ef65a0"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "4501974ad08b5d693311457e2ea4ce845676e329"
"sha": "5b5bf6d519b2d658d9f2e483d9f6f3d0ba8ee6bc"
}
}
],
40 changes: 36 additions & 4 deletions tests/system/conftest.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

import datetime
import pathlib
import random

import pytest
import google.api_core.exceptions
@@ -16,6 +18,12 @@
DATA_DIR = pathlib.Path(__file__).parent / "data"


def temp_suffix():
timestamp = datetime.datetime.utcnow().strftime("%y%m%d_%H%M%S")
random_string = hex(random.randrange(1000000))[2:]
return f"{timestamp}_{random_string}"


def load_sample_data(
full_table_id: str,
bigquery_client: bigquery.Client,
@@ -84,12 +92,36 @@ def bigquery_dataset(


@pytest.fixture(scope="session", autouse=True)
def bigquery_empty_table(bigquery_dataset, bigquery_client, bigquery_schema):
def bigquery_dml_dataset(bigquery_client: bigquery.Client):
project_id = bigquery_client.project
dataset_id = "test_pybigquery_dml"
dataset = bigquery.Dataset(f"{project_id}.{dataset_id}")
# Add default table expiration in case cleanup fails.
dataset.default_table_expiration_ms = 1000 * int(
datetime.timedelta(days=1).total_seconds()
)
dataset = bigquery_client.create_dataset(dataset, exists_ok=True)
return dataset_id


@pytest.fixture(scope="session", autouse=True)
def bigquery_empty_table(
bigquery_dataset: str,
bigquery_dml_dataset: str,
bigquery_client: bigquery.Client,
bigquery_schema: List[bigquery.SchemaField],
):
project_id = bigquery_client.project
dataset_id = bigquery_dataset
table_id = f"{project_id}.{dataset_id}.sample_dml"
# Cleanup the sample_dml table, if it exists.
old_table_id = f"{project_id}.{bigquery_dataset}.sample_dml"
bigquery_client.delete_table(old_table_id, not_found_ok=True)
# Create new table in its own dataset.
dataset_id = bigquery_dml_dataset
table_id = f"{project_id}.{dataset_id}.sample_dml_{temp_suffix()}"
empty_table = bigquery.Table(table_id, schema=bigquery_schema)
bigquery_client.create_table(empty_table, exists_ok=True)
bigquery_client.create_table(empty_table)
yield table_id
bigquery_client.delete_table(empty_table)


@pytest.fixture(scope="session", autouse=True)
74 changes: 74 additions & 0 deletions tests/system/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2021 The PyBigQuery Authors
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

import os
import json

import pytest


@pytest.fixture(scope="session")
def module_under_test():
from pybigquery import _helpers

return _helpers


@pytest.fixture
def credentials_path():
if "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:
pytest.skip("GOOGLE_APPLICATION_CREDENTIALS must be set")
return os.environ["GOOGLE_APPLICATION_CREDENTIALS"]


@pytest.fixture
def credentials_info(credentials_path):
with open(credentials_path) as credentials_file:
return json.load(credentials_file)


def test_create_bigquery_client_with_credentials_path(
module_under_test, credentials_path, credentials_info
):
bqclient = module_under_test.create_bigquery_client(
credentials_path=credentials_path
)
assert bqclient.project == credentials_info["project_id"]


def test_create_bigquery_client_with_credentials_path_respects_project(
module_under_test, credentials_path
):
"""Test that project_id is used, even when there is a default project.
https://github.com/googleapis/python-bigquery-sqlalchemy/issues/48
"""
bqclient = module_under_test.create_bigquery_client(
credentials_path=credentials_path, project_id="connection-url-project",
)
assert bqclient.project == "connection-url-project"


def test_create_bigquery_client_with_credentials_info(
module_under_test, credentials_info
):
bqclient = module_under_test.create_bigquery_client(
credentials_info=credentials_info
)
assert bqclient.project == credentials_info["project_id"]


def test_create_bigquery_client_with_credentials_info_respects_project(
module_under_test, credentials_info
):
"""Test that project_id is used, even when there is a default project.
https://github.com/googleapis/python-bigquery-sqlalchemy/issues/48
"""
bqclient = module_under_test.create_bigquery_client(
credentials_info=credentials_info, project_id="connection-url-project",
)
assert bqclient.project == "connection-url-project"
14 changes: 5 additions & 9 deletions tests/system/test_sqlalchemy_bigquery.py
Original file line number Diff line number Diff line change
@@ -174,8 +174,8 @@ def table_one_row(engine):


@pytest.fixture(scope="session")
def table_dml(engine):
return Table("test_pybigquery.sample_dml", MetaData(bind=engine), autoload=True)
def table_dml(engine, bigquery_empty_table):
return Table(bigquery_empty_table, MetaData(bind=engine), autoload=True)


@pytest.fixture(scope="session")
@@ -355,13 +355,11 @@ def test_tables_list(engine, engine_using_test_dataset):
tables = engine.table_names()
assert "test_pybigquery.sample" in tables
assert "test_pybigquery.sample_one_row" in tables
assert "test_pybigquery.sample_dml" in tables
assert "test_pybigquery.sample_view" not in tables

tables = engine_using_test_dataset.table_names()
assert "sample" in tables
assert "sample_one_row" in tables
assert "sample_dml" in tables
assert "sample_view" not in tables


@@ -520,7 +518,7 @@ def test_dml(engine, session, table_dml):
{"string": "updated_row"}, synchronize_session=False
)
updated_result = table_dml.select().execute().fetchone()
assert updated_result["test_pybigquery.sample_dml_string"] == "updated_row"
assert updated_result[table_dml.c.string] == "updated_row"

# test delete
session.query(table_dml).filter(table_dml.c.string == "updated_row").delete(
@@ -576,16 +574,14 @@ def test_table_names_in_schema(inspector, inspector_using_test_dataset):
tables = inspector.get_table_names("test_pybigquery")
assert "test_pybigquery.sample" in tables
assert "test_pybigquery.sample_one_row" in tables
assert "test_pybigquery.sample_dml" in tables
assert "test_pybigquery.sample_view" not in tables
assert len(tables) == 3
assert len(tables) == 2

tables = inspector_using_test_dataset.get_table_names()
assert "sample" in tables
assert "sample_one_row" in tables
assert "sample_dml" in tables
assert "sample_view" not in tables
assert len(tables) == 3
assert len(tables) == 2


def test_view_names(inspector, inspector_using_test_dataset):
2 changes: 1 addition & 1 deletion tests/unit/test_helpers.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class AnonymousCredentialsWithProject(google.auth.credentials.AnonymousCredentia

def __init__(self, project):
super().__init__()
self.project = project
self.project_id = project

def with_scopes(self, scopes):
return self