def test_load_config_ex(self, loader_mock=None, get_mock=None): """Test load config with exception.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') with self.assertRaises(AssertionError): EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api, None)
def test_load_config_api_ko(self, loader_mock=None, get_mock=None): """Test load config with API unavailable.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["available"], False)
def test_load_config_ex(self, loader_mock=None, get_mock=None): """Test load config with exception.""" for key in ['NODE_NAME', 'ENERGY_RECORDER_API_URL']: os.environ[key] = '' with self.assertRaises(AssertionError): EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api, None)
def test_load_config_no_creds(self, loader_mock=None, pod_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"], "http://pod-uri:8888/recorders/environment/MOCK_POD")
def test_load_config_api_ko(self, loader_mock=None, get_mock=None): """Test load config with API unavailable.""" os.environ['NODE_NAME'] = 'MOCK_POD' self._set_env_creds() EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["available"], False)
def test_load_config_no_creds(self, loader_mock=None, get_mock=None): """Test load config without creds.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], None) self.assertEquals( EnergyRecorder.energy_recorder_api["uri"], "http://pod-uri:8888/recorders/environment/MOCK_POD")
def test_load_config(self, loader_mock=None, pod_mock=None): """Test load config.""" EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], ("user", "password")) self.assertEquals( EnergyRecorder.energy_recorder_api["uri"], "http://pod-uri:8888/recorders/environment/MOCK_POD")
def test_load_config(self, loader_mock=None, get_mock=None): """Test load config.""" os.environ['NODE_NAME'] = 'MOCK_POD' self._set_env_creds() EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], ("user", "password")) self.assertEquals( EnergyRecorder.energy_recorder_api["uri"], "http://pod-uri:8888/recorders/environment/MOCK_POD")
def test_get_current_scenario(self, loader_mock=None, pod_mock=None, get_mock=None): """Test get_current_scenario.""" self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is not None)
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)
def test_stop(self, delete_mock=None): """EnergyRecorder.stop method (regular case).""" self.test_load_config() self.assertTrue(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_error(self, post_mock=None): """EnergyRecorder.start method (error in method).""" self.test_load_config() self.assertFalse(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)
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)
def test_start(self, post_mock=None, get_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(self, post_mock=None): """EnergyRecorder.set_step method (regular case).""" self.test_load_config() self.assertTrue(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_TIMOUT)
def test_current_scenario_exception(self, get_mock=None): """Test get current scenario with exception.""" scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is None)
def test_current_scenario_api_error(self, get_mock=None): """Test get current scenario with API error.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is None)
def test_current_scenario_not_found(self, get_mock=None): """Test get current scenario not existing.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is None)
def test_get_current_scenario(self, loader_mock=None, get_mock=None): """Test get_current_scenario.""" CONST.__setattr__('NODE_NAME', 'MOCK_POD') self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is not None)
def test_load_config_ex(self, loader_mock=None, pod_mock=None): """Test load config with exception.""" with self.assertRaises(AssertionError): EnergyRecorder.energy_recorder_api = None EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api, None)
def test_set_step_connection_error(self, conf_loader_mock=None): """EnergyRecorder.start test with exception during execution.""" step_status = EnergyRecorder.set_step(STEP_NAME) self.assertFalse(step_status)
def test_start_exception(self, conf_loader_mock=None): """EnergyRecorder.start test with exception during execution.""" start_status = EnergyRecorder.start(CASE_NAME) self.assertFalse(start_status)
def test_current_scenario_api_error(self, get_mock=None): """Test get current scenario with API error.""" os.environ['NODE_NAME'] = 'MOCK_POD' self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is None)
def test_current_scenario_not_found(self, get_mock=None): """Test get current scenario not existing.""" os.environ['NODE_NAME'] = 'MOCK_POD' self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is None)
def test_get_current_scenario(self, loader_mock=None, get_mock=None): """Test get_current_scenario.""" os.environ['NODE_NAME'] = 'MOCK_POD' self.test_load_config() scenario = EnergyRecorder.get_current_scenario() self.assertTrue(scenario is not None)