def test_cannot_create_case_variant_of_user(self, db_session): bob = models.User(authority="example.com", username="******", email="*****@*****.**") bob2 = models.User(authority="example.com", username="******", email="*****@*****.**") db_session.add(bob) db_session.add(bob2) with pytest.raises(exc.IntegrityError): db_session.flush()
def test_cannot_create_dot_variant_of_user(self, db_session): fred = models.User(authority="example.com", username="******", email="*****@*****.**") fred2 = models.User(authority="example.com", username="******", email="*****@*****.**") db_session.add(fred) db_session.add(fred2) with pytest.raises(exc.IntegrityError): db_session.flush()
def test_userid_in_query(self, db_session): fred = models.User(authority="example.net", username="******", email="*****@*****.**") alice = models.User(authority="foobar.com", username="******", email="*****@*****.**") db_session.add_all([fred, alice]) db_session.flush() result = (db_session.query(models.User).filter( models.User.userid.in_([ "acct:[email protected]", "acct:[email protected]", "acct:[email protected]", ])).all()) assert len(result) == 2 assert fred in result assert alice in result
def test_userid_equals_query(self, db_session): fred = models.User(authority="example.net", username="******", email="*****@*****.**") db_session.add(fred) db_session.flush() result = (db_session.query( models.User).filter_by(userid="acct:[email protected]").one()) assert result == fred
def test_filtering_by_username_matches_case_variant_of_user( self, db_session): fred = models.User(authority="example.com", username="******", email="*****@*****.**") db_session.add(fred) db_session.flush() result = db_session.query( models.User).filter_by(username="******").one() assert result == fred
def test_userid_in_query_with_invalid_userid_mixed_in(self, db_session): # This is to ensure that we don't expose the ValueError that could # potentially be thrown by split_user. fred = models.User(authority="example.net", username="******", email="*****@*****.**") db_session.add(fred) db_session.flush() result = (db_session.query(models.User).filter( models.User.userid.in_(["acct:[email protected]", "invalid"])).all()) assert len(result) == 1 assert fred in result
def test_can_change_email_to_null(self): user = models.User(email="*****@*****.**") user.email = None
def test_can_create_user_with_null_email(self): models.User(email=None)
def test_cannot_create_user_with_too_long_email(self): with pytest.raises(ValueError): models.User(email="bob@b" + "o" * 100 + "b.com")
def test_cannot_create_user_with_invalid_chars(self): with pytest.raises(ValueError): models.User(username="******")
def test_cannot_create_user_with_too_long_username(self): with pytest.raises(ValueError): models.User(username="******")
def test_cannot_create_user_with_too_short_username(self): with pytest.raises(ValueError): models.User(username="******")
def test_userid_derived_from_username_and_authority(self): fred = models.User(authority="example.net", username="******", email="*****@*****.**") assert fred.userid == "acct:[email protected]"
def user(self): user = models.User(username="******", authority="example.com") return user