Beispiel #1
0
def test_update(sut: SqlalchemyRepository, connection):
    w = Widget(name='foo')
    sut.add(w).commit()
    id_ = w.id
    w = sut.find(id_)
    w.name = 'bar'
    sut.update(w).commit()

    assert len(connection.execute('select * from widgets').fetchall()) == 1
    assert len(
        connection.execute(
            "select * from widgets where name = 'bar'").fetchall()) == 1
Beispiel #2
0
def test_many_to_one(sut: SqlalchemyRepository, connection):
    w = Widget(name='foo')
    w.category = Category(name='cat1')
    sut.add(w).commit()

    assert len(connection.execute("select * from widgets").fetchall()) == 1
    assert len(
        connection.execute(
            "select * from widgets where category_id is not null").fetchall()
    ) == 1
    assert len(connection.execute("select * from categories").fetchall()) == 1

    w = sut.find(w.id)
    assert w.category.name == 'cat1'