Skip to content

Commit

Permalink
tests - increase setting TC Code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
odudex committed Dec 12, 2024
1 parent 7a430c8 commit c41809b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/pages/test_settings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,18 @@ def test_set_first_tc_code(amigo, mocker):
mocker,
[
BUTTON_ENTER,
BUTTON_PAGE,
BUTTON_ENTER,
], # Skip TC Flash Hash at boot
], # Confirm TC Flash Hash at boot
)
ctx.tc_code_enabled = False
settings_page = SettingsPage(ctx)
settings_page.capture_from_keypad = mocker.MagicMock(return_value="123456")
settings_page.enter_modify_tc_code()
assert ctx.tc_code_enabled == True
assert mock_file.write_data == TC_CODE_EXTENDED_HASH
assert mock_file.previous_data[-1] == TC_CODE_EXTENDED_HASH
assert (
mock_file.write_data == '{"settings": {"security": {"boot_flash_hash": true}}}'
)


def test_set_first_tc_code_not_match(amigo, mocker):
Expand Down Expand Up @@ -477,16 +479,18 @@ def test_set_new_tc_code(amigo, mocker):
mocker,
[
BUTTON_ENTER,
BUTTON_PAGE,
BUTTON_ENTER,
], # Skip TC Flash Hash at boot
], # Confirm TC Flash Hash at boot
)
ctx.tc_code_enabled = True
settings_page = SettingsPage(ctx)
settings_page.capture_from_keypad = mocker.MagicMock(return_value="123456")
settings_page.enter_modify_tc_code()
assert ctx.tc_code_enabled == True
assert mock_file.write_data == TC_CODE_EXTENDED_HASH
assert mock_file.previous_data[-1] == TC_CODE_EXTENDED_HASH
assert (
mock_file.write_data == '{"settings": {"security": {"boot_flash_hash": true}}}'
)


def test_wrong_code_set_new_tc_code(amigo, mocker):
Expand Down
5 changes: 5 additions & 0 deletions tests/shared_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MockFile:

def __init__(self, data=b""):
self.data = data if isinstance(data, bytes) else data.encode()
self.previous_data = []
self.position = 0
self.write_data = bytearray()
self.mode = "rb"
Expand All @@ -20,8 +21,12 @@ def __init__(self, data=b""):

def set_mode(self, mode):
self.mode = mode
if self.write_data:
self.previous_data.append(self.write_data)
if "b" not in mode:
self.write_data = ""
else:
self.write_data = bytearray()

def seek(self, pos):
self.position = pos
Expand Down

0 comments on commit c41809b

Please sign in to comment.