extended_appointment - deletes appointment size

This commit is contained in:
Sergi Delgado Segura
2020-04-22 14:48:00 +02:00
parent 5f7a909804
commit eb6d292d3c
4 changed files with 15 additions and 19 deletions

View File

@@ -1,3 +1,7 @@
from teos.responder import TransactionTracker
from teos.extended_appointment import ExtendedAppointment
class Builder: class Builder:
""" """
The :class:`Builder` class is in charge of reconstructing data loaded from the appointments database and build the The :class:`Builder` class is in charge of reconstructing data loaded from the appointments database and build the
@@ -26,17 +30,14 @@ class Builder:
locator_uuid_map = {} locator_uuid_map = {}
for uuid, data in appointments_data.items(): for uuid, data in appointments_data.items():
appointments[uuid] = { appointment = ExtendedAppointment.from_dict(data)
"locator": data.get("locator"), appointments[uuid] = appointment.get_summary()
"user_id": data.get("user_id"),
"size": len(data.get("encrypted_blob")),
}
if data.get("locator") in locator_uuid_map: if appointment.locator in locator_uuid_map:
locator_uuid_map[data.get("locator")].append(uuid) locator_uuid_map[appointment.locator].append(uuid)
else: else:
locator_uuid_map[data.get("locator")] = [uuid] locator_uuid_map[appointment.locator] = [uuid]
return appointments, locator_uuid_map return appointments, locator_uuid_map
@@ -64,17 +65,14 @@ class Builder:
tx_tracker_map = {} tx_tracker_map = {}
for uuid, data in tracker_data.items(): for uuid, data in tracker_data.items():
trackers[uuid] = { tracker = TransactionTracker.from_dict(data)
"penalty_txid": data.get("penalty_txid"), trackers[uuid] = tracker.get_summary()
"locator": data.get("locator"),
"user_id": data.get("user_id"),
}
if data.get("penalty_txid") in tx_tracker_map: if tracker.penalty_txid in tx_tracker_map:
tx_tracker_map[data.get("penalty_txid")].append(uuid) tx_tracker_map[tracker.penalty_txid].append(uuid)
else: else:
tx_tracker_map[data.get("penalty_txid")] = [uuid] tx_tracker_map[tracker.penalty_txid] = [uuid]
return trackers, tx_tracker_map return trackers, tx_tracker_map

View File

@@ -13,7 +13,7 @@ class ExtendedAppointment(Appointment):
Returns: Returns:
:obj:`dict`: the appointment summary. :obj:`dict`: the appointment summary.
""" """
return {"locator": self.locator, "user_id": self.user_id, "size": len(self.encrypted_blob)} return {"locator": self.locator, "user_id": self.user_id}
@classmethod @classmethod
def from_dict(cls, appointment_data): def from_dict(cls, appointment_data):

View File

@@ -47,7 +47,6 @@ def test_build_appointments():
assert uuid in appointments_data.keys() assert uuid in appointments_data.keys()
assert appointments_data[uuid].get("locator") == appointment.get("locator") assert appointments_data[uuid].get("locator") == appointment.get("locator")
assert appointments_data[uuid].get("user_id") == appointment.get("user_id") assert appointments_data[uuid].get("user_id") == appointment.get("user_id")
assert len(appointments_data[uuid].get("encrypted_blob")) == appointment.get("size")
assert uuid in locator_uuid_map[appointment.get("locator")] assert uuid in locator_uuid_map[appointment.get("locator")]

View File

@@ -45,7 +45,6 @@ def test_get_summary(appointment_data):
assert ExtendedAppointment.from_dict(appointment_data).get_summary() == { assert ExtendedAppointment.from_dict(appointment_data).get_summary() == {
"locator": appointment_data["locator"], "locator": appointment_data["locator"],
"user_id": appointment_data["user_id"], "user_id": appointment_data["user_id"],
"size": len(appointment_data["encrypted_blob"]),
} }