-
Notifications
You must be signed in to change notification settings - Fork 10
Improve make_group/make_acc_group fixture consistency
#50
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b424b9
Implement double-check waiting after creating groups to ensure they a…
asnare d93afd3
Tidy up None-checking of the group identifier.
asnare 8ccd960
Merge branch 'main' into make-group-reliability
asnare 022d8b0
Remove comments.
asnare 41e2418
Merge branch 'main' into make-group-reliability
asnare 9777e9d
Mark tests for type-checking.
asnare 87e48fa
Ensure no other warnings occurred.
asnare 8eb3263
Replace fixture setup via context variables with a setup hook instead.
asnare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,75 @@ | ||
| from databricks.labs.pytester.fixtures.iam import make_user, make_group, make_acc_group | ||
| from databricks.labs.pytester.fixtures.unwrap import call_stateful | ||
| import sys | ||
| import warnings | ||
| from functools import partial | ||
| from unittest.mock import call | ||
|
|
||
| import pytest | ||
|
|
||
| def test_make_user_no_args(): | ||
| from databricks.labs.pytester.fixtures.iam import make_acc_group, make_group, make_user, Group | ||
| from databricks.labs.pytester.fixtures.unwrap import call_stateful, CallContext | ||
|
|
||
|
|
||
| def test_make_user_no_args() -> None: | ||
| ctx, user = call_stateful(make_user) | ||
| assert ctx is not None | ||
| assert user is not None | ||
| ctx['ws'].users.create.assert_called_once() | ||
| ctx['ws'].users.delete.assert_called_once() | ||
|
|
||
|
|
||
| def test_make_group_no_args(): | ||
| ctx, group = call_stateful(make_group) | ||
| assert ctx is not None | ||
| def _setup_groups_api(call_context: CallContext, *, client_fixture_name: str) -> CallContext: | ||
| """Minimum mocking of the specific client so that when a group is created it is also visible via the list() method. | ||
| This is required because the make_group and make_acc_group fixtures double-check after creating a group to ensure | ||
| the group is visible.""" | ||
| mock_group = Group(id="an_id") | ||
| call_context[client_fixture_name].groups.create.return_value = mock_group | ||
| call_context[client_fixture_name].groups.list.return_value = [mock_group] | ||
| return call_context | ||
|
|
||
|
|
||
| def test_make_group_no_args() -> None: | ||
| ctx, group = call_stateful(make_group, call_context_setup=partial(_setup_groups_api, client_fixture_name="ws")) | ||
|
|
||
| assert group is not None | ||
| ctx['ws'].groups.create.assert_called_once() | ||
| assert ctx['ws'].groups.get.call_args_list == [call("an_id"), call("an_id")] | ||
| assert ctx['ws'].groups.list.call_args_list == [ | ||
| call(attributes="id", filter='id eq "an_id"'), | ||
| call(attributes="id", filter='id eq "an_id"'), | ||
| ] | ||
| ctx['ws'].groups.delete.assert_called_once() | ||
|
|
||
|
|
||
| def test_make_acc_group_no_args(): | ||
| ctx, group = call_stateful(make_acc_group) | ||
| assert ctx is not None | ||
| def test_make_acc_group_no_args() -> None: | ||
| ctx, group = call_stateful(make_acc_group, call_context_setup=partial(_setup_groups_api, client_fixture_name="acc")) | ||
|
|
||
| assert group is not None | ||
| ctx['acc'].groups.create.assert_called_once() | ||
| assert ctx['acc'].groups.get.call_args_list == [call("an_id"), call("an_id")] | ||
| assert ctx['acc'].groups.list.call_args_list == [ | ||
| call(attributes="id", filter='id eq "an_id"'), | ||
| call(attributes="id", filter='id eq "an_id"'), | ||
| ] | ||
| ctx['acc'].groups.delete.assert_called_once() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "make_group_fixture, client_fixture_name", | ||
| [(make_group, "ws"), (make_acc_group, "acc")], | ||
| ) | ||
| def test_make_group_deprecated_arg(make_group_fixture, client_fixture_name) -> None: | ||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
|
|
||
| call_stateful( | ||
| make_group_fixture, | ||
| wait_for_provisioning=True, | ||
| call_context_setup=partial(_setup_groups_api, client_fixture_name=client_fixture_name), | ||
| ) | ||
|
|
||
| # Check that the expected warning was emitted and attributed to the caller. | ||
| (the_warning, *other_warnings) = w | ||
| assert not other_warnings | ||
| assert issubclass(the_warning.category, DeprecationWarning) | ||
| assert "wait_for_provisioning when making a group is deprecated" in str(the_warning.message) | ||
| assert the_warning.filename == sys.modules[call_stateful.__module__].__file__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.