Esempio n. 1
0
def test_constructor_invalid_username():
    username = 42
    password = "******"
    user = User(username, password)

    assert user.username is None
    assert user.password == password
Esempio n. 2
0
def test_constructor_empty_string_username():
    username = ""
    password = "******"
    user = User(username, password)

    assert user.username is None
    assert user.password == password
Esempio n. 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
Esempio n. 4
0
def test_equality_when_equal(user):
    assert user == user

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

    assert user == other
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 11
0
 def add_movie_to_watchlist(self, user: User, movie: Movie) -> None:
     user.add_to_watchlist(movie)
Esempio n. 12
0
 def remove_from_watchlist(self, user: User, movie: Movie) -> None:
     user.remove_from_watchlist(movie)
Esempio n. 13
0
 def add_movie_to_watched(self, user: User, movie: Movie) -> None:
     user.watch_movie(movie)
Esempio n. 14
0
 def remove_from_watched(self, user: User, movie: Movie) -> None:
     user.remove_from_watched_movies(movie)
Esempio n. 15
0
 def change_password(self, user: User, new_password: str) -> None:
     user.password = new_password
Esempio n. 16
0
def test_hash_changes(user):
    username = "******"
    password = user.password
    other = User(username, password)
    assert hash(user) != hash(other)
Esempio n. 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()
Esempio n. 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()
Esempio n. 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
Esempio n. 22
0
def user():
    return User("username", "correcthorsebatterystaple", id_=1)
Esempio n. 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)