def test_load_config_no_creds(self, yaml_mock=None, open_mock=None, get_mock=None): """Test load config without creds.""" EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], None) self.assertEquals( EnergyRecorder.energy_recorder_api["uri"], "mock_url/recorders/environment/MOCK_ENV" ) self.assertTrue(EnergyRecorder.energy_recorder_api["available"])
def test_load_config(self, yaml_mock=None, open_mock=None, get_mock=None): """Test load config.""" EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals( EnergyRecorder.energy_recorder_api["auth"], ("mock_user", "mock_password") ) self.assertEquals( EnergyRecorder.energy_recorder_api["uri"], "mock_url/recorders/environment/MOCK_ENV" ) self.assertTrue(EnergyRecorder.energy_recorder_api["available"])
def test_stop_error(self, delete_mock=None): """EnergyRecorder.stop method (method error).""" self.test_load_config() self.assertFalse(EnergyRecorder.stop()) delete_mock.assert_called_once_with( EnergyRecorder.energy_recorder_api["uri"], auth=EnergyRecorder.energy_recorder_api["auth"], headers=self.request_headers, timeout=EnergyRecorder.CONNECTION_TIMEOUT )
def test_start(self, post_mock=None): """EnergyRecorder.start method (regular case).""" self.test_load_config() self.assertTrue(EnergyRecorder.start(self.case_name)) post_mock.assert_called_once_with( EnergyRecorder.energy_recorder_api["uri"], auth=EnergyRecorder.energy_recorder_api["auth"], data=mock.ANY, headers=self.request_headers, timeout=EnergyRecorder.CONNECTION_TIMEOUT )
def test_set_step_error(self, post_mock=None): """EnergyRecorder.set_step method (method error).""" self.test_load_config() self.assertFalse(EnergyRecorder.set_step(STEP_NAME)) post_mock.assert_called_once_with( EnergyRecorder.energy_recorder_api["uri"] + "/step", auth=EnergyRecorder.energy_recorder_api["auth"], data=mock.ANY, headers=self.request_headers, timeout=EnergyRecorder.CONNECTION_TIMEOUT )
def test_get_current_scenario(self, get_mock=None, yaml_mock=None, open_mock=None): """Test get_current_scenario.""" self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is not None)
def test_load_config_api_ko(self, loader_mock=None, pod_mock=None, get_mock=None): """Test load config with API unavailable.""" EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertFalse(EnergyRecorder.energy_recorder_api["available"])
def test_load_config_ex(self, yaml_mock=None, open_mock=None): """Test load config with exception.""" with self.assertRaises(Exception): EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api, None)