def test_constructor_invalid_username(): username = 42 password = "******" user = User(username, password) assert user.username is None assert user.password == password
def test_constructor_empty_string_username(): username = "" password = "******" user = User(username, password) assert user.username is None assert user.password == password
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
def test_equality_when_equal(user): assert user == user username = user.username password = user.password other = User(username, password) assert user == other
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
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)
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)
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()
def add_movie_to_watchlist(self, user: User, movie: Movie) -> None: user.add_to_watchlist(movie)
def remove_from_watchlist(self, user: User, movie: Movie) -> None: user.remove_from_watchlist(movie)
def add_movie_to_watched(self, user: User, movie: Movie) -> None: user.watch_movie(movie)
def remove_from_watched(self, user: User, movie: Movie) -> None: user.remove_from_watched_movies(movie)
def change_password(self, user: User, new_password: str) -> None: user.password = new_password
def test_hash_changes(user): username = "******" password = user.password other = User(username, password) assert hash(user) != hash(other)
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()
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()
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
def user(): return User("username", "correcthorsebatterystaple", id_=1)
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)