Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for delete participant endpoint (fixes #193) #194

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions backend/tests/test_participant_details.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
from http import HTTPStatus

import pytest

from backend.models import Participant
from backend.serializers.participant_serializer import ParticipantSchema


def test_get_participant_when_logged_in(client, access_token, add_participants):
"""Test get participant details for logged in user."""
rv = client.get(
@pytest.mark.parametrize("method", ["get", "delete"])
def test_get_delete_participant_when_logged_in(
client, access_token, add_participants, method
):
"""Test get and delete participant details for logged in user."""
rv = getattr(client, method)(
"/participants/1/", headers={"Authorization": "Bearer {}".format(access_token)}
)
response = rv.get_json()
participant_schema = ParticipantSchema()
assert rv.status_code == HTTPStatus.OK
assert response == participant_schema.dump(Participant.query.get(1))
if method == "get":
assert response == participant_schema.dump(Participant.query.get(1))
else:
assert response["message"] == "Participant deleted successfully."


def test_get_non_existent_participant(client, access_token, add_participants):
"""Test get detais of non-existent participant"""
rv = client.get(
@pytest.mark.parametrize("method", ["get", "delete"])
def test_get_delete_non_existing_participant(
client, access_token, add_participants, method
):
"""Test get and delete non-existing participant."""
rv = getattr(client, method)(
"/participants/11/", headers={"Authorization": "Bearer {}".format(access_token)}
)
assert rv.status_code == HTTPStatus.NOT_FOUND


def test_get_participant_unauthorized(client, add_participants):
"""Test get participant details for not logged in user."""
@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."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove get from all the scenarios and ensure that we have explicit one for testing get method. Others will be eg.: "Test delete participant when user logged-in / logged-out".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make tests less readable, especially if we would merge #191. Following magul suggesion I introduced there logged in client fixture. So e.g. for testing get method I will have to inject two different test clients, which could be confussing.

rv = client.get("/participants/1/")
response = rv.get_json()
assert rv.status_code == HTTPStatus.UNAUTHORIZED
Expand Down