コード例 #1
0
def test_movie_review(client, auth):
    '''
    - A beginning implementation is already provided to check 
    if the movie detail page for the 'Guardians of the Galaxy'
    page will show up. The choice of this id is arbitrary, and 
    you can change it to something else if you want.
    - Register and login. 
    - Submit a movie review with a randomly generated string 
    (to make sure that you're adding a truly unique review)
    - Test that the review shows up on the page
    - Test that the review is saved in the database
    '''
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)
    assert resp.status_code == 200
    auth.register()
    auth.login()
    # CREATE FORM WITH OUR TEST REVIEW
    content = "!!!HERE-IS-MY-REVIEW-FOR-TESTING!!!"
    review = SimpleNamespace(text=content, submit="Enter Comment")
    form = MovieReviewForm(formdata=None, obj=review)
    resp = client.post(url, data=form.data, follow_redirects=True)
    # CHECK THAT content SHOWS UP IN HTML.
    assert str.encode(content) in resp.data
    # CHECK THAT REVIEW WITH content SHOWS UP IN DB.
    db_review = Review.objects(content=content).first()
    assert db_review is not None
コード例 #2
0
def test_movie_review_input_validation(client, auth, comment, message):
    # %%%%%% TESTING GUARDIANS OF THE GALAXY %%%%%%
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)

    assert resp.status_code == 200

    # %%%%%% REGISTER AND LOGIN %%%%%%
    auth.register(username="******",
                  email="*****@*****.**",
                  passwrd="pytesting",
                  confirm="pytesting")
    auth.login(username="******", password="******")

    resp = client.get(url)
    assert resp.status_code == 200

    review_input = SimpleNamespace(text=comment, submit="Enter Comment")

    form = MovieReviewForm(formdata=None, obj=review_input)
    response = client.post(url, data=form.data, follow_redirects=True)

    assert response.status_code == 200

    assert message in response.data
コード例 #3
0
def test_movie_review(client, auth):
    # %%%%%% TESTING GUARDIANS OF THE GALAXY %%%%%%
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)

    assert resp.status_code == 200

    # %%%%%% REGISTER AND LOGIN %%%%%%
    auth.register(username="******",
                  email="*****@*****.**",
                  passwrd="pytesting",
                  confirm="pytesting")
    auth.login(username="******", password="******")

    # %%%%%% RANDOM STRING %%%%%%
    letters = string.ascii_lowercase
    random_str = ''.join(random.choice(letters) for i in range(42))

    # %%%%%% REVIEWING %%%%%%
    resp = client.get(url)
    assert resp.status_code == 200

    review_input = SimpleNamespace(text=random_str, submit="Enter Comment")
    form = MovieReviewForm(formdata=None, obj=review_input)
    response = client.post(url, data=form.data, follow_redirects=True)
    assert response.status_code == 200
    assert bytes(random_str, 'utf-8') in response.data

    # %%%%%% CHECKING IF IN DB %%%%%%
    reviews = Review.objects(imdb_id=guardians_id, content=random_str)
    assert len(reviews) >= 1
コード例 #4
0
def movie_detail(movie_id):
    try:
        mov = client.retrieve_movie_by_id(movie_id)
    except ValueError as ve:
        return render_template('movie_detail.html', error_msg=ve)

    if mov is not None:
        form = MovieReviewForm()
        if form.validate_on_submit():
            rev = {
                'commenter': form.name.data,
                'content': form.text.data,
                'date': current_time(),
                'imdb_id': movie_id,
            }
            mongo.db.reviews.insert_one(rev)
            return redirect(request.path)

        review = list(mongo.db.reviews.find({'imdb_id': mov.imdb_id}))
        return render_template('movie_detail.html',
                               movie=mov,
                               reviews=review,
                               form=form)
コード例 #5
0
def test_movie_review_input_validation(client, auth, comment, message):
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)

    assert resp.status_code == 200

    auth.register()
    auth.login()

    review = SimpleNamespace(text=comment, submit="Enter Comment")
    form = MovieReviewForm(formdata=None, obj=review)
    response = client.post(f"/movies/{guardians_id}",
                           data=form.data,
                           follow_redirects=True)

    assert message in response.data
コード例 #6
0
def test_movie_review(client, auth):
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)

    assert resp.status_code == 200

    auth.register()
    auth.login()

    testData = ''.join(
        random.choice(string.ascii_lowercase) for i in range(10))

    review = SimpleNamespace(text=testData, submit="Enter Comment")
    form = MovieReviewForm(formdata=None, obj=review)
    response = client.post(f"/movies/{guardians_id}",
                           data=form.data,
                           follow_redirects=True)

    assert bytes(testData, encoding='utf-8') in response.data
コード例 #7
0
def test_movie_review_input_validation(client, auth, comment, message):
    '''
    - This test checks whether the proper validation errors from MovieReviewForm
    are raised when you provide incorrect input.
    - Test that with an empty string, you get the error "This field is required"
    - Test that with (1) a string shorter than 5 characters and (2) a string longer
    than 500 characters, you get the error "Field must be between 5 and 500 characters long."
    - Hint: 'a' * 10 == 'aaaaaaaaaa'
    - You can use any movie id here, just make sure it's valid or your test will fail.
    '''
    guardians_id = "tt2015381"
    url = f"/movies/{guardians_id}"
    resp = client.get(url)
    assert resp.status_code == 200
    auth.register()
    auth.login()
    review = SimpleNamespace(text=comment, submit="Enter Comment")
    form = MovieReviewForm(formdata=None, obj=review)
    resp = client.post(url, data=form.data, follow_redirects=True)
    # CHECK THAT content SHOWS UP IN HTML.
    assert message in resp.data
    # CHECK THAT REVIEW WITH content DOES NOT SHOW UP IN DB.
    db_review = Review.objects(content=comment).first()
    assert db_review is None