Skip to content

List users #270

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 9 commits into from
Apr 22, 2021
Merged

List users #270

merged 9 commits into from
Apr 22, 2021

Conversation

ceciliastevens
Copy link
Contributor

Description of Change

This adds a "users list" command and parameters to filter on active status, org Uid, and role name.

This partially addresses #259, but more work will follow in additional PRs.

Testing Procedure

code42 users list
code42 users list --role-name "Customer Cloud Admin"
code42 users list --org-uid "12345"
code42 users list --inactive
code42 users list --active

PR Checklist

  • Add unit tests to verify this change
  • Add an entry to CHANGELOG.md describing this change
  • Add docstrings for any new public parameters / methods / classes

@github-actions
Copy link

github-actions bot commented Apr 21, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️

assert isinstance(result, DataFrame)


def test_get_users_dataframe_calls_get_all_users_with_correct_parameters(
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't typically test the implementation details of commands (the protected methods).
Can we change these tests such that their entry point occurs from command execution?

Copy link
Contributor Author

@ceciliastevens ceciliastevens Apr 21, 2021

Choose a reason for hiding this comment

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

Updated! Let me know if you'd like any further changes, but it now runs "users list" and works from that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are also a couple other tests (test_get_role_id_returns_appropriate_role_id and test_get_users_dataframe_returns_dataframe) that test the details of internal methods, should those be updated as well? I think it might be difficult to test some of those things from command execution as they aren't directly exposed in the result.

Copy link
Contributor

@antazoey antazoey Apr 22, 2021

Choose a reason for hiding this comment

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

Yes, that would be nice.

Tests like test_get_users_dataframe_returns_dataframe are not needed. The fact that we use dataframes under the hood shouldn't matter.

For testing role_ids logic, the test would look something this

def test_list_users_includes_expected_role_ids()

And then you would verify that the role IDs from the mock responses have shown up in the output

assert "12" in result.output

(Mayne make the role ID more specific, like 1230123 or something)

Additionally, I would really appreciate some tests around the logic that figures out active.

def test_list_users_when_given_inactive_uses_active_equals_false()

def test_list_users_when_given_active_and_inactive_raises_error()

def test_list_users_when_given_excluding_active_and_inactive_uses_active_equals_none()

^ These tests can just verify that py42 was called correctly if we are unable to verify these states via the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the additional tests for the active logic. I updated the role Id test as well, but roleId isn't actually included in the output, it's just passed as a parameter to the users.get_all() method that gets the users (where it's used as a filter). So I ended up just testing that the users.get_all() call has the appropriate parameter.

required=False,
type=str,
default=None,
help="Limit users to only those in the organization you specify. ",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this include child orgs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so. I'll update the text.

def _get_role_id(sdk, role_name):
try:
roles_dataframe = DataFrame.from_records(sdk.users.get_available_roles().data)
return str(
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 70 - 73 is quite complex. Can we break this into multiple statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did break this out, and also found a way to do it using DataFrame.at[] instead of DataFrame.loc[]

assert "Error: --inactive can't be used with: --active" in result.output


def test_list_users_when_given_excluding_active_and_inactive_uses_active_equals_none(
Copy link
Contributor

Choose a reason for hiding this comment

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

technically don't need the word _given_ in the test signature (not a blocker though)

@antazoey antazoey merged commit e26da51 into code42:master Apr 22, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2021
@ceciliastevens ceciliastevens deleted the list-users branch April 22, 2021 18:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants