def test_repository_does_not_add_a_review_without_a_movie_properly_attached(in_memory_repo): user = User('spooky', 'Spookier9') in_memory_repo.add_user(user) user = in_memory_repo.get_user('Spooky') movie = in_memory_repo.get_movie(2) review = Review(None, movie, "Action packed!") user.add_review(review) with pytest.raises(RepositoryException): # Exception expected because the Article doesn't refer to the Comment. in_memory_repo.add_review(review)
def test_repository_does_not_add_a_review_without_a_movie_properly_attached( in_memory_repo): user = User('wpking', 'Alphadog123') in_memory_repo.add_user(user) user = in_memory_repo.get_user('wpking') movie = in_memory_repo.get_movie(2) review = Review(None, movie, "The movie was quite average") user.add_review(review) with pytest.raises(RepositoryException): # Exception expected because the Article doesn't refer to the Comment. in_memory_repo.add_review(review)
def test_repository_does_not_add_a_review_without_a_movie_properly_attached( in_memory_repo): user = User('Nina', '123456789') in_memory_repo.add_user(user) user = in_memory_repo.get_user('Nina') movie = in_memory_repo.get_movie(2) review = Review(None, movie, "i like this movie :)") user.add_review(review) with pytest.raises(RepositoryException): # Exception expected because the Article doesn't refer to the Comment. in_memory_repo.add_review(review)
def add_user(username: str, password: str, repository: AbstractRepository): user = repository.get_user(username) if user is not None: raise NameNotUniqueException password_hash = generate_password_hash(password) user = User(username, password_hash) repository.add_user(user)
def test_repository_can_retrieve_reviews(in_memory_repo): assert len(in_memory_repo.get_reviews()) == 0 user = User('spooky', 'Spookier9') in_memory_repo.add_user(user) user = in_memory_repo.get_user('spooky') movie = in_memory_repo.get_movie(2) review = make_review(review_text="HIGHLY RECOMMEND!", user=user, movie=movie) in_memory_repo.add_review(review) assert len(in_memory_repo.get_reviews()) == 1
def test_repository_can_add_a_review(in_memory_repo): user = User('spooky', 'Spookier9') in_memory_repo.add_user(user) user = in_memory_repo.get_user('spooky') movie = in_memory_repo.get_movie(2) review = make_review(review_text="This was pretty boring", user=user, movie= movie) in_memory_repo.add_review(review) assert review in in_memory_repo.get_reviews()
def test_repository_can_retrieve_reviews(in_memory_repo): assert len(in_memory_repo.get_reviews()) == 0 user = User('wpking', 'Alphadog123') in_memory_repo.add_user(user) user = in_memory_repo.get_user('wpking') movie = in_memory_repo.get_movie(2) review = make_review(review_text="This movie was terrible", user=user, movie=movie) in_memory_repo.add_review(review) assert len(in_memory_repo.get_reviews()) == 1
def test_repository_can_add_a_review(in_memory_repo): user = User('wpking', 'Alphadog123') in_memory_repo.add_user(user) user = in_memory_repo.get_user('wpking') movie = in_memory_repo.get_movie(2) review = make_review(review_text="This movie was not entertaining", user=user, movie=movie) in_memory_repo.add_review(review) assert review in in_memory_repo.get_reviews()
def add_user(username: str, password: str, repo: AbstractRepository): # Check that the given username is available. user = repo.get_user(username) if user is not None: 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_repository_can_retrieve_reviews(in_memory_repo): assert len(in_memory_repo.get_reviews()) == 0 user = User('Nina', '123456789') in_memory_repo.add_user(user) user = in_memory_repo.get_user('Nina') movie = in_memory_repo.get_movie(2) review = make_review(review_text="This movie was average", user=user, movie=movie) in_memory_repo.add_review(review) assert len(in_memory_repo.get_reviews()) == 1
def user(): return User('taylor', '123456789')
def remove_from_watchlist(self, movie: Movie, user: User): if movie in user.watchlist: user.remove_from_watchlist(movie)
def add_to_watchlist(self, movie: Movie, user: User): if movie not in user.watchlist: user.add_to_watchlist(movie)
def test_repository_can_add_a_user(in_memory_repo): user = User('wpking2', 'Alpha1234') in_memory_repo.add_user(user) assert in_memory_repo.get_user('wpking2') is user
def user(): return User('dbowie', '1234567890')
def test_repository_can_add_a_user(in_memory_repo): user = User('Dave', '123456789') in_memory_repo.add_user(user) assert in_memory_repo.get_user('Dave') is user