-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from kristhina/214_tests_for_edit_paticipant_…
…endpoint tests for edit participant endpoint (fixes #214)
- Loading branch information
Showing
1 changed file
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|