Exemplo n.º 1
0
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()
    )
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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:')
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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')
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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:')
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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:")
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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 != []
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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'),
    )
Exemplo n.º 19
0
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
Exemplo n.º 20
0
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(),
    )
Exemplo n.º 21
0
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
Exemplo n.º 22
0
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)
Exemplo n.º 23
0
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)
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
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)