-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added BigQuery client method (create table) for Tables API #3
Conversation
@engelke please review We're working from my fork, as this is dependent on googleapis#7562 which adds the samples directory. |
bigquery/samples/create_table.py
Outdated
# limitations under the License. | ||
|
||
|
||
def create_table(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect to see a client
argument here (and also the table ID).
Do the tests pass when you run pytest
on the samples directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Tests have now been updated to pass. 😄
bigquery/samples/tests/conftest.py
Outdated
now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8] | ||
) | ||
table = client.create_table("{}.{}".format(dataset_id, table_id)) | ||
yield "{}".format(table.full_table_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use the full_table_id
property for this. Use table.project
, table.dataset_id
, and table.table_id
.
The full_table_id
property is in legacy SQL format, and also I don't really trust that it's always populated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with your suggestion
bigquery/samples/tests/conftest.py
Outdated
table_id = "example_table_{}_{}".format( | ||
now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8] | ||
) | ||
table = client.create_table("{}.{}".format(dataset_id, table_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're creating a table in your sample, you don't actually want to create one in the test fixture.
We might want to rename this to random_table_id
to indicate that no table is actually created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the fixture to random_table_id
and removed the creation of the table in the fixture.
create_table.create_table(client, project_id, dataset_id, table_id) | ||
out, err = capsys.readouterr() | ||
assert create_table in out | ||
assert table.table_id == "my_table" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the table
object coming from? Potentially you could return it from the create_table
function, but in this case I think we can get a good enough of a sense that what we wanted to happen actually happened from out
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the test to work as you suggested.
from .. import create_table | ||
|
||
|
||
def test_table_samples(capsys, client, project_id, dataset_id, table_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename table_id
to random_table_id
when you rename the fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this as suggested.
""" | ||
create_table.create_table(client, project_id, dataset_id, table_id) | ||
out, err = capsys.readouterr() | ||
assert create_table in out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert that some string you expect appears in out, not the sample module. In this case, looking for table_id
in out would give a good indication that the table was created successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this as you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much improved, thank you! A few more items to cleanup in the tests.
bigquery/samples/tests/conftest.py
Outdated
table = client.create_table("{}.{}".format(dataset_id, table_id)) | ||
yield "{}".format(table.full_table_id) | ||
client.delete_table(table, delete_contents=True) | ||
yield "{}.{}".format(dataset_id, random_table_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, since you don't have to do any cleanup, this can now be return
instead of yield
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced both table and dataset fixtures to return instead of yield.
def test_table_samples(capsys, client, project_id, dataset_id, table_id): | ||
"""Since creating a table is a long operation, test all table model samples | ||
def test_table_samples(capsys, client, random_table_id): | ||
"""Since creating a table is a long operation, test all table samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a table isn't all that long of an operation. You can test each sample separately. This docstring comment can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this docstring.
@@ -15,11 +15,10 @@ | |||
from .. import create_table | |||
|
|||
|
|||
def test_table_samples(capsys, client, project_id, dataset_id, table_id): | |||
"""Since creating a table is a long operation, test all table model samples | |||
def test_table_samples(capsys, client, random_table_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be renamed to test_create_table
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name as directed.
bigquery/samples/tests/conftest.py
Outdated
@@ -25,6 +25,20 @@ def client(): | |||
return bigquery.Client() | |||
|
|||
|
|||
@pytest.fixture | |||
def project_id(client): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you don't use the project_id
fixture anywhere, this can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
Oh, and one last thing. Let's remove the |
The test_create_table_sample snippet is now removed from the bigquery collection. |
bigquery/samples/tests/conftest.py
Outdated
@pytest.fixture | ||
def dataset_id(client): | ||
now = datetime.datetime.now() | ||
dataset_id = "python_samples_{}_{}".format( | ||
now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8] | ||
) | ||
dataset = client.create_dataset(dataset_id) | ||
yield "{}.{}".format(dataset.project, dataset.dataset_id) | ||
return "{}.{}".format(dataset.project, dataset.dataset_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this should stay yield
, because it needs to clean up the dataset after the test runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
LGTM |
* iam proposal #3 maintain compatibility with defaultdict remove in place raise KeyError on delete update deprecation for dict-key access and factory methods clean up maintain compatibility - removing duplicate in __setitems__ check for conditions for dict access remove empty binding fix test accessing private var _bindings fix(tests): change version to make existing tests pass tests: add tests for getitem, delitem, setitem on v3 and conditions test policy.bindings property fixlint black sort bindings by role when converting to api repr add deprecation warning for iam factory methods update deprecation message for role methods make Policy#bindings.members a set update policy docs fix docs make docs better fix: Bigtable policy class to use Policy.bindings add from_pb with conditions test add to_pb condition test blacken fix policy __delitem__ add docs on dict access do not modify binding in to_apr_repr * feat(storage): support requested_policy_version for get_iam_policy * add system-test * add ref doc sample to get_iam_policy * add requested_policy_version to blob * fix tests * nit: typo * blacken * fix docs build * format docs * remove unused variables
…ogleapis#10001) * iam proposal #3 maintain compatibility with defaultdict remove in place raise KeyError on delete update deprecation for dict-key access and factory methods clean up maintain compatibility - removing duplicate in __setitems__ check for conditions for dict access remove empty binding fix test accessing private var _bindings fix(tests): change version to make existing tests pass tests: add tests for getitem, delitem, setitem on v3 and conditions test policy.bindings property fixlint black sort bindings by role when converting to api repr add deprecation warning for iam factory methods update deprecation message for role methods make Policy#bindings.members a set update policy docs fix docs make docs better fix: Bigtable policy class to use Policy.bindings add from_pb with conditions test add to_pb condition test blacken fix policy __delitem__ add docs on dict access do not modify binding in to_apr_repr * feat(bigtable): support requested_policy_version to instance * fix passing requested_policy_version to pb2 * add unit test * add unit test
No description provided.