Skip to content

Commit 4c06280

Browse files
author
Peter Briggs
authored
Bugfix/improve invalid org uid error (#319)
* Improve error message for `code42 users list` when supplied org UID is invalid * Improve error message for device commands in event of invalid org UID * Remove per-command exception handling, add it to groups.py instead * Remove unused imports * Bump py42 version to get updated error handling, add tests for devices * Update changelog * rollback blank line delete
1 parent 81600c6 commit 4c06280

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
2525
### Fixed
2626

2727
- Bug where `audit-logs search` with `--use-checkpoint` option was causing output formatting problems.
28+
- Improve error message for `code42 users list`, `code42 devices list`, `code42 devices list-backup-sets`
2829

2930
## 1.9.0 - 2021-08-19
3031

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"keyrings.alt==3.2.0",
4141
"ipython>=7.16.1",
4242
"pandas>=1.1.3",
43-
"py42>=1.18.0",
43+
"py42>=1.18.1",
4444
],
4545
extras_require={
4646
"dev": [

src/code42cli/click_ext/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from py42.exceptions import Py42InvalidRuleOperationError
1515
from py42.exceptions import Py42InvalidUsernameError
1616
from py42.exceptions import Py42LegalHoldNotFoundOrPermissionDeniedError
17+
from py42.exceptions import Py42OrgNotFoundError
1718
from py42.exceptions import Py42UpdateClosedCaseError
1819
from py42.exceptions import Py42UserAlreadyAddedError
1920
from py42.exceptions import Py42UsernameMustBeEmailError
@@ -77,6 +78,7 @@ def invoke(self, ctx):
7778
Py42InvalidPasswordError,
7879
Py42InvalidUsernameError,
7980
Py42ActiveLegalHoldError,
81+
Py42OrgNotFoundError,
8082
) as err:
8183
self.logger.log_error(err)
8284
raise Code42CLIError(str(err))

tests/cmds/test_devices.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from py42.exceptions import Py42BadRequestError
1111
from py42.exceptions import Py42ForbiddenError
1212
from py42.exceptions import Py42NotFoundError
13+
from py42.exceptions import Py42OrgNotFoundError
1314
from tests.conftest import create_mock_response
1415

1516
from code42cli.cmds.devices import _add_backup_set_settings_to_dataframe
@@ -725,6 +726,40 @@ def test_list_include_legal_hold_membership_merges_in_and_concats_legal_hold_inf
725726
assert "123456789,987654321" in result.output
726727

727728

729+
def test_list_invalid_org_uid_raises_error(runner, cli_state, custom_error):
730+
custom_error.response.text = "Unable to find org"
731+
invalid_org_uid = "invalid_org_uid"
732+
cli_state.sdk.devices.get_all.side_effect = Py42OrgNotFoundError(
733+
custom_error, invalid_org_uid
734+
)
735+
result = runner.invoke(
736+
cli, ["devices", "list", "--org-uid", invalid_org_uid], obj=cli_state
737+
)
738+
assert result.exit_code == 1
739+
assert (
740+
f"Error: The organization with UID '{invalid_org_uid}' was not found."
741+
in result.output
742+
)
743+
744+
745+
def test_list_backup_sets_invalid_org_uid_raises_error(runner, cli_state, custom_error):
746+
custom_error.response.text = "Unable to find org"
747+
invalid_org_uid = "invalid_org_uid"
748+
cli_state.sdk.devices.get_all.side_effect = Py42OrgNotFoundError(
749+
custom_error, invalid_org_uid
750+
)
751+
result = runner.invoke(
752+
cli,
753+
["devices", "list-backup-sets", "--org-uid", invalid_org_uid],
754+
obj=cli_state,
755+
)
756+
assert result.exit_code == 1
757+
assert (
758+
f"Error: The organization with UID '{invalid_org_uid}' was not found."
759+
in result.output
760+
)
761+
762+
728763
def test_break_backup_usage_into_total_storage_correctly_calculates_values():
729764
test_backupusage_cell = json.loads(TEST_BACKUPUSAGE_RESPONSE)["data"]["backupUsage"]
730765
result = _break_backup_usage_into_total_storage(test_backupusage_cell)

tests/cmds/test_users.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from py42.exceptions import Py42InvalidEmailError
44
from py42.exceptions import Py42InvalidPasswordError
55
from py42.exceptions import Py42InvalidUsernameError
6+
from py42.exceptions import Py42OrgNotFoundError
67
from tests.conftest import create_mock_http_error
78
from tests.conftest import create_mock_response
89

@@ -330,6 +331,22 @@ def test_list_users_when_given_excluding_active_and_inactive_uses_active_equals_
330331
)
331332

332333

334+
def test_list_users_when_given_invalid_org_uid_raises_error(
335+
runner, cli_state, get_available_roles_success, custom_error
336+
):
337+
invalid_org_uid = "invalid_org_uid"
338+
cli_state.sdk.users.get_all.side_effect = Py42OrgNotFoundError(
339+
custom_error, invalid_org_uid
340+
)
341+
result = runner.invoke(
342+
cli, ["users", "list", "--org-uid", invalid_org_uid], obj=cli_state
343+
)
344+
assert (
345+
f"Error: The organization with UID '{invalid_org_uid}' was not found."
346+
in result.output
347+
)
348+
349+
333350
def test_list_legal_hold_flag_reports_none_for_users_not_on_legal_hold(
334351
runner,
335352
cli_state,

0 commit comments

Comments
 (0)