Skip to content

Commit 6773178

Browse files
Extend tests
This patch moves the tests from nk3.updates into the test suite and also adds some tests for listing NK3 and NKPK devices.
1 parent 2a52868 commit 6773178

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

src/nitrokey/nk3/updates.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -373,26 +373,3 @@ def _perform_update(
373373
except Exception as e:
374374
raise self.ui.error("Failed to perform firmware update", e)
375375
logger.debug("Firmware update finished successfully")
376-
377-
378-
def test_update_path_default() -> None:
379-
assert (
380-
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 1, 0))
381-
== UpdatePath.default
382-
)
383-
assert UpdatePath.create(None, None, Version(1, 1, 0)) == UpdatePath.default
384-
385-
386-
def test_update_path_match() -> None:
387-
assert (
388-
UpdatePath.create(Variant.NRF52, Version(1, 2, 2), Version(1, 3, 0))
389-
== UpdatePath.nRF_IFS_Migration_v1_3
390-
)
391-
assert (
392-
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 3, 0))
393-
== UpdatePath.nRF_IFS_Migration_v1_3
394-
)
395-
assert (
396-
UpdatePath.create(Variant.NRF52, None, Version(1, 3, 0))
397-
== UpdatePath.nRF_IFS_Migration_v1_3
398-
)

tests/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@ def test_import(self):
1212

1313
self.assertIsInstance(nitrokey, ModuleType)
1414

15+
def test_list_nk3(self):
16+
from nitrokey.nk3 import list
17+
18+
list()
19+
20+
def test_list_nkpk(self):
21+
from nitrokey.nkpk import list
22+
23+
list()
24+
25+
26+
class TestNk3Updates(unittest.TestCase):
27+
def test_update_path_default(self):
28+
from nitrokey.nk3.updates import UpdatePath
29+
from nitrokey.trussed.bootloader import Variant
30+
from nitrokey.trussed.utils import Version
31+
32+
self.assertEquals(
33+
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 1, 0)),
34+
UpdatePath.default,
35+
)
36+
37+
def test_update_path_match(self):
38+
from nitrokey.nk3.updates import UpdatePath
39+
from nitrokey.trussed.bootloader import Variant
40+
from nitrokey.trussed.utils import Version
41+
42+
self.assertEquals(
43+
UpdatePath.create(Variant.NRF52, Version(1, 2, 2), Version(1, 3, 0)),
44+
UpdatePath.nRF_IFS_Migration_v1_3,
45+
)
46+
self.assertEquals(
47+
UpdatePath.create(Variant.NRF52, Version(1, 0, 0), Version(1, 3, 0)),
48+
UpdatePath.nRF_IFS_Migration_v1_3,
49+
)
50+
self.assertEquals(
51+
UpdatePath.create(Variant.NRF52, None, Version(1, 3, 0)),
52+
UpdatePath.nRF_IFS_Migration_v1_3,
53+
)
54+
1555

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

0 commit comments

Comments
 (0)