def test_anonymous_user_should_be_redirected_on_login_page_when_create_review(
        client, db):
    helpers.insert_complete_restaurant(db)

    res = create_review(client, redirect=False)

    assert res.status_code == 302
    assert urlparse(res.location).path == "/login/user"
def test_anonymous_user_should_see_review_form(client, db):
    helpers.insert_complete_restaurant(db)

    res = visit_restaurant_page(client)

    assert res.status_code == 200
    assert b"Add your review" in res.data
    assert b"Your rating" in res.data
    assert b"Your review" in res.data
def test_operator_should_not_create_review(client, db):
    helpers.create_operator(client)
    helpers.login_operator(client)
    helpers.insert_complete_restaurant(db)

    res = create_review(client)

    assert res.status_code == 200
    assert b"Only a logged user can review a restaurant." in res.data
def test_user_should_create_review_if_already_did(client, db):
    helpers.create_user(client)
    helpers.login_user(client)
    helpers.insert_complete_restaurant(db)

    create_review(client)
    res = create_review(client, rating=3)

    assert res.status_code == 200
    assert b"You already reviewed this restaraunt"
def test_operator_should_not_see_the_review_form(client, db):
    helpers.create_operator(client)
    helpers.login_operator(client)
    helpers.insert_complete_restaurant(db)

    res = visit_restaurant_page(client)

    assert res.status_code == 200
    assert b"Add your review" not in res.data
    assert b"Your rating" not in res.data
    assert b"Your review" not in res.data
def test_user_should_create_review(client, db):
    helpers.create_user(client)
    helpers.login_user(client)
    helpers.insert_complete_restaurant(db)

    res = create_review(client)

    assert res.status_code == 200
    assert b"mario" in res.data
    assert b"5" in res.data
    assert (
        b"It was a delicious dinner, but initially the service was not so excellent in the speed of serving the meals."
        in res.data)
def test_user_should_not_create_review_when_message_is_less_than_30_character(
        client, db):
    helpers.create_user(client)
    helpers.login_user(client)
    helpers.insert_complete_restaurant(db)

    res = client.post(
        "/restaurants/1",
        data=dict(rating=4, message="It was a"),
        follow_redirects=True,
    )

    assert res.status_code == 200
    assert b"The review should be at least of 30 characters." in res.data