示例#1
0
def test_many_to_many(control):
    # test the creation of a many to many relationship
    with control.session as session:
        create_pages(session)
        session.add(Permission(perm_type='admin'))
        session.commit()

        users = session.query(Person).\
            filter(Person.perm.any(Permission.perm_type == 'user')).\
            all()

        for user in users:
            assert user.perm[0].perm_type == 'user'
        control.save_person({
            'perm': ['admin', 'user']
        }, 1)
        admin = session.query(Person).\
            filter(Person.perm.any(Permission.perm_type == 'admin')).\
            all()
        assert len(admin) == 1
        assert admin[0].id == 1
示例#2
0
def test_exists(control):
    # test the use of the exists function

    EMAIL = "*****@*****.**"
    NAME = "Foobert Barfoo"

    test_id = control.save_person({
        'email': EMAIL,
        'name': NAME
    })
    with control.session as session:
        stmt = exists().where(Person.id == test_id)
        result = session.query(Person.name).filter(stmt)

    assert result[0][0] == NAME
示例#3
0
def test_delete(control):
    # test delete functionality
    EMAIL = "*****@*****.**"
    NAME = "Foobert Barfoo"

    test_id = control.save_person({
        'email': EMAIL,
        'name': NAME
    })
    with control.session as session:
        foobert = session.query(Person).get(test_id)
        print(foobert)
        session.delete(foobert)
        session.commit()
        remaining = session.query(Person).filter_by(name=NAME).count()
        assert remaining == 0
        # TODO: create new data
        result = session.query(Page.owner_id).\
            join(Page.content).\
            filter(PageItem.body.isnot(None)).first()