Beispiel #1
0
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
Beispiel #2
0
def test_lot_roots():
    """Tests getting the method Lot.roots."""
    lots = Lot('1'), Lot('2'), Lot('3')
    l1, l2, l3 = lots
    db.session.add_all(lots)
    db.session.flush()

    assert set(Lot.roots()) == {l1, l2, l3}
    l1.add_children(l2)
    assert set(Lot.roots()) == {l1, l3}
Beispiel #3
0
 def post(self):
     l = request.get_json()
     lot = Lot(**l)
     db.session.add(lot)
     db.session().final_flush()
     ret = self.schema.jsonify(lot)
     ret.status_code = 201
     db.session.commit()
     return ret
Beispiel #4
0
def test_lot_model_children():
    """Tests the property Lot.children

    l1
    |
    l2
    |
    l3
    """
    lots = Lot('1'), Lot('2'), Lot('3')
    l1, l2, l3 = lots
    db.session.add_all(lots)
    db.session.flush()
    assert not l1.children
    assert not l1.parents
    assert not l2.children
    assert not l2.parents
    assert not l3.parents
    assert not l3.children

    l1.add_children(l2)
    assert l1.children == {l2}
    assert l2.parents == {l1}

    l2.add_children(l3)
    assert l1.children == {l2}
    assert l2.parents == {l1}
    assert l2.children == {l3}
    assert l3.parents == {l2}

    l2.delete()
    db.session.flush()
    assert not l1.children
    assert not l3.parents

    l1.delete()
    db.session.flush()
    l3b = Lot.query.one()
    assert l3 == l3b
    assert not l3.parents
Beispiel #5
0
def test_lot_unite_graphs_and_find():
    """Adds and removes children uniting already existing graphs.

    1  3
     \/
     2

      4
     | \
     |  6
     \ /
      5
     | \
     7  8

     This builds the graph and then unites 2 - 4.
    """

    lots = tuple(Lot(str(i)) for i in range(1, 9))
    l1, l2, l3, l4, l5, l6, l7, l8 = lots
    db.session.add_all(lots)
    db.session.flush()

    l1.add_children(l2)
    assert l2 in l1
    l3.add_children(l2)
    assert l2 in l3
    l5.add_children(l7)
    assert l7 in l5
    l4.add_children(l5)
    assert l5 in l4
    assert l7 in l4
    l5.add_children(l8)
    assert l8 in l5
    l4.add_children(l6)
    assert l6 in l4
    l6.add_children(l5)
    assert l5 in l6 and l5 in l4

    # We unite the two graphs
    l2.add_children(l4)
    assert l4 in l2 and l5 in l2 and l6 in l2 and l7 in l2 and l8 in l2
    assert l4 in l3 and l5 in l3 and l6 in l3 and l7 in l3 and l8 in l3

    # We remove the union
    l2.remove_children(l4)
    assert l4 not in l2 and l5 not in l2 and l6 not in l2 and l7 not in l2 and l8 not in l2
    assert l4 not in l3 and l5 not in l3 and l6 not in l3 and l7 not in l3 and l8 not in l3
Beispiel #6
0
 def post(self):
     # Create delivery note
     dn = request.get_json()
     dlvnote = Deliverynote(**dn)
     # Create a lot
     lot_name = dlvnote.document_id + "_" + datetime.datetime.utcnow(
     ).strftime("%Y-%m-%d")
     new_lot = Lot(name=lot_name)
     dlvnote.lot_id = new_lot.id
     db.session.add(new_lot)
     db.session.add(dlvnote)
     db.session().final_flush()
     ret = self.schema.jsonify(dlvnote)
     ret.status_code = 201
     db.session.commit()
     return ret
Beispiel #7
0
def test_lot_multiple_parents(auth_app_context):
    """Tests creating a lot with two parent lots:

    grandparent1 grandparent2
             \   /
            parent
              |
            child
    """
    lots = Lot('child'), Lot('parent'), Lot('grandparent1'), Lot(
        'grandparent2')
    child, parent, grandparent1, grandparent2 = lots
    db.session.add_all(lots)
    db.session.flush()

    grandparent1.add_children(parent)
    assert parent in grandparent1
    parent.add_children(child)
    assert child in parent
    assert child in grandparent1
    grandparent2.add_children(parent)
    assert parent in grandparent1
    assert parent in grandparent2
    assert child in parent
    assert child in grandparent1
    assert child in grandparent2

    p = parent.id
    c = child.id
    gp1 = grandparent1.id
    gp2 = grandparent2.id

    nodes = auth_app_context.resources[Lot.t].VIEW.ui_tree()
    assert nodes[0]['id'] == gp1
    assert nodes[0]['nodes'][0]['id'] == p
    assert nodes[0]['nodes'][0]['nodes'][0]['id'] == c
    assert nodes[0]['nodes'][0]['nodes'][0]['nodes'] == []
    assert nodes[1]['id'] == gp2
    assert nodes[1]['nodes'][0]['id'] == p
    assert nodes[1]['nodes'][0]['nodes'][0]['id'] == c
    assert nodes[1]['nodes'][0]['nodes'][0]['nodes'] == []

    # Now remove all childs

    grandparent1.remove_children(parent)
    assert parent not in grandparent1
    assert child in parent
    assert parent in grandparent2
    assert child not in grandparent1
    assert child in grandparent2

    nodes = auth_app_context.resources[Lot.t].VIEW.ui_tree()
    assert nodes[0]['id'] == gp1
    assert nodes[0]['nodes'] == []
    assert nodes[1]['id'] == gp2
    assert nodes[1]['nodes'][0]['id'] == p
    assert nodes[1]['nodes'][0]['nodes'][0]['id'] == c
    assert nodes[1]['nodes'][0]['nodes'][0]['nodes'] == []

    grandparent2.remove_children(parent)
    assert parent not in grandparent2
    assert parent not in grandparent1
    assert child not in grandparent2
    assert child not in grandparent1
    assert child in parent

    nodes = auth_app_context.resources[Lot.t].VIEW.ui_tree()
    assert nodes[0]['id'] == gp1
    assert nodes[0]['nodes'] == []
    assert nodes[1]['id'] == gp2
    assert nodes[1]['nodes'] == []
    assert nodes[2]['id'] == p
    assert nodes[2]['nodes'][0]['id'] == c
    assert nodes[2]['nodes'][0]['nodes'] == []

    parent.remove_children(child)
    assert child not in parent
    assert len(child.paths) == 1
    assert len(parent.paths) == 1

    nodes = auth_app_context.resources[Lot.t].VIEW.ui_tree()
    assert nodes[0]['id'] == gp1
    assert nodes[0]['nodes'] == []
    assert nodes[1]['id'] == gp2
    assert nodes[1]['nodes'] == []
    assert nodes[2]['id'] == p
    assert nodes[2]['nodes'] == []
    assert nodes[3]['id'] == c
    assert nodes[3]['nodes'] == []
Beispiel #8
0
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
Beispiel #9
0
 def _delete(self, lot: Lot, ids: Set[uuid.UUID]):
     lot.remove_children(*ids)
Beispiel #10
0
 def _post(self, lot: Lot, ids: Set[uuid.UUID]):
     lot.add_children(*ids)