-
Notifications
You must be signed in to change notification settings - Fork 13
Add legal hold membership to device reporting #192
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 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b285a68
Legal Hold work to meet Issue 176
maddie-vargo ed72879
Fix to Changelog
maddie-vargo ea4381a
Minor fix to CHANGELOG
maddie-vargo a0ebe57
Added to legal hold user guide
maddie-vargo 077dea1
Adjusting build parameters to bypass 3.5 for this PR
maddie-vargo 03a3814
Merge branch 'master' into iss176
maddie-vargo f174992
Fix low hanging fruit for initial PR review
maddie-vargo 205d559
Move development from legal-hold command to devices command, add new …
maddie-vargo 02d6530
remove whitespaces that are coming through as edits
maddie-vargo e5784cf
fix changes identfied by tox style run
maddie-vargo 9bfcd42
remove duplication in setup.py - file should have no edits
maddie-vargo 2e303de
remove duplication in setup.py - file should have no edits
maddie-vargo 94fe3b9
refactor membership function to use generator and remove NaNs from ou…
maddie-vargo 0b79911
fix tox style run issue
maddie-vargo 1bd1e2f
Fix tox style run x2
maddie-vargo e4725c7
flipping back to using NaN, awaiting PR #245
maddie-vargo 237ea31
Adding --include-total-storage option, which calculates total number …
maddie-vargo 7212fbf
Remove V2 archives from storage calcuation; rename columns
maddie-vargo 2a917bd
fix small change to the incldue/excluded archive types
maddie-vargo 2d1db8c
reword
maddie-vargo 9a0afcb
conflict reconciliation in changelog, part I
maddie-vargo a3dd28f
conflict reconciliation in changelog, part II (repulled from upstream…
maddie-vargo 9677f23
fix style run
maddie-vargo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import json | ||
from datetime import date | ||
|
||
import numpy as np | ||
import pytest | ||
from pandas import DataFrame | ||
from pandas import Series | ||
from pandas._testing import assert_frame_equal | ||
from pandas._testing import assert_series_equal | ||
from py42.exceptions import Py42BadRequestError | ||
from py42.exceptions import Py42ForbiddenError | ||
from py42.exceptions import Py42NotFoundError | ||
|
@@ -11,7 +16,9 @@ | |
|
||
from code42cli import PRODUCT_NAME | ||
from code42cli.cmds.devices import _add_backup_set_settings_to_dataframe | ||
from code42cli.cmds.devices import _add_legal_hold_membership_to_device_dataframe | ||
from code42cli.cmds.devices import _add_usernames_to_device_dataframe | ||
from code42cli.cmds.devices import _break_backup_usage_into_total_storage | ||
from code42cli.cmds.devices import _get_device_dataframe | ||
from code42cli.main import cli | ||
|
||
|
@@ -77,7 +84,19 @@ | |
"836476656572622471","serverName":"cif-sea","serverHostName":"https://cif-sea.crashplan.com", | ||
"isProvider":false,"archiveGuid":"843293524842941560","archiveFormat":"ARCHIVE_V1","activity": | ||
{"connected":false,"backingUp":false,"restoring":false,"timeRemainingInMs":0, | ||
"remainingFiles":0,"remainingBytes":0}}]}}""" | ||
"remainingFiles":0,"remainingBytes":0}},{"targetComputerParentId":null,"targetComputerParentGuid": | ||
null,"targetComputerGuid":"43","targetComputerName":"PROe Cloud, US","targetComputerOsName":null, | ||
"targetComputerType":"SERVER","selectedFiles":1599,"selectedBytes":1529420143,"todoFiles":0, | ||
"todoBytes":0,"archiveBytes":56848550,"billableBytes":1529420143,"sendRateAverage":0, | ||
"completionRateAverage":0,"lastBackup":"2019-12-02T09:34:28.364-06:00","lastCompletedBackup": | ||
"2019-12-02T09:34:28.364-06:00","lastConnected":"2019-12-02T11:02:36.108-06:00","lastMaintenanceDate": | ||
"2021-02-16T07:01:11.697-06:00","lastCompactDate":"2021-02-16T07:01:11.694-06:00","modificationDate": | ||
"2021-02-17T04:57:27.222-06:00","creationDate":"2019-09-26T15:27:38.806-05:00","using":true, | ||
"alertState":16,"alertStates":["CriticalBackupAlert"],"percentComplete":100.0,"storePointId":10989, | ||
"storePointName":"fsa-iad-2","serverId":160024121,"serverGuid":"883282371081742804","serverName": | ||
"fsa-iad","serverHostName":"https://web-fsa-iad.crashplan.com","isProvider":false,"archiveGuid": | ||
"92077743916530001","archiveFormat":"ARCHIVE_V1","activity":{"connected":false,"backingUp":false, | ||
"restoring":false,"timeRemainingInMs":0,"remainingFiles":0,"remainingBytes":0}}]}}""" | ||
TEST_EMPTY_BACKUPUSAGE_RESPONSE = """{"metadata":{"timestamp":"2020-10-13T12:51:28.410Z","params": | ||
{"incBackupUsage":"True","idType":"guid"}},"data":{"computerId":1767,"name":"SNWINTEST1", | ||
"osHostname":"UNKNOWN","guid":"843290890230648046","type":"COMPUTER","status":"Active", | ||
|
@@ -222,6 +241,75 @@ | |
}, | ||
], | ||
} | ||
MATTER_RESPONSE = { | ||
"legalHolds": [ | ||
{ | ||
"legalHoldUid": "123456789", | ||
"name": "Test legal hold matter", | ||
"description": "", | ||
"notes": None, | ||
"holdExtRef": None, | ||
"active": True, | ||
"creationDate": "2020-08-05T10:49:58.353-05:00", | ||
"lastModified": "2020-08-05T10:49:58.358-05:00", | ||
"creator": { | ||
"userUid": "12345", | ||
"username": "[email protected]", | ||
"email": "[email protected]", | ||
"userExtRef": None, | ||
}, | ||
"holdPolicyUid": "966191295667423997", | ||
}, | ||
{ | ||
"legalHoldUid": "987654321", | ||
"name": "Another Matter", | ||
"description": "", | ||
"notes": None, | ||
"holdExtRef": None, | ||
"active": True, | ||
"creationDate": "2020-05-20T15:58:31.375-05:00", | ||
"lastModified": "2020-05-28T13:49:16.098-05:00", | ||
"creator": { | ||
"userUid": "76543", | ||
"username": "[email protected]", | ||
"email": "[email protected]", | ||
"userExtRef": None, | ||
}, | ||
"holdPolicyUid": "946178665645035826", | ||
}, | ||
] | ||
} | ||
ALL_CUSTODIANS_RESPONSE = { | ||
"legalHoldMemberships": [ | ||
{ | ||
"legalHoldMembershipUid": "99999", | ||
"active": True, | ||
"creationDate": "2020-07-16T08:50:23.405Z", | ||
"legalHold": { | ||
"legalHoldUid": "123456789", | ||
"name": "Test legal hold matter", | ||
}, | ||
"user": { | ||
"userUid": "840103986007089121", | ||
"username": "[email protected]", | ||
"email": "[email protected]", | ||
"userExtRef": None, | ||
}, | ||
}, | ||
{ | ||
"legalHoldMembershipUid": "88888", | ||
"active": True, | ||
"creationDate": "2020-07-16T08:50:23.405Z", | ||
"legalHold": {"legalHoldUid": "987654321", "name": "Another Matter"}, | ||
"user": { | ||
"userUid": "840103986007089121", | ||
"username": "[email protected]", | ||
"email": "[email protected]", | ||
"userExtRef": None, | ||
}, | ||
}, | ||
] | ||
} | ||
|
||
|
||
def _create_py42_response(mocker, text): | ||
|
@@ -275,6 +363,14 @@ def users_list_generator(): | |
yield TEST_USERS_LIST_PAGE | ||
|
||
|
||
def matter_list_generator(): | ||
yield MATTER_RESPONSE | ||
|
||
|
||
def custodian_list_generator(): | ||
yield ALL_CUSTODIANS_RESPONSE | ||
|
||
|
||
@pytest.fixture | ||
def backupusage_response(mocker): | ||
return _create_py42_response(mocker, TEST_BACKUPUSAGE_RESPONSE) | ||
|
@@ -357,6 +453,18 @@ def get_all_users_success(cli_state): | |
cli_state.sdk.users.get_all.return_value = users_list_generator() | ||
|
||
|
||
@pytest.fixture | ||
def get_all_matter_success(cli_state): | ||
cli_state.sdk.legalhold.get_all_matters.return_value = matter_list_generator() | ||
|
||
|
||
@pytest.fixture | ||
def get_all_custodian_success(cli_state): | ||
cli_state.sdk.legalhold.get_all_matter_custodians.return_value = ( | ||
custodian_list_generator() | ||
) | ||
|
||
|
||
def test_deactivate_deactivates_device( | ||
runner, cli_state, deactivate_device_success, get_device_by_guid_success | ||
): | ||
|
@@ -559,6 +667,79 @@ def test_add_usernames_to_device_dataframe_adds_usernames_to_dataframe( | |
assert "username" in result.columns | ||
|
||
|
||
def test_add_legal_hold_membership_to_device_dataframe_adds_legal_hold_columns_to_dataframe( | ||
cli_state, get_all_matter_success, get_all_custodian_success | ||
): | ||
testdf = DataFrame.from_records( | ||
[ | ||
{"userUid": "840103986007089121", "status": "Active"}, | ||
{"userUid": "836473273124890369", "status": "Active, Deauthorized"}, | ||
] | ||
) | ||
result = _add_legal_hold_membership_to_device_dataframe(cli_state.sdk, testdf) | ||
assert "legalHoldUid" in result.columns | ||
assert "legalHoldName" in result.columns | ||
|
||
|
||
def test_list_include_legal_hold_membership_pops_legal_hold_if_device_deactivated( | ||
cli_state, get_all_matter_success, get_all_custodian_success | ||
): | ||
testdf = DataFrame.from_records( | ||
[ | ||
{"userUid": "840103986007089121", "status": "Deactivated"}, | ||
{"userUid": "840103986007089121", "status": "Active"}, | ||
] | ||
) | ||
|
||
testdf_result = DataFrame.from_records( | ||
[ | ||
{ | ||
"userUid": "840103986007089121", | ||
"status": "Deactivated", | ||
"legalHoldUid": np.nan, | ||
"legalHoldName": np.nan, | ||
}, | ||
{ | ||
"userUid": "840103986007089121", | ||
"status": "Active", | ||
"legalHoldUid": "123456789,987654321", | ||
"legalHoldName": "Test legal hold matter,Another Matter", | ||
}, | ||
] | ||
) | ||
result = _add_legal_hold_membership_to_device_dataframe(cli_state.sdk, testdf) | ||
|
||
assert_frame_equal(result, testdf_result) | ||
|
||
|
||
def test_list_include_legal_hold_membership_merges_in_and_concats_legal_hold_info( | ||
runner, | ||
cli_state, | ||
get_all_devices_success, | ||
get_all_custodian_success, | ||
get_all_matter_success, | ||
): | ||
result = runner.invoke( | ||
cli, ["devices", "list", "--include-legal-hold-membership"], obj=cli_state | ||
) | ||
|
||
assert "Test legal hold matter,Another Matter" in result.output | ||
assert "123456789,987654321" in result.output | ||
|
||
|
||
def test_break_backup_usage_into_total_storage_correctly_calculates_values(): | ||
test_backupusage_cell = json.loads(TEST_BACKUPUSAGE_RESPONSE)["data"]["backupUsage"] | ||
result = _break_backup_usage_into_total_storage(test_backupusage_cell) | ||
|
||
test_empty_backupusage_cell = json.loads(TEST_EMPTY_BACKUPUSAGE_RESPONSE)["data"][ | ||
"backupUsage" | ||
] | ||
empty_result = _break_backup_usage_into_total_storage(test_empty_backupusage_cell) | ||
|
||
assert_series_equal(result, Series([2, 56968051])) | ||
assert_series_equal(empty_result, Series([0, 0])) | ||
|
||
|
||
def test_last_connected_after_filters_appropriate_results( | ||
cli_state, runner, get_all_devices_success | ||
): | ||
|
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.
Looks like our changelog has gotten messed up? The
#Unreleased
tag should not be there...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.
@unparalleled-js I re-pulled from master. The #Unreleased tag should be at the top, right? Let me know if I should fix it with this PR