def test_repository_can_add_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = User('Dave', '123456789') print(user) repo.add_user(user) repo.add_user(User('Martin', '123456789')) user2 = repo.get_user('Dave') print(user2) assert user2 == user and user2 is user
def test_repository_can_add_a_review(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('thorke') movie = repo.get_movie_by_index(10) review = Review(user=user, movie=movie, review_text='Great!', rating=10, timestamp=date.today()) assert repo.get_total_number_of_reviews() == 4 assert review in repo.get_movie_reviews(movie) assert review in repo.get_user_reviews(user)
def test_repository_does_not_add_a_review_without_a_movie_properly_attached(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('thorke') movie = repo.get_movie_by_index(1) review = Review(user=user, movie=None, review_text="Awesome!", rating=10, timestamp=date.today()) with pytest.raises(RepositoryException): # Exception expected because the Review doesn't refer to the Movie repo.add_review(review)
def test_repository_does_not_retrieve_a_non_existent_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('prince') assert user is None
def test_repository_can_retrieve_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('fmercury') assert user == User('fmercury', '8734gfe2058v')