def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to attempt to add the new user. try: services.add_user(form.username.data, form.password.data, repo.repo_instance) # All is well, redirect the user to the login page. return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = 'Your username is already taken - please supply another' # For a GET or a failed POST request, return the Registration Web page. return render_template( 'authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, handler_url=url_for('authentication_bp.register'), selected_movies=utilities.get_selected_movies(), genre_urls=utilities.get_genres_and_urls() )
def test_cannot_add_user_with_existing_name(in_memory_repo): username = '******' password = '******' auth_services.add_user(username, password, in_memory_repo) with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user(username, password, in_memory_repo)
def test_authentication_with_invalid_credentials(in_memory_repo): username = '******' password = '******' auth_services.add_user(username, password, in_memory_repo) with pytest.raises(AuthenticationException): auth_services.authenticate_user(username, "abcdefg", in_memory_repo)
def test_authentication_with_invalid_credentials(in_memory_repo): username = '******' password = '******' auth_services.add_user(username, password, in_memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(username, 'abcd1A234', in_memory_repo)
def test_can_add_user(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) user_as_dict = auth_services.get_user(new_username, in_memory_repo) assert user_as_dict['username'] == new_username assert user_as_dict['password'].startswith('pbkdf2:sha256:')
def test_authentication_with_valid_credentials(in_memory_repo): username = '******' password = '******' auth_services.add_user(username, password, in_memory_repo) try: auth_services.authenticate_user(username, password, in_memory_repo) except AuthenticationException: assert False
def test_can_add_user(in_memory_repo): username = "******" password = "******" auth_services.add_user(username, password, in_memory_repo) user_as_dict = auth_services.get_user(username, in_memory_repo) assert user_as_dict["username"] == username assert user_as_dict["password"].startswith('pbkdf2:sha256')
def test_auth_with_valid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) try: auth_services.authenticate_user(new_username, new_password, in_memory_repo) except: assert False
def test_can_add_user(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) user_as_dict = auth_services.get_user(new_username, in_memory_repo) assert user_as_dict['username'] == new_username # Check that password has been encrypted. assert user_as_dict['password'].startswith('pbkdf2:sha256:')
def test_cannot_add_review_for_non_existent_movie(in_memory_repo): movie_id = 1001 review_text = "good film" new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) # Call the service layer to attempt to add the comment. with pytest.raises(movie_library_services.NonExistentMovieException): movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo)
def test_can_add_user(in_memory_repo): username = "******" password = '******' auth_services.add_user(username, password, in_memory_repo) user = auth_services.get_user(username, in_memory_repo) assert user['username'] == username # Check password is encrypted assert user['password'].startswith("pbkdf2:sha256:")
def test_cannot_add_comment_for_non_existent_movie(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) mov_title = 'abcsac' comment_text = "what's that movie?" username = '******' # Call the service layer to attempt to add the comment. with pytest.raises(movs_services.NonExistentMovieException): movs_services.add_review(mov_title, comment_text, username, in_memory_repo)
def text_cannot_add_review_for_non_existent_movie(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_title = "fake movie" review_text = "Lots of carnage" rating = 7 with pytest.raises(NonExistentMovieException): movies_services.add_review(movie_title, review_text, new_username, rating, in_memory_repo)
def test_get_reviews_for_movie(in_memory_repo): movie_id = 1 review_text = "Good as movie" new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo) reviews_as_dict = movie_library_services.get_reviews_for_movie( 1, in_memory_repo) assert len(reviews_as_dict) == 1 # Check that the review relates to the movie whose id is 1. movie_ids = [review['movie_id'] for review in reviews_as_dict] movie_ids = set(movie_ids) assert 1 in movie_ids and len(movie_ids) == 1
def test_can_add_comment(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_title = '21' comment_text = 'The loonies are stripping the supermarkets bare!' username = '******' # Call the service layer to add the comment. movs_services.add_review(movie_title, comment_text, username, in_memory_repo) # Retrieve the comments for the article from the repository. comments_as_dict = movs_services.get_reviews_for_movie(movie_title, in_memory_repo) # Check that the comments include a comment with the new comment text. assert comments_as_dict != []
def test_can_add_review(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_title = "Suicide Squad" review_text = "Lots of carnage" rating = 7 movies_services.add_review(movie_title, review_text, new_username, rating, in_memory_repo) reviews_as_dict = movies_services.get_reviews_for_movie( movie_title, in_memory_repo) assert next((dictionary['review_text'] for dictionary in reviews_as_dict if dictionary['review_text'] == review_text), None) is not None
def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): try: services.add_user(form.username.data, form.password.data, repo.repo_instance) return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = "Your username is already taken - please supply another" # For a GET or a failed POST request, return the Registration Web page. return render_template( 'authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, handler_url=url_for('authentication_bp.register'), )
def test_can_add_review(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_id = 3 review_text = 'Average movie' # Call the service layer to add the review. movie_library_services.add_review(movie_id, review_text, new_username, in_memory_repo) # Retrieve the review for the movie from the repository. reviews_as_dict = movie_library_services.get_reviews_for_movie( movie_id, in_memory_repo) # Check that the review includes a review with the new review text. assert next((dictionary['review_text'] for dictionary in reviews_as_dict if dictionary['review_text'] == review_text), None) is not None
def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): try: services.add_user(form.username.data, form.password.data, repo.repo_instance) return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = 'Username is already taken' return render_template( 'authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, password_error_message=None, handler_url=url_for('authentication_bp.register'), movieSearch=movies.movieByTitle(), )
def test_get_reviews_for_movie(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) movie_title = "Suicide Squad" review_text = "Lots of carnage" rating = 7 movies_services.add_review(movie_title, review_text, new_username, rating, in_memory_repo) reviews_as_dict = movies_services.get_reviews_for_movie( movie_title, in_memory_repo) reviews_as_dict = movies_services.get_reviews_for_movie( "Suicide Squad", in_memory_repo) assert len(reviews_as_dict) == 1 movies = [review['movie'].title for review in reviews_as_dict] assert movie_title in movies and len(movies) == 1
def test_cannot_add_user_with_existing_name(in_memory_repo): username = '******' password = "******" with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user(username, password, in_memory_repo)
def test_cannot_add_user_with_existing_name(in_memory_repo): auth_services.add_user("thorke", "Copycat112", in_memory_repo) with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user('thorke', "abcd1A23", in_memory_repo)
def test_add_user(repository): assert len(repository.get_users()) == 2 services.add_user("Scott Phillips", "789", repository) assert len(repository.get_users()) == 3 with pytest.raises(services.NameNotUniqueException): services.add_user("Myles Kennedy", "123", repository)
def test_authenticate_user(repository): services.add_user("Scott Phillips", "789", repository) services.authenticate_user("Scott Phillips", "789", repository) with pytest.raises(services.AuthenticationException): services.authenticate_user("Mark Tremonti", "234", repository)