Skip to content

Commit

Permalink
Extend tests
Browse files Browse the repository at this point in the history
This patch moves the tests from nk3.updates into the test suite and also
adds some tests for listing NK3 and NKPK devices.
  • Loading branch information
robin-nitrokey committed Jul 23, 2024
1 parent 2a52868 commit 6773178
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/nitrokey/nk3/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,26 +373,3 @@ def _perform_update(
except Exception as e:
raise self.ui.error("Failed to perform firmware update", e)
logger.debug("Firmware update finished successfully")


def test_update_path_default() -> None:
assert (
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 1, 0))
== UpdatePath.default
)
assert UpdatePath.create(None, None, Version(1, 1, 0)) == UpdatePath.default


def test_update_path_match() -> None:
assert (
UpdatePath.create(Variant.NRF52, Version(1, 2, 2), Version(1, 3, 0))
== UpdatePath.nRF_IFS_Migration_v1_3
)
assert (
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 3, 0))
== UpdatePath.nRF_IFS_Migration_v1_3
)
assert (
UpdatePath.create(Variant.NRF52, None, Version(1, 3, 0))
== UpdatePath.nRF_IFS_Migration_v1_3
)
40 changes: 40 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@ def test_import(self):

self.assertIsInstance(nitrokey, ModuleType)

def test_list_nk3(self):
from nitrokey.nk3 import list

list()

def test_list_nkpk(self):
from nitrokey.nkpk import list

list()


class TestNk3Updates(unittest.TestCase):
def test_update_path_default(self):
from nitrokey.nk3.updates import UpdatePath
from nitrokey.trussed.bootloader import Variant
from nitrokey.trussed.utils import Version

self.assertEquals(
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 1, 0)),
UpdatePath.default,
)

def test_update_path_match(self):
from nitrokey.nk3.updates import UpdatePath
from nitrokey.trussed.bootloader import Variant
from nitrokey.trussed.utils import Version

self.assertEquals(
UpdatePath.create(Variant.NRF52, Version(1, 2, 2), Version(1, 3, 0)),
UpdatePath.nRF_IFS_Migration_v1_3,
)
self.assertEquals(
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 3, 0)),
UpdatePath.nRF_IFS_Migration_v1_3,
)
self.assertEquals(
UpdatePath.create(Variant.NRF52, None, Version(1, 3, 0)),
UpdatePath.nRF_IFS_Migration_v1_3,
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 6773178

Please sign in to comment.