def family(request): global session session = db.connect() family = Family(family=test.random_string()) session.add(family) session.commit() def finalize(): session.delete(family) session.close() request.addfinalizer(finalize) return family
def test_constraints(): """ Test that the family constraints were created correctly """ session = db.connect() family_name = test.random_string() values = [dict(family=family_name), dict(family=family_name, qualifier='s. lat.')] # fail with two families that have the same name and same qualifiers session.add(Family(**values[0])) session.add(Family(**values[0])) with pytest.raises(IntegrityError): session.commit() session.rollback() # fail with two families that have the same name and same qualifiers session.add(Family(**values[1])) session.add(Family(**values[1])) with pytest.raises(IntegrityError): session.commit() session.rollback() # verify that a family can have the same name as long as the qualifier is different # fail with two families that have the same name and same qualifiers family = Family(**values[0]) family2 = Family(**values[1]) session.add_all([family, family2]) session.commit() session.delete(family) session.delete(family2) session.commit() # test that family cannot be null session.add(Family(family=None)) with pytest.raises(IntegrityError): session.commit() session.rollback() session.close()