From 97b746ba3a9e9b5caa98b6db4d605d99cee419f7 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 26 Aug 2024 23:36:21 -0400 Subject: [PATCH] doorcontrol: Add basic unit tests for Credential --- doorcontrol/hid/tests/__init__.py | 0 doorcontrol/hid/tests/test_Credential.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 doorcontrol/hid/tests/__init__.py create mode 100644 doorcontrol/hid/tests/test_Credential.py diff --git a/doorcontrol/hid/tests/__init__.py b/doorcontrol/hid/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/doorcontrol/hid/tests/test_Credential.py b/doorcontrol/hid/tests/test_Credential.py new file mode 100644 index 0000000..7e9b240 --- /dev/null +++ b/doorcontrol/hid/tests/test_Credential.py @@ -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)