def test_backup_set_excluded_files_returns_expected_values( self, device_settings_with_empty_values, device_settings_with_multiple_values ): # empty file selection device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].excluded_files == [] # multiple path pathset device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].excluded_files == [TEST_PHOTOS_DIR]
def test_backup_set_filename_exclusions_append_produces_expected_values( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty starting filename exclusions device_settings = DeviceSettings(device_settings_with_empty_values) device_settings.backup_sets[0].filename_exclusions.append(PHOTOS_REGEX) assert device_settings["settings"]["serviceBackupConfig"][ "backupConfig"]["backupSets"][0]["backupPaths"]["excludeUser"][ "patternList"]["pattern"] == [{ "@regex": PHOTOS_REGEX }] assert "filename_exclusions" in device_settings.changes assert PHOTOS_REGEX in device_settings.changes["filename_exclusions"] # single starting filename exclusion device_settings = DeviceSettings(device_settings_with_single_values) device_settings.backup_sets[0].filename_exclusions.append( PICTURES_REGEX) assert device_settings["settings"]["serviceBackupConfig"][ "backupConfig"]["backupSets"][0]["backupPaths"]["excludeUser"][ "patternList"]["pattern"] == [ { "@regex": PHOTOS_REGEX }, { "@regex": PICTURES_REGEX }, ] assert "filename_exclusions" in device_settings.changes assert PHOTOS_REGEX in device_settings.changes["filename_exclusions"] assert PICTURES_REGEX in device_settings.changes["filename_exclusions"] # multiple starting filename exclusions NEW_REGEX = ".*/Logs/" device_settings = DeviceSettings(device_settings_with_multiple_values) device_settings.backup_sets[0].filename_exclusions.append(NEW_REGEX) assert device_settings["settings"]["serviceBackupConfig"][ "backupConfig"]["backupSets"][0]["backupPaths"]["excludeUser"][ "patternList"]["pattern"] == [ { "@regex": PHOTOS_REGEX }, { "@regex": PICTURES_REGEX }, { "@regex": NEW_REGEX }, ]
def test_backup_set_filename_exclusions_returns_expected_list_results( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty exclude list device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].filename_exclusions == [] # single exclude device_settings = DeviceSettings(device_settings_with_single_values) assert device_settings.backup_sets[0].filename_exclusions == [PHOTOS_REGEX] # multiple excludes device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].filename_exclusions == [ PHOTOS_REGEX, PICTURES_REGEX, ]
def test_backup_set_included_files_returns_expected_values( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty pathset device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].included_files == [] # single path pathset device_settings = DeviceSettings(device_settings_with_single_values) assert device_settings.backup_sets[0].included_files == [TEST_HOME_DIR] # multiple path pathset device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].included_files == [ TEST_HOME_DIR, TEST_EXTERNAL_DOCUMENTS_DIR, ]
def get_settings(self, guid): """Gets setting data for a device and returns a `DeviceSettings` object for the target device. Args: guid (int,str): The globally unique identifier of the device. Returns: :class:`py42.clients.settings.device_settings.DeviceSettings`: A class to help manage device settings. """ settings = self.get_by_guid(guid, incSettings=True) return DeviceSettings(settings.data)
def test_backup_set_when_set_locked_allows_destination_modifications( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) destination_guid_to_add = list(device_settings.available_destinations)[2] destination_guid_to_remove = list(device_settings.available_destinations)[0] device_settings.backup_sets[0].add_destination(destination_guid_to_add) device_settings.backup_sets[0].remove_destination(destination_guid_to_remove) assert destination_guid_to_add in device_settings.backup_sets[0].destinations assert ( destination_guid_to_remove not in device_settings.backup_sets[0].destinations )
def test_backup_set_when_set_locked_non_destination_attributes_raise_attr_error_when_set( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) with pytest.raises(AttributeError): device_settings.backup_sets[0].included_files.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].included_files = ["test"] with pytest.raises(AttributeError): device_settings.backup_sets[0].excluded_files.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].excluded_files = ["test"] with pytest.raises(AttributeError): device_settings.backup_sets[0].filename_exclusions.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].filename_exclusions = ["test"]
def test_backup_set_when_locked_returns_expected_property_value( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) assert device_settings.backup_sets[0].locked
class TestDeviceSettingsBackupSets(object): device_settings = DeviceSettings(deepcopy(DEVICE_DICT_W_SETTINGS)) def test_backup_set_destinations_property_returns_expected_value(self,): expected_destinations = {"4200": "Dest42 <LOCKED>", "4300": "Dest43"} assert self.device_settings.backup_sets[0].destinations == expected_destinations def test_backup_set_add_destination_when_destination_available(self,): self.device_settings.backup_sets[0].add_destination(4400) expected_destinations_property = { "4200": "Dest42 <LOCKED>", "4300": "Dest43", "4400": "Dest44", } expected_destinations_dict = [ {"@id": TEST_DESTINATION_GUID_1, "@locked": "true"}, {"@id": TEST_DESTINATION_GUID_2}, {"@id": TEST_DESTINATION_GUID_3}, ] assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) assert ( self.device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["destinations"] == expected_destinations_dict ) def test_backup_set_add_destination_when_destination_not_available_raises(self,): expected_destinations_property = { "4200": "Dest42 <LOCKED>", "4300": "Dest43", "4400": "Dest44", } with pytest.raises(Py42Error): self.device_settings.backup_sets[0].add_destination(404) assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) def test_backup_set_remove_destination_when_destination_available(self,): expected_destinations_property = { "4200": "Dest42 <LOCKED>", "4300": "Dest43", } expected_destinations_dict = [ {"@id": TEST_DESTINATION_GUID_1, "@locked": "true"}, {"@id": TEST_DESTINATION_GUID_2}, ] self.device_settings.backup_sets[0].remove_destination(4400) assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) assert ( self.device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["destinations"] == expected_destinations_dict ) def test_backup_set_remove_destination_when_destination_not_available_raises(self,): expected_destinations_property = { "4200": "Dest42 <LOCKED>", "4300": "Dest43", } with pytest.raises(Py42Error): self.device_settings.backup_sets[0].remove_destination(404) assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) def test_backup_set_lock_destination(self): expected_destinations_property = { "4200": "Dest42 <LOCKED>", "4300": "Dest43 <LOCKED>", } expected_destinations_dict = [ {"@id": TEST_DESTINATION_GUID_1, "@locked": "true"}, {"@id": TEST_DESTINATION_GUID_2, "@locked": "true"}, ] self.device_settings.backup_sets[0].lock_destination(4300) assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) assert ( self.device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["destinations"] == expected_destinations_dict ) def test_backup_set_unlock_destination(self): expected_destinations_property = { "4200": "Dest42", "4300": "Dest43 <LOCKED>", } expected_destinations_dict = [ {"@id": TEST_DESTINATION_GUID_1}, {"@id": TEST_DESTINATION_GUID_2, "@locked": "true"}, ] self.device_settings.backup_sets[0].unlock_destination(4200) assert ( self.device_settings.backup_sets[0].destinations == expected_destinations_property ) assert ( self.device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["destinations"] == expected_destinations_dict ) def test_backup_set_included_files_returns_expected_values( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty pathset device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].included_files == [] # single path pathset device_settings = DeviceSettings(device_settings_with_single_values) assert device_settings.backup_sets[0].included_files == [TEST_HOME_DIR] # multiple path pathset device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].included_files == [ TEST_HOME_DIR, TEST_EXTERNAL_DOCUMENTS_DIR, ] def test_backup_set_included_files_append_produces_expected_pathset_value_and_registers_change( self, ): expected_path_list = [ {"@include": TEST_HOME_DIR, "@und": "false"}, {"@include": TEST_EXTERNAL_DOCUMENTS_DIR, "@und": "false"}, {"@include": TEST_ADDED_PATH, "@und": "false"}, {"@exclude": TEST_PHOTOS_DIR, "@und": "false"}, ] self.device_settings.backup_sets[0].included_files.append(TEST_ADDED_PATH) actual_path_list = self.device_settings["settings"]["serviceBackupConfig"][ "backupConfig" ]["backupSets"][0]["backupPaths"]["pathset"]["paths"]["path"] assert actual_path_list == expected_path_list assert "included_files" in self.device_settings.changes def test_backup_set_included_files_remove_produces_expected_pathset_value(self): expected_path_list = [ {"@include": TEST_HOME_DIR, "@und": "false"}, {"@include": TEST_ADDED_PATH, "@und": "false"}, {"@exclude": TEST_PHOTOS_DIR, "@und": "false"}, ] self.device_settings.backup_sets[0].included_files.remove( TEST_EXTERNAL_DOCUMENTS_DIR ) actual_path_list = self.device_settings["settings"]["serviceBackupConfig"][ "backupConfig" ]["backupSets"][0]["backupPaths"]["pathset"]["paths"]["path"] assert actual_path_list == expected_path_list assert "included_files" in self.device_settings.changes def test_backup_set_excluded_files_returns_expected_values( self, device_settings_with_empty_values, device_settings_with_multiple_values ): # empty file selection device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].excluded_files == [] # multiple path pathset device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].excluded_files == [TEST_PHOTOS_DIR] def test_backup_set_excluded_files_append_produces_expected_pathset_value_and_registers_change( self, ): self.device_settings.backup_sets[0].excluded_files.append( TEST_ADDED_EXCLUDED_PATH ) expected_path_list = [ {"@include": TEST_HOME_DIR, "@und": "false"}, {"@include": TEST_ADDED_PATH, "@und": "false"}, {"@exclude": TEST_PHOTOS_DIR, "@und": "false"}, {"@exclude": TEST_ADDED_EXCLUDED_PATH, "@und": "false"}, ] actual_path_list = self.device_settings["settings"]["serviceBackupConfig"][ "backupConfig" ]["backupSets"][0]["backupPaths"]["pathset"]["paths"]["path"] assert actual_path_list == expected_path_list assert "excluded_files" in self.device_settings.changes def test_backup_set_excluded_files_remove_produces_expected_pathset_value(self): expected_path_list = [ {"@include": TEST_HOME_DIR, "@und": "false"}, {"@include": TEST_ADDED_PATH, "@und": "false"}, {"@exclude": TEST_ADDED_EXCLUDED_PATH, "@und": "false"}, ] self.device_settings.backup_sets[0].excluded_files.remove(TEST_PHOTOS_DIR) actual_path_list = self.device_settings["settings"]["serviceBackupConfig"][ "backupConfig" ]["backupSets"][0]["backupPaths"]["pathset"]["paths"]["path"] assert actual_path_list == expected_path_list assert "excluded_files" in self.device_settings.changes def test_backup_set_filename_exclusions_returns_expected_list_results( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty exclude list device_settings = DeviceSettings(device_settings_with_empty_values) assert device_settings.backup_sets[0].filename_exclusions == [] # single exclude device_settings = DeviceSettings(device_settings_with_single_values) assert device_settings.backup_sets[0].filename_exclusions == [PHOTOS_REGEX] # multiple excludes device_settings = DeviceSettings(device_settings_with_multiple_values) assert device_settings.backup_sets[0].filename_exclusions == [ PHOTOS_REGEX, PICTURES_REGEX, ] def test_backup_set_filename_exclusions_append_produces_expected_values( self, device_settings_with_empty_values, device_settings_with_single_values, device_settings_with_multiple_values, ): # empty starting filename exclusions device_settings = DeviceSettings(device_settings_with_empty_values) device_settings.backup_sets[0].filename_exclusions.append(PHOTOS_REGEX) assert device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["backupPaths"]["excludeUser"]["patternList"]["pattern"] == [ {"@regex": PHOTOS_REGEX} ] assert "filename_exclusions" in device_settings.changes assert PHOTOS_REGEX in device_settings.changes["filename_exclusions"] # single starting filename exclusion device_settings = DeviceSettings(device_settings_with_single_values) device_settings.backup_sets[0].filename_exclusions.append(PICTURES_REGEX) assert device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["backupPaths"]["excludeUser"]["patternList"]["pattern"] == [ {"@regex": PHOTOS_REGEX}, {"@regex": PICTURES_REGEX}, ] assert "filename_exclusions" in device_settings.changes assert PHOTOS_REGEX in device_settings.changes["filename_exclusions"] assert PICTURES_REGEX in device_settings.changes["filename_exclusions"] # multiple starting filename exclusions NEW_REGEX = ".*/Logs/" device_settings = DeviceSettings(device_settings_with_multiple_values) device_settings.backup_sets[0].filename_exclusions.append(NEW_REGEX) assert device_settings["settings"]["serviceBackupConfig"]["backupConfig"][ "backupSets" ][0]["backupPaths"]["excludeUser"]["patternList"]["pattern"] == [ {"@regex": PHOTOS_REGEX}, {"@regex": PICTURES_REGEX}, {"@regex": NEW_REGEX}, ] def test_backup_set_when_locked_returns_expected_property_value( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) assert device_settings.backup_sets[0].locked def test_backup_set_when_set_locked_non_destination_attributes_raise_attr_error_when_set( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) with pytest.raises(AttributeError): device_settings.backup_sets[0].included_files.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].included_files = ["test"] with pytest.raises(AttributeError): device_settings.backup_sets[0].excluded_files.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].excluded_files = ["test"] with pytest.raises(AttributeError): device_settings.backup_sets[0].filename_exclusions.append("test") with pytest.raises(AttributeError): device_settings.backup_sets[0].filename_exclusions = ["test"] def test_backup_set_when_set_locked_allows_destination_modifications( self, device_settings_with_locked_backup_set ): device_settings = DeviceSettings(device_settings_with_locked_backup_set) destination_guid_to_add = list(device_settings.available_destinations)[2] destination_guid_to_remove = list(device_settings.available_destinations)[0] device_settings.backup_sets[0].add_destination(destination_guid_to_add) device_settings.backup_sets[0].remove_destination(destination_guid_to_remove) assert destination_guid_to_add in device_settings.backup_sets[0].destinations assert ( destination_guid_to_remove not in device_settings.backup_sets[0].destinations )
class TestDeviceSettings(object): device_settings = DeviceSettings(DEVICE_DICT_W_SETTINGS) @pytest.mark.parametrize( "param", [ ("computer_id", TEST_COMPUTER_ID), ("guid", TEST_COMPUTER_GUID), ("user_id", TEST_USER_ID), ("org_id", TEST_COMPUTER_ORG_ID), ("version", TEST_DEVICE_VERSION), ( "available_destinations", { TEST_DESTINATION_GUID_1: TEST_DESTINATION_NAME_1, TEST_DESTINATION_GUID_2: TEST_DESTINATION_NAME_2, TEST_DESTINATION_GUID_3: TEST_DESTINATION_NAME_3, }, ), ], ) def test_device_settings_properties_return_expected_value_and_cannot_be_changed( self, param ): name, expected_value = param assert getattr(self.device_settings, name) == expected_value with pytest.raises(AttributeError): setattr(self.device_settings, name, expected_value) @pytest.mark.parametrize( "param", [ ("notes", None), ("name", TEST_COMPUTER_NAME), ("external_reference", None), ("warning_email_enabled", True), ("critical_email_enabled", True), ("warning_alert_days", 5), ("critical_alert_days", 10), ("backup_status_email_enabled", False), ("backup_status_email_frequency_days", 7), ], ) def test_device_settings_get_mutable_properties_return_expected_values(self, param): name, expected_value = param assert getattr(self.device_settings, name) == expected_value @pytest.mark.parametrize( "param", [ param( name="notes", new_val="a device note.", expected_stored_val="a device note.", dict_location=["notes"], ), param( name="name", new_val="Settings Test Device Updated", expected_stored_val="Settings Test Device Updated", dict_location=["name"], ), param( name="external_reference", new_val="reference#id", expected_stored_val="reference#id", dict_location=["computerExtRef"], ), param( name="warning_email_enabled", new_val=False, expected_stored_val="false", dict_location=[ "settings", "serviceBackupConfig", "warningEmailEnabled", ], ), param( name="critical_email_enabled", new_val=False, expected_stored_val="false", dict_location=["settings", "serviceBackupConfig", "severeEmailEnabled"], ), param( name="warning_alert_days", new_val=10, expected_stored_val="14400", dict_location=[ "settings", "serviceBackupConfig", "minutesUntilWarning", ], ), param( name="critical_alert_days", new_val=100, expected_stored_val="144000", dict_location=["settings", "serviceBackupConfig", "minutesUntilSevere"], ), ], ) def test_device_settings_setting_mutable_property_updates_dict_correctly_and_registers_changes( self, param, ): setattr(self.device_settings, param.name, param.new_val) assert ( get_val(self.device_settings.data, param.dict_location) == param.expected_stored_val ) assert param.name in self.device_settings.changes @pytest.mark.parametrize( "param", [ param( name="backup_status_email_frequency_days", new_val=9, expected_stored_val={"#text": "12960", "@locked": "true"}, dict_location=[ "settings", "serviceBackupConfig", "backupStatusEmailFreqInMinutes", ], ), param( name="backup_status_email_enabled", new_val=True, expected_stored_val={"#text": "true", "@locked": "true"}, dict_location=[ "settings", "serviceBackupConfig", "backupStatusEmailEnabled", ], ), ], ) def test_device_settings_setting_mutable_property_updates_dict_correctly_and_registers_changes_when_setting_locked( self, param, ): setattr(self.device_settings, param.name, param.new_val) assert ( get_val(self.device_settings.data, param.dict_location) == param.expected_stored_val ) assert param.name in self.device_settings.changes
def test_backup_set_when_device_on_legal_hold_hides_legal_hold_set( self, device_settings_legal_hold): device_settings = DeviceSettings(device_settings_legal_hold) assert len(device_settings.backup_sets) == 1 for bs in device_settings.backup_sets: assert bs["@id"] != TEST_LEGAL_HOLD_BACKUP_SET_ID