def test_lot_device_relationship(): device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', chassis=ComputerChassis.Lunchbox) device.components.add( GraphicCard(serial_number='foo', model='bar1', manufacturer='baz')) child = Lot('child') child.devices.add(device) db.session.add(child) db.session.flush() lot_device = LotDevice.query.one() # type: LotDevice assert lot_device.device_id == device.id assert lot_device.lot_id == child.id assert lot_device.created assert lot_device.author_id == g.user.id assert device.lots == {child} assert device in child assert device in child.all_devices graphic = GraphicCard(serial_number='foo', model='bar') device.components.add(graphic) db.session.flush() assert graphic in child parent = Lot('parent') db.session.add(parent) db.session.flush() parent.add_children(child) assert child in parent
def test_add_edge(): """Tests creating an edge between child - parent - grandparent.""" child = Lot('child') parent = Lot('parent') db.session.add(child) db.session.add(parent) db.session.flush() parent.add_children(child) assert child in parent assert len(child.paths) == 1 assert len(parent.paths) == 1 parent.remove_children(child) assert child not in parent assert len(child.paths) == 1 assert len(parent.paths) == 1 grandparent = Lot('grandparent') db.session.add(grandparent) db.session.flush() grandparent.add_children(parent) parent.add_children(child) assert parent in grandparent assert child in parent assert child in grandparent
def _post(self, lot: Lot, ids: Set[uuid.UUID]): lot.add_children(*ids)