示例#1
0
def test_constructor_invalid_username():
    username = 42
    password = "******"
    user = User(username, password)

    assert user.username is None
    assert user.password == password
示例#2
0
def test_constructor_empty_string_username():
    username = ""
    password = "******"
    user = User(username, password)

    assert user.username is None
    assert user.password == password
示例#3
0
def test_constructor_empty_string_password():
    username = "******"
    username_expected = "Test  User"
    password = ""
    user = User(username, password)

    assert user.username == username_expected
    assert user.password == password
示例#4
0
def test_equality_when_equal(user):
    assert user == user

    username = user.username
    password = user.password
    other = User(username, password)

    assert user == other
示例#5
0
def test_equality_when_not_equal(user):
    # Check not equal when users are partially equal
    username = "******"
    password = user.password
    other = User(username, password)
    assert user != other

    username = user.username
    password = "******"
    other = User(username, password)
    assert user != other

    # Check not equal when users are completely different
    username = "******"
    password = "******"
    other = User(username, password)
    assert user != other
示例#6
0
def test_constructor():
    username = "******"
    username_expected = "Test  User"
    password = "******"
    user = User(username, password)

    assert user.username == username_expected
    assert user.password == password
    assert isinstance(user.joined_on_utc, datetime)
示例#7
0
def add_user(repo: AbstractRepository, username: str, password: str) -> None:
    """ Adds the given user to the given repository. """
    # Check that the given username is available.
    if check_if_user_exists(repo, username):
        raise NameNotUniqueException

    # Encrypt password so that the database doesn't store passwords 'in the clear'.
    password_hash = generate_password_hash(password)

    # Create and store the new User, with password encrypted.
    user = User(username, password_hash)
    repo.add_user(user)
示例#8
0
def test_less_than_when_true():
    # Check password doesn't affect the ordering
    a = User("a", 'a')
    b = User("b", 'a')
    assert a < b

    a = User("a", 'a')
    b = User("b", 'b')
    assert a < b

    a = User("a", 'b')
    b = User("b", 'a')
    assert a < b
 def change_username(self, user: User, new_username: str) -> None:
     with self._session_cm as scm:
         user.username = new_username
         scm.session.commit()
 def change_password(self, user: User, new_password: str) -> None:
     with self._session_cm as scm:
         user.password = new_password
         scm.session.commit()
示例#11
0
 def add_movie_to_watchlist(self, user: User, movie: Movie) -> None:
     user.add_to_watchlist(movie)
示例#12
0
 def remove_from_watchlist(self, user: User, movie: Movie) -> None:
     user.remove_from_watchlist(movie)
示例#13
0
 def add_movie_to_watched(self, user: User, movie: Movie) -> None:
     user.watch_movie(movie)
示例#14
0
 def remove_from_watched(self, user: User, movie: Movie) -> None:
     user.remove_from_watched_movies(movie)
示例#15
0
 def change_password(self, user: User, new_password: str) -> None:
     user.password = new_password
示例#16
0
def test_hash_changes(user):
    username = "******"
    password = user.password
    other = User(username, password)
    assert hash(user) != hash(other)
示例#17
0
def test_constructor_invalid_password():
    username = "******"
    password = 42

    with pytest.raises(TypeError):
        _ = User(username, password)
 def add_movie_to_watchlist(self, user: User, movie: Movie) -> None:
     with self._session_cm as scm:
         user.add_to_watchlist(movie)
         scm.session.commit()
示例#19
0
def test_repr_no_username():
    username = None
    password = "******"
    user = User(username, password)

    assert repr(user) == f"<User {user.id}, None>"
 def remove_from_watchlist(self, user: User, movie: Movie) -> None:
     with self._session_cm as scm:
         user.remove_from_watchlist(movie)
         scm.session.commit()
示例#21
0
 def change_username(self, user: User, new_username: str) -> None:
     # Update the mapping from username to user id
     del self._user_id_map[user.username]
     self._user_id_map[new_username] = user.id
     user.username = new_username
示例#22
0
def user():
    return User("username", "correcthorsebatterystaple", id_=1)
示例#23
0
def test_less_than_when_false():
    a = User("a", 'a')
    b = User("a", 'a')
    assert not (a < b)

    a = User("a", 'a')
    b = User("a", 'b')
    assert not (a < b)

    a = User("a", 'b')
    b = User("a", 'a')
    assert not (a < b)

    a = User("b", 'a')
    b = User("a", 'a')
    assert not (a < b)

    a = User("b", 'a')
    b = User("a", 'b')
    assert not (a < b)

    a = User("b", 'b')
    b = User("a", 'a')
    assert not (a < b)