Skip to content

Commit

Permalink
Merge pull request #273 from NebraLtd/shawaj/testsbc
Browse files Browse the repository at this point in the history
sbc: add test cases
  • Loading branch information
shawaj authored Jun 27, 2023
2 parents ee6e97e + e22d7e4 commit 99c6a63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hm_pyhelper/sbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions hm_pyhelper/tests/test_sbc.py
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 99c6a63

Please sign in to comment.