Skip to content

Commit

Permalink
Upgrade device (#395)
Browse files Browse the repository at this point in the history
* added devices.upgrade method

* changelog

* simplified handling of upgrade uri in test_upgrade_calls_upgrade_with_uri_and_params

Co-authored-by: Tim Abramson <tim.abramson@code42.com>
  • Loading branch information
ceciliastevens and timabrmsn committed Apr 29, 2022
1 parent 097c22e commit c237412
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
## Unreleased

### Added

- `Watchlists` and `UserRiskProfile` clients
- These features replace the `DetectionLists` client as well as its `DepartingEmployee` and `HighRiskEmployee` services. All related classes and methods have been marked as deprecated and will raise deprecation warnings.
- `Watchlists` client includes the following methods:
Expand All @@ -34,6 +35,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
- `add_cloud_aliases()`
- `delete_cloud_aliases()`

- `sdk.devices.upgrade()` to instruct the Code42 cloud to upgrade an individual device to the latest available version.

### Fixed

- Bug where attempting to restore from an empty archive would throw a confusing `TypeError`, we now raise appropriate `Py42ArchiveFileNotFoundError`.
Expand Down
12 changes: 12 additions & 0 deletions src/py42/services/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,15 @@ def update_settings(self, device_settings):
new_config_date_ms = str(int(time() * 1000))
device_settings["settings"]["configDateMs"] = new_config_date_ms
return self._connection.put(uri, json=device_settings)

def upgrade(self, guid):
"""Instructs a device to upgrade to the latest available version.
Args:
guid (str): The globally unique identifier of the device.
Returns:
:class:`py42.response.Py42Response`: A response containing the result of the upgrade request.
"""
uri = "/api/v4/device-upgrade/upgrade-device"
return self._connection.post(uri, json={"deviceGuid": guid})
11 changes: 11 additions & 0 deletions tests/services/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from py42.services.devices import DeviceService

COMPUTER_URI = "/api/v1/Computer"
UPGRADE_URI = "/api/v4/device-upgrade/upgrade-device"

DEFAULT_GET_DEVICES_PARAMS = {
"active": None,
Expand Down Expand Up @@ -167,6 +168,16 @@ def test_get_page_when_org_not_found_raises_expected_error(
assert "The organization with UID 'TestOrgUid' was not found." in str(err.value)
assert err.value.org_uid == "TestOrgUid"


def test_upgrade_calls_upgrade_with_uri_and_params(
self, mock_connection, successful_response
):
mock_connection.get.return_value = successful_response
service = DeviceService(mock_connection)
service.upgrade("DEVICE_ID")
expected_params = {"deviceGuid": "DEVICE_ID"}
mock_connection.post.assert_called_once_with(UPGRADE_URI, json=expected_params)

def test_get_settings_returns_crashplan_settings_when_crashplan_service(
self, mocker, mock_connection
):
Expand Down

0 comments on commit c237412

Please sign in to comment.