def add_default_room_and_two_items(session):
    r = Room('basic room')
    session.add(r)
    session.commit()

    i1 = Item(r, 'toy trucks', 'hudson')
    i2 = Item(r, 'toy boats', 'potato')
    session.add(i1)
    session.add(i2)
    session.commit()

    return (r, [i1, i2])
Beispiel #2
0
def test_update_item_with_new_vals(session, client):
    r = Room('basic')
    session.add(r)
    session.commit()
    i = Item(r, 'toy trucks', 'hudson')
    session.add(i)
    session.commit()

    data = {
        'requestedRoom': r.encoded_room_name,
        'password': '',
        'action': {
            'type': 'update',
            'target': 'item',
            'targetId': i.id,
            'dataToUpdate': {
                'who_has_current': 'Luca',
                'how_long_can_borrow': '3 weeks',
                'due_back': datetime.date(2019, 11, 14).__str__(),
            }
        }
    }

    response = client.post(url_for('server.update_record'),
                           data=json.dumps(data),
                           headers={'Content-Type': 'application/json'})

    assert response.status_code == 200
    item = Item.query.first()
    assert item.who_has_current == 'Luca'
    assert item.how_long_can_borrow == '3 weeks'
    assert item.due_back == datetime.datetime(2019, 11, 14, 0, 0)
def add_room_and_default_item(session):
    newRoom = Room('hudsons room')
    session.add(newRoom)
    session.commit()

    item_1 = Item(newRoom, 'toy trucks', 'hudson')
    session.add(item_1)
    session.commit()
    return (newRoom, item_1)
def test_create_item(session):
    newRoom = Room('hudsons room')
    session.add(newRoom)
    session.commit()

    item_1 = Item(newRoom, 'toy trucks', 'hudson')
    session.add(item_1)
    session.commit()

    assert len(Item.query.all()) == 1
    assert newRoom.items[0] == item_1

    item_2 = Item(newRoom, 'toy boats', 'hudson')
    session.add(item_2)
    session.commit()

    assert len(Item.query.all()) == 2
    assert len(newRoom.items) == 2
    assert 'toy boats' in [i.name for i in Item.query.all()]
Beispiel #5
0
def add_basic_room_item_and_borrowhistory(session):
    r = Room('basic')
    session.add(r)
    session.commit()
    i = Item(r, 'toy trucks', 'hudson')
    session.add(i)
    session.commit()
    bh = BorrowHistory(i, 'Luca')
    session.add(bh)
    session.commit()
    return (r, i, bh)
def test_delete_cascade_doesnt_delete_parents(session):
    room = Room('basic room')
    session.add(room)
    session.commit()

    item = Item(room, 'toys', 'hudson')
    session.add(item)
    session.commit()

    h = BorrowHistory(item, 'Luca')
    session.add(h)
    session.commit()

    Item.query.filter_by(id=item.id).delete()
    session.commit()

    assert Room.query.count() == 1
    assert Item.query.count() == 0
    assert BorrowHistory.query.count() == 0
def test_delete_cascade(session):
    room = Room('basic room')
    session.add(room)
    session.commit()

    item = Item(room, 'toys', 'hudson')
    session.add(item)
    session.commit()

    h = BorrowHistory(item, 'Luca')
    session.add(h)
    session.commit()

    assert Room.query.first() == room
    assert Item.query.first() == item
    assert BorrowHistory.query.first() == h

    Room.query.filter_by(room_name=room.room_name).delete()
    session.commit()

    assert Room.query.count() == 0
    assert Item.query.count() == 0
    assert BorrowHistory.query.count() == 0
Beispiel #8
0
def test_update_borrow_history(session, client):
    r = Room('basic')
    session.add(r)
    session.commit()
    i = Item(r, 'toy trucks', 'hudson')
    session.add(i)
    session.commit()
    bh = BorrowHistory(i, 'Luca')
    session.add(bh)
    session.commit()

    data = {
        'requestedRoom': r.encoded_room_name,
        'password': '',
        'action': {
            'type': 'update',
            'target': 'borrowHistory',
            'targetId': bh.id,
            'dataToUpdate': {
                'date_borrowed': datetime.date(2019, 11, 14).__str__(),
                'due_back': datetime.date(2019, 11, 18).__str__(),
                'notes': 'yuck, it smelled funny'
            }
        }
    }

    response = client.post(url_for('server.update_record'),
                           data=json.dumps(data),
                           headers={'Content-Type': 'application/json'})

    assert response.status_code == 200
    assert response.json['status'] == 'success'
    assert response.json['dbresponse'] == 1
    bhist = BorrowHistory.query.first()
    assert bhist.date_borrowed == datetime.datetime(2019, 11, 14, 0, 0)
    assert bhist.notes == 'yuck, it smelled funny'
    assert bhist.due_back == datetime.datetime(2019, 11, 18, 0, 0)
def add_item_to_room(session, room, name='truck toy', who_owns='hudson'):
    new_item = Item(room, name, who_owns)
    session.add(new_item)
    session.commit()
    return new_item