-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reply test cases, added keypad data
- Loading branch information
Showing
5 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Tests for OSDP Replies""" | ||
|
||
import os | ||
import sys | ||
import unittest | ||
import datetime | ||
from uuid import UUID, uuid4 | ||
|
||
sys.path.insert(0, os.path.abspath('..')) | ||
from osdp import * | ||
|
||
|
||
class CommandTestCase(unittest.TestCase): | ||
|
||
"""Test commands for OSDP Python Module.""" | ||
|
||
def setUp(self): | ||
"""Setup.""" | ||
|
||
def tearDown(self): | ||
"""Teardown.""" | ||
|
||
def test_poll_reply_no_data_checksum(self): | ||
bus_id = uuid4() | ||
device = Device(address=0x7F, use_crc=False, use_secure_channel=False) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 1) | ||
|
||
command = PollCommand(address=0x7F) | ||
data = bytes.fromhex('53 FF 07 00 01 40 66') | ||
reply = Reply.parse(data, bus_id, command, device) | ||
self.assertEqual(reply.type, ReplyType.Ack) | ||
self.assertEqual(reply.extract_reply_data, b'') | ||
|
||
message = reply.build_reply(address=0x7F, control=device.message_control).hex().upper() | ||
self.assertEqual(message, data.hex().upper()) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 2) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 3) | ||
|
||
def test_poll_reply_card_data_checksum(self): | ||
bus_id = uuid4() | ||
device = Device(address=0x7F, use_crc=False, use_secure_channel=False) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 1) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 2) | ||
|
||
command = PollCommand(address=0x7F) | ||
data = bytes.fromhex('53 FF 0F 00 02 50 FF 01 1A 00 CD 22 C7 16 67') | ||
reply = Reply.parse(data, bus_id, command, device) | ||
self.assertEqual(reply.type, ReplyType.RawReaderData) | ||
self.assertEqual(reply.extract_reply_data.hex().upper(), 'FF011A00CD22C716') | ||
|
||
card_data = RawCardData.parse_data(reply) | ||
self.assertEqual(card_data.data.hex().upper(), 'CD22C716') | ||
|
||
message = reply.build_reply(address=0x7F, control=device.message_control).hex().upper() | ||
self.assertEqual(message, data.hex().upper()) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 3) | ||
|
||
def test_poll_reply_key_data_checksum(self): | ||
bus_id = uuid4() | ||
device = Device(address=0x7F, use_crc=False, use_secure_channel=False) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 1) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 2) | ||
|
||
command = PollCommand(address=0x7F) | ||
data = bytes.fromhex('53 FF 0D 00 02 53 FF 04 31 32 33 34 7F') | ||
reply = Reply.parse(data, bus_id, command, device) | ||
self.assertEqual(reply.type, ReplyType.KeypadData) | ||
self.assertEqual(reply.extract_reply_data.hex().upper(), 'FF0431323334') | ||
|
||
keypad_data = KeypadData.parse_data(reply) | ||
self.assertEqual(keypad_data.data.hex().upper(), '31323334') | ||
|
||
message = reply.build_reply(address=0x7F, control=device.message_control).hex().upper() | ||
self.assertEqual(message, data.hex().upper()) | ||
|
||
device.message_control.increment_sequence(device.message_control.sequence) | ||
self.assertEqual(device.message_control.sequence, 3) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |