2024-08-26 23:36:21 -04:00
|
|
|
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)
|
2024-12-03 11:49:34 -05:00
|
|
|
hex_cred = Credential.from_26bit_hex(cred.hex)
|
2024-08-26 23:36:21 -04:00
|
|
|
self.assertEqual(cred, hex_cred)
|
2024-09-01 21:35:58 -04:00
|
|
|
|
|
|
|
def test_example_numbers(self):
|
|
|
|
examples = [
|
|
|
|
(100, 12345, "02C86073"),
|
|
|
|
]
|
|
|
|
|
|
|
|
for facility_code, card_number, hex_number in examples:
|
|
|
|
code_cred = Credential.from_code(facility_code, card_number)
|
2024-12-03 11:49:34 -05:00
|
|
|
hex_cred = Credential.from_26bit_hex(hex_number)
|
2024-09-01 21:35:58 -04:00
|
|
|
self.assertEqual(code_cred, hex_cred)
|