-
Notifications
You must be signed in to change notification settings - Fork 13
Update user #300
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
Update user #300
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a69397f
added update-user method
ceciliastevens 25a9a79
fix failing test
ceciliastevens 9b7a2da
fix test
ceciliastevens f2d07ba
style
ceciliastevens e018e3a
style
ceciliastevens 7c1aa88
added bulk method
ceciliastevens b0ea1af
updated bulk method to more gracefully handle arguments
ceciliastevens b957bd1
style
ceciliastevens 0c2c372
style and changelog
ceciliastevens 764946d
add Py42UsernameMustBeEmailError to groups.py; consistency in the "up…
ceciliastevens 4d0ff0d
update devices bulk deactivate to use string instead of boolean for "…
ceciliastevens 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
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
from code42cli.main import cli | ||
|
||
|
||
_NAMESPACE = "code42cli.cmds.users" | ||
|
||
TEST_ROLE_RETURN_DATA = { | ||
"data": [{"roleName": "Customer Cloud Admin", "roleId": "1234543"}] | ||
} | ||
|
@@ -50,6 +52,11 @@ def get_all_users_generator(): | |
yield TEST_USERS_RESPONSE | ||
|
||
|
||
@pytest.fixture | ||
def update_user_response(mocker): | ||
return _create_py42_response(mocker, "") | ||
|
||
|
||
@pytest.fixture | ||
def get_available_roles_response(mocker): | ||
return _create_py42_response(mocker, json.dumps(TEST_ROLE_RETURN_DATA)) | ||
|
@@ -75,6 +82,11 @@ def get_available_roles_success(cli_state, get_available_roles_response): | |
cli_state.sdk.users.get_available_roles.return_value = get_available_roles_response | ||
|
||
|
||
@pytest.fixture | ||
def update_user_success(cli_state, update_user_response): | ||
cli_state.sdk.users.update_user.return_value = update_user_response | ||
|
||
|
||
def test_list_when_non_table_format_outputs_expected_columns( | ||
runner, cli_state, get_all_users_success | ||
): | ||
|
@@ -263,3 +275,116 @@ def test_remove_user_role_raises_error_when_username_does_not_exist( | |
result = runner.invoke(cli, command, obj=cli_state) | ||
assert result.exit_code == 1 | ||
assert "User '[email protected]' does not exist." in result.output | ||
|
||
|
||
def test_update_user_calls_update_user_with_correct_parameters_when_only_some_are_passed( | ||
runner, cli_state, update_user_success | ||
): | ||
command = ["users", "update", "--user-id", "12345", "--email", "test_email"] | ||
runner.invoke(cli, command, obj=cli_state) | ||
cli_state.sdk.users.update_user.assert_called_once_with( | ||
"12345", | ||
username=None, | ||
email="test_email", | ||
password=None, | ||
first_name=None, | ||
last_name=None, | ||
notes=None, | ||
archive_size_quota_bytes=None, | ||
) | ||
|
||
|
||
def test_update_user_calls_update_user_with_correct_parameters_when_all_are_passed( | ||
runner, cli_state, update_user_success | ||
): | ||
command = [ | ||
"users", | ||
"update", | ||
"--user-id", | ||
"12345", | ||
"--email", | ||
"test_email", | ||
"--username", | ||
"test_username", | ||
"--password", | ||
"test_password", | ||
"--first-name", | ||
"test_fname", | ||
"--last-name", | ||
"test_lname", | ||
"--notes", | ||
"test notes", | ||
"--archive-size-quota", | ||
"123456", | ||
] | ||
runner.invoke(cli, command, obj=cli_state) | ||
cli_state.sdk.users.update_user.assert_called_once_with( | ||
"12345", | ||
username="test_username", | ||
email="test_email", | ||
password="test_password", | ||
first_name="test_fname", | ||
last_name="test_lname", | ||
notes="test notes", | ||
archive_size_quota_bytes="123456", | ||
) | ||
|
||
|
||
def test_bulk_deactivate_uses_expected_arguments_when_only_some_are_passed( | ||
runner, mocker, cli_state | ||
): | ||
bulk_processor = mocker.patch(f"{_NAMESPACE}.run_bulk_process") | ||
with runner.isolated_filesystem(): | ||
with open("test_bulk_update.csv", "w") as csv: | ||
csv.writelines( | ||
[ | ||
"user_id,username,email,password,first_name,last_name,notes,archive_size_quota\n", | ||
"12345,,test_email,,,,,\n", | ||
] | ||
) | ||
runner.invoke( | ||
cli, ["users", "bulk", "update", "test_bulk_update.csv"], obj=cli_state | ||
) | ||
assert bulk_processor.call_args[0][1] == [ | ||
{ | ||
"user_id": "12345", | ||
"username": "", | ||
"email": "test_email", | ||
"password": "", | ||
"first_name": "", | ||
"last_name": "", | ||
"notes": "", | ||
"archive_size_quota": "", | ||
"updated": "False", | ||
} | ||
] | ||
|
||
|
||
def test_bulk_deactivate_uses_expected_arguments_when_all_are_passed( | ||
runner, mocker, cli_state | ||
): | ||
bulk_processor = mocker.patch(f"{_NAMESPACE}.run_bulk_process") | ||
with runner.isolated_filesystem(): | ||
with open("test_bulk_update.csv", "w") as csv: | ||
csv.writelines( | ||
[ | ||
"user_id,username,email,password,first_name,last_name,notes,archive_size_quota\n", | ||
"12345,test_username,test_email,test_pword,test_fname,test_lname,test notes,4321\n", | ||
] | ||
) | ||
runner.invoke( | ||
cli, ["users", "bulk", "update", "test_bulk_update.csv"], obj=cli_state | ||
) | ||
assert bulk_processor.call_args[0][1] == [ | ||
{ | ||
"user_id": "12345", | ||
"username": "test_username", | ||
"email": "test_email", | ||
"password": "test_pword", | ||
"first_name": "test_fname", | ||
"last_name": "test_lname", | ||
"notes": "test notes", | ||
"archive_size_quota": "4321", | ||
"updated": "False", | ||
} | ||
] |
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.
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.
Can you include all the args here so the test confirms they all get passed to the right spot?
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 wanted to test also that it properly passed
None
where no argument was given (since we don't want the method to accidentally update all unchanged fields to blank values). I've added additional tests to validate that all parameters are passed properly.