Skip to content

Commit

Permalink
Merge pull request #236 from kristhina/214_tests_for_edit_paticipant_…
Browse files Browse the repository at this point in the history
…endpoint

tests for edit participant endpoint (fixes #214)
  • Loading branch information
jacekkalbarczyk authored Feb 19, 2020
2 parents d5c7690 + eba1074 commit 93e04f4
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions backend/tests/test_participant_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,41 @@ def test_get_delete_participant_when_logged_in(
assert response["message"] == "Participant deleted successfully."


@pytest.mark.parametrize("method", ["get", "delete"])
def test_get_delete_non_existing_participant(
def test_put_participant_when_logged_in(app, auth_client, add_participants):
"""Test put participant details for logged in user and valid data."""
with app.app_context():
payload = {"last_name": "TestTest", "email": "[email protected]"}
rv = auth_client.put("/participants/1/", json=payload,)
response = rv.get_json()
schema = ParticipantSchema()
participant = schema.dump(Participant.query.first())
assert rv.status_code == HTTPStatus.OK
assert response["last_name"] == payload["last_name"]
assert response["email"] == payload["email"]
assert participant["last_name"] == payload["last_name"]


def test_put_participant_with_invalid_data(auth_client):
"""Test try to edit participant with invalid email address."""
payload = {"last_name": "TestTest", "email": "test"}
rv = auth_client.post("/participants/", json=payload,)
response = rv.get_json()
assert rv.status_code == HTTPStatus.BAD_REQUEST
assert "Not a valid email address." in response["email"]


@pytest.mark.parametrize("method", ["get", "delete", "put"])
def test_get_delete_put_non_existing_participant(
client, auth_client, add_participants, method
):
"""Test get and delete non-existing participant."""
"""Test get, put and delete non-existing participant."""
rv = getattr(auth_client, method)("/participants/11/")
assert rv.status_code == HTTPStatus.NOT_FOUND


@pytest.mark.parametrize("method", ["get", "delete"])
def test_get_delete_participant_unauthorized(client, add_participants, method):
"""Test get and delete participant with not logged in user."""
@pytest.mark.parametrize("method", ["get", "delete", "put"])
def test_get_delete_put_participant_unauthorized(client, add_participants, method):
"""Test get, put and delete participant with not logged in user."""
rv = client.get("/participants/1/")
response = rv.get_json()
assert rv.status_code == HTTPStatus.UNAUTHORIZED
Expand Down

0 comments on commit 93e04f4

Please sign in to comment.