From e22d7e4de4ae3d044a720d55a1e853f9221fd0ea Mon Sep 17 00:00:00 2001 From: Aaron Shaw Date: Tue, 27 Jun 2023 18:47:09 +0100 Subject: [PATCH] sbc: add test cases and fix nebra_fleet check Closes: #272 --- hm_pyhelper/sbc.py | 2 +- hm_pyhelper/tests/test_sbc.py | 27 +++++++++++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 hm_pyhelper/tests/test_sbc.py diff --git a/hm_pyhelper/sbc.py b/hm_pyhelper/sbc.py index c6669d2..abd832c 100644 --- a/hm_pyhelper/sbc.py +++ b/hm_pyhelper/sbc.py @@ -207,7 +207,7 @@ def is_nebra_fleet() -> bool: api_url = os.environ.get('BALENA_API_URL') fleet_id = int(os.environ.get('BALENA_APP_ID')) - if api_url is not NEBRA_API_URL or (fleet_id not in COMMERCIAL_FLEETS and fleet_id not in NON_COMMERCIAL_FLEETS): + if (api_url != NEBRA_API_URL) or (fleet_id not in COMMERCIAL_FLEETS and fleet_id not in NON_COMMERCIAL_FLEETS): return False return True diff --git a/hm_pyhelper/tests/test_sbc.py b/hm_pyhelper/tests/test_sbc.py new file mode 100644 index 0000000..7726308 --- /dev/null +++ b/hm_pyhelper/tests/test_sbc.py @@ -0,0 +1,27 @@ +import unittest + +from unittest.mock import patch +from hm_pyhelper.sbc import is_commercial_fleet, is_nebra_fleet + + +class TestSBC(unittest.TestCase): + + @patch.dict('os.environ', {"BALENA_API_URL": "https://api.cloud.nebra.com"}) + @patch.dict('os.environ', {"BALENA_APP_ID": "55"}) + def test_is_nebra_fleet_true(self): + self.assertTrue(is_nebra_fleet()) + + @patch.dict('os.environ', {"BALENA_API_URL": "https://test.com"}) + @patch.dict('os.environ', {"BALENA_APP_ID": "5500"}) + def test_is_nebra_fleet_false(self): + self.assertFalse(is_nebra_fleet()) + + @patch.dict('os.environ', {"BALENA_APP_NAME": "test-c"}) + @patch.dict('os.environ', {"BALENA_APP_ID": "87"}) + def test_is_commercial_fleet_true(self): + self.assertTrue(is_commercial_fleet()) + + @patch.dict('os.environ', {"BALENA_APP_NAME": "test"}) + @patch.dict('os.environ', {"BALENA_APP_ID": "8700"}) + def test_is_commercial_fleet_false(self): + self.assertFalse(is_commercial_fleet()) diff --git a/pyproject.toml b/pyproject.toml index 33f0af4..2b2a861 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "hm_pyhelper" -version = "0.14.18" +version = "0.14.19" description = "Helium Python Helper" authors = ["Nebra Ltd "] readme = "README.md"