示例#1
0
    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()
示例#2
0
    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()
示例#3
0
    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
示例#4
0
    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
示例#5
0
    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
示例#6
0
    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
示例#7
0
    def test_can_change_email_to_null(self):
        user = models.User(email="*****@*****.**")

        user.email = None
示例#8
0
 def test_can_create_user_with_null_email(self):
     models.User(email=None)
示例#9
0
 def test_cannot_create_user_with_too_long_email(self):
     with pytest.raises(ValueError):
         models.User(email="bob@b" + "o" * 100 + "b.com")
示例#10
0
 def test_cannot_create_user_with_invalid_chars(self):
     with pytest.raises(ValueError):
         models.User(username="******")
示例#11
0
 def test_cannot_create_user_with_too_long_username(self):
     with pytest.raises(ValueError):
         models.User(username="******")
示例#12
0
 def test_cannot_create_user_with_too_short_username(self):
     with pytest.raises(ValueError):
         models.User(username="******")
示例#13
0
    def test_userid_derived_from_username_and_authority(self):
        fred = models.User(authority="example.net",
                           username="******",
                           email="*****@*****.**")

        assert fred.userid == "acct:[email protected]"
示例#14
0
 def user(self):
     user = models.User(username="******", authority="example.com")
     return user