def test_update_configuration_enable(self): """Validate retrieving the ASUP configuration""" self._set_args(dict(asup='enabled')) expected = dict() initial = dict(asupCapable=False, asupEnabled=False, onDemandEnabled=False, remoteDiagsEnabled=False, schedule=dict(daysOfWeek=[], dailyMinTime=0, weeklyMinTime=0, dailyMaxTime=24, weeklyMaxTime=24)) asup = Asup() with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req: with mock.patch.object(asup, 'get_configuration', return_value=initial): updated = asup.update_configuration() self.assertTrue(updated) self.assertTrue(req.called) # Ensure it was called with the right arguments called_with = req.call_args body = json.loads(called_with[1]['data']) self.assertTrue(body['asupEnabled']) self.assertTrue(body['onDemandEnabled']) self.assertTrue(body['remoteDiagsEnabled'])
def test_update_configuration_request_exception(self): """Validate exception handling when request throws an exception.""" config_response = dict(asupEnabled=True, onDemandEnabled=True, remoteDiagsEnabled=True, schedule=dict(daysOfWeek=[], dailyMinTime=0, weeklyMinTime=0, dailyMaxTime=24, weeklyMaxTime=24)) self._set_args(dict(state="enabled")) asup = Asup() with self.assertRaises(Exception): with mock.patch.object(asup, 'get_configuration', return_value=config_response): with mock.patch(self.REQ_FUNC, side_effect=Exception): asup.update_configuration()
def test_update_configuration(self): """Validate retrieving the ASUP configuration""" self._set_args(dict(asup='enabled')) expected = dict() initial = dict(asupCapable=True, asupEnabled=True, onDemandEnabled=False, remoteDiagsEnabled=False, schedule=dict(daysOfWeek=[], dailyMinTime=0, weeklyMinTime=0, dailyMaxTime=24, weeklyMaxTime=24)) asup = Asup() with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req: with mock.patch.object(asup, 'get_configuration', return_value=initial): updated = asup.update_configuration() self.assertTrue(req.called) self.assertTrue(updated)