Skip to content
Closed
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
1 change: 0 additions & 1 deletion docs/samples

This file was deleted.

22 changes: 0 additions & 22 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,6 @@ def system(session):
"py.test", "--quiet", os.path.join("tests", "system.py"), *session.posargs
)


@nox.session(python=["2.7", "3.8"])
def snippets(session):
"""Run the snippets test suite."""

# Sanity check: Only run snippets tests if the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable.")

# Install all test dependencies, then install local packages in place.
session.install("mock", "pytest", "google-cloud-testutils")
session.install("google-cloud-storage")
session.install("grpcio")
session.install("-e", ".[all]")

# Run py.test against the snippets tests.
# Skip tests in samples/snippets, as those are run in a different session
# using the nox config from that directory.
session.run("py.test", os.path.join("docs", "snippets.py"), *session.posargs)
session.run("py.test", "samples", "--ignore=samples/snippets", *session.posargs)


Copy link
Contributor

Choose a reason for hiding this comment

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

We need to drop the linting of docs/samples below (Github isn't letting me leave the comment there).

@nox.session(python="3.8")
def cover(session):
"""Run the final coverage report.
Expand Down
Empty file removed samples/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 42 additions & 1 deletion samples/tests/conftest.py → samples/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import datetime
import os
import uuid

import google.auth
Expand All @@ -21,6 +22,7 @@

from google.cloud import bigquery
from google.cloud import bigquery_v2
from google.cloud import kms_v1


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -164,4 +166,43 @@ def model_id(client, dataset_id):

@pytest.fixture
def kms_key_name():
return "projects/cloud-samples-tests/locations/us/keyRings/test/cryptoKeys/test"
client = kms_v1.KeyManagementServiceClient()

location_name = f"projects/{os.environ.get('GOOGLE_CLOUD_PROJECT')}/locations/us"
key_ring_id = f"bigquery-test-{uuid.uuid4()}"

key_ring = client.create_key_ring(
request={"parent": location_name, "key_ring_id": key_ring_id, "key_ring": {}}
)

key_id = "{}".format(uuid.uuid4())
key = client.create_crypto_key(
request={
"parent": key_ring.name,
"crypto_key_id": key_id,
"crypto_key": {
"purpose": kms_v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT,
"version_template": {
"algorithm": kms_v1.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION,
"protection_level": kms_v1.ProtectionLevel.HSM,
},
"labels": {"foo": "bar", "zip": "zap"},
},
}
)

yield key.name

for key in client.list_crypto_keys(request={"parent": key_ring.name}):
if key.rotation_period or key.next_rotation_time:
updated_key = {"name": key.name}
update_mask = {"paths": ["rotation_period", "next_rotation_time"]}
client.update_crypto_key(
request={"crypto_key": updated_key, "update_mask": update_mask}
)

f = "state != DESTROYED AND state != DESTROY_SCHEDULED"
for version in client.list_crypto_key_versions(
request={"parent": key.name, "filter": f}
):
client.destroy_crypto_key_version(request={"name": version.name})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions samples/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==5.4.3
mock==4.0.2
google-cloud-kms==2.0.0
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import add_empty_column
import add_empty_column


def test_add_empty_column(capsys, table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import browse_table_data
import browse_table_data


def test_browse_table_data(capsys, table_with_data_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_list_jobs
from .. import create_job
import client_list_jobs
import create_job


def test_client_list_jobs(capsys, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_load_partitioned_table
import client_load_partitioned_table


def test_client_load_partitioned_table(capsys, random_table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query
import client_query


def test_client_query(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from google.cloud import bigquery

from .. import client_query_add_column
import client_query_add_column


def test_client_query_add_column(capsys, random_table_id, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_batch
import client_query_batch


def test_client_query_batch(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_destination_table
import client_query_destination_table


def test_client_query_destination_table(capsys, table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_destination_table_cmek
import client_query_destination_table_cmek


def test_client_query_destination_table_cmek(capsys, random_table_id, kms_key_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_destination_table_legacy
import client_query_destination_table_legacy


def test_client_query_destination_table_legacy(capsys, random_table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_dry_run
import client_query_dry_run


def test_client_query_dry_run(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import re

from .. import client_query_legacy_sql
import client_query_legacy_sql


def test_client_query_legacy_sql(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from google.cloud import bigquery

from .. import client_query_relax_column
import client_query_relax_column


def test_client_query_relax_column(capsys, random_table_id, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_w_array_params
import client_query_w_array_params


def test_client_query_w_array_params(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_w_named_params
import client_query_w_named_params


def test_client_query_w_named_params(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_w_positional_params
import client_query_w_positional_params


def test_client_query_w_positional_params(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_w_struct_params
import client_query_w_struct_params


def test_client_query_w_struct_params(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import client_query_w_timestamp_params
import client_query_w_timestamp_params


def test_client_query_w_timestamp_params(capsys,):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import copy_table
import copy_table


def test_copy_table(capsys, table_with_data_id, random_table_id, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import copy_table_cmek
import copy_table_cmek


def test_copy_table_cmek(capsys, random_table_id, table_with_data_id, kms_key_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import six
from google.cloud import bigquery

from .. import copy_table_multiple_source
import copy_table_multiple_source


def test_copy_table_multiple_source(capsys, random_table_id, random_dataset_id, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import create_dataset
import create_dataset


def test_create_dataset(capsys, random_dataset_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import create_job
import create_job


def test_create_job(capsys, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import create_table
import create_table


def test_create_table(capsys, random_table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import create_table_range_partitioned
import create_table_range_partitioned


def test_create_table_range_partitioned(capsys, random_table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from google.cloud import bigquery

from .. import dataset_exists
import dataset_exists


def test_dataset_exists(capsys, random_dataset_id, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import delete_dataset_labels
from .. import get_dataset_labels
from .. import label_dataset
import delete_dataset_labels
import get_dataset_labels
import label_dataset


def test_dataset_label_samples(capsys, dataset_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import delete_dataset
import delete_dataset


def test_delete_dataset(capsys, dataset_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import delete_table
import delete_table


def test_delete_table(capsys, table_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging

from .. import download_public_data
import download_public_data


def test_download_public_data(caplog, capsys):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging

from .. import download_public_data_sandbox
import download_public_data_sandbox


def test_download_public_data_sandbox(caplog, capsys):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import get_dataset
import get_dataset


def test_get_dataset(capsys, dataset_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from google.cloud import bigquery

from .. import get_table
import get_table


def test_get_table(capsys, random_table_id, client):
Expand Down
Loading