mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Adds ExtendedAppointent unit tests and simplifies Appointment's
This commit is contained in:
@@ -15,7 +15,7 @@ class ExtendedAppointment(Appointment):
|
||||
|
||||
Args:
|
||||
appointment_data (:obj:`dict`): a dictionary containing the following keys:
|
||||
``{locator, to_self_delay, encrypted_blob, expiry}``
|
||||
``{locator, to_self_delay, encrypted_blob, user_id}``
|
||||
|
||||
Returns:
|
||||
:obj:`ExtendedAppointment <teos.extended_appointment.ExtendedAppointment>`: An appointment initialized
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import struct
|
||||
import binascii
|
||||
import pytest
|
||||
from pytest import fixture
|
||||
|
||||
from common.appointment import Appointment
|
||||
@@ -29,8 +30,6 @@ def appointment_data():
|
||||
def test_init_appointment(appointment_data):
|
||||
# The appointment has no checks whatsoever, since the inspector is the one taking care or that, and the only one
|
||||
# creating appointments.
|
||||
# DISCUSS: whether this makes sense by design or checks should be ported from the inspector to the appointment
|
||||
# 35-appointment-checks
|
||||
appointment = Appointment(
|
||||
appointment_data["locator"],
|
||||
appointment_data["start_time"],
|
||||
@@ -78,13 +77,9 @@ def test_from_dict(appointment_data):
|
||||
prev_val = appointment_data[key]
|
||||
appointment_data[key] = None
|
||||
|
||||
try:
|
||||
with pytest.raises(ValueError, match="Wrong appointment data"):
|
||||
Appointment.from_dict(appointment_data)
|
||||
assert False
|
||||
|
||||
except ValueError:
|
||||
appointment_data[key] = prev_val
|
||||
assert True
|
||||
|
||||
|
||||
def test_serialize(appointment_data):
|
||||
|
||||
56
test/teos/unit/test_extended_appointment.py
Normal file
56
test/teos/unit/test_extended_appointment.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
from pytest import fixture
|
||||
|
||||
from common.constants import LOCATOR_LEN_BYTES
|
||||
from teos.extended_appointment import ExtendedAppointment
|
||||
|
||||
from test.common.unit.conftest import get_random_value_hex
|
||||
|
||||
|
||||
# Parent methods are not tested.
|
||||
@fixture
|
||||
def appointment_data():
|
||||
locator = get_random_value_hex(LOCATOR_LEN_BYTES)
|
||||
to_self_delay = 20
|
||||
user_id = get_random_value_hex(16)
|
||||
encrypted_blob_data = get_random_value_hex(100)
|
||||
|
||||
return {
|
||||
"locator": locator,
|
||||
"to_self_delay": to_self_delay,
|
||||
"encrypted_blob": encrypted_blob_data,
|
||||
"user_id": user_id,
|
||||
}
|
||||
|
||||
|
||||
def test_init_appointment(appointment_data):
|
||||
# The appointment has no checks whatsoever, since the inspector is the one taking care or that, and the only one
|
||||
# creating appointments.
|
||||
appointment = ExtendedAppointment(
|
||||
appointment_data["locator"],
|
||||
appointment_data["to_self_delay"],
|
||||
appointment_data["encrypted_blob"],
|
||||
appointment_data["user_id"],
|
||||
)
|
||||
|
||||
assert (
|
||||
appointment_data["locator"] == appointment.locator
|
||||
and appointment_data["to_self_delay"] == appointment.to_self_delay
|
||||
and appointment_data["encrypted_blob"] == appointment.encrypted_blob
|
||||
and appointment_data["user_id"] == appointment.user_id
|
||||
)
|
||||
|
||||
|
||||
def test_from_dict(appointment_data):
|
||||
# The appointment should be build if we don't miss any field
|
||||
appointment = ExtendedAppointment.from_dict(appointment_data)
|
||||
assert isinstance(appointment, ExtendedAppointment)
|
||||
|
||||
# Otherwise it should fail
|
||||
for key in appointment_data.keys():
|
||||
prev_val = appointment_data[key]
|
||||
appointment_data[key] = None
|
||||
|
||||
with pytest.raises(ValueError, match="Wrong appointment data"):
|
||||
ExtendedAppointment.from_dict(appointment_data)
|
||||
appointment_data[key] = prev_val
|
||||
Reference in New Issue
Block a user