diff --git a/smsdk/ma_session.py b/smsdk/ma_session.py index 6efdbe7..1c3546d 100644 --- a/smsdk/ma_session.py +++ b/smsdk/ma_session.py @@ -181,7 +181,7 @@ def _get_records_v1( url_params["db_mode"] = db_mode # print(f'Pulling up to {this_loop_limit} records ({remaining_limit} remain)') - + response = None try: response = getattr(self.session, method.lower())( endpoint, json=url_params @@ -191,7 +191,7 @@ def _get_records_v1( f"Error connecting to {endpoint}. Check your tenant name" ) - if response and response.text: + if response is not None and response.text: if response.status_code not in [200, 201]: raise ValueError(format(response.text)) try: diff --git a/tests/kpi/test_kpi.py b/tests/kpi/test_kpi.py index d39ccd4..fa1e973 100644 --- a/tests/kpi/test_kpi.py +++ b/tests/kpi/test_kpi.py @@ -4,6 +4,7 @@ from tests.kpi.kpi_data import AVALIBLE_KPI_JSON, KPI_DATA_VIZ_JSON from smsdk.smsdk_entities.kpi.kpi import KPI from mock import mock_open, MagicMock, patch +import unittest @patch("smsdk.ma_session.Session") @@ -112,6 +113,20 @@ def test_kpi_for_asset_display_name(get_client): assert df1 == df2 +def test_kpi_for_asset_incorrect_machine(get_client): + kpis = ["performance", "oee", "quality", "availability"] + # Query against machine that does not exist in the system. + query = { + "asset_selection": { + "machine_type": ["PickAndPlace"], + "machine_source": ["incorrect"], + } + } + # Expecting a value error while tring to get KPIs for incorrect machine. + with unittest.TestCase().assertRaises(ValueError) as context: + df1 = get_client.get_kpis_for_asset(**query) + + def test_get_kpi_data_viz(get_client): machine_sources = ["Nagoya - Pick and Place 6"] kpis = ["quality"]