doorcontrol: Add basic unit tests for Credential

This commit is contained in:
Adam Goldsmith 2024-08-26 23:36:21 -04:00
parent cbe684d918
commit 97b746ba3a
2 changed files with 20 additions and 0 deletions

View File

View File

@ -0,0 +1,20 @@
from unittest import TestCase
from hypothesis import given
from hypothesis import strategies as st
from doorcontrol.hid.Credential import Credential
class CredentialTestCase(TestCase):
@given(facility_code=st.integers(0, 0xFF), card_number=st.integers(0, 0xFFFF))
def test_code_round_trip(self, facility_code: int, card_number: int):
cred = Credential.from_code(facility_code, card_number)
self.assertEqual(cred.facility_code, facility_code)
self.assertEqual(cred.card_number, card_number)
@given(facility_code=st.integers(0, 0xFF), card_number=st.integers(0, 0xFFFF))
def test_to_hex_round_trip(self, facility_code: int, card_number: int):
cred = Credential.from_code(facility_code, card_number)
hex_cred = Credential.from_hex(cred.hex)
self.assertEqual(cred, hex_cred)