Coverage for src/tests/api/v1/club/coaches/test_endpoints.py: 100%
22 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module for testing the coaches endpoints of the club API."""
3import pytest
5from fastapi import status
6from fastapi.testclient import TestClient
9pytestmark = [pytest.mark.api, pytest.mark.db]
12def test_get_coaches(secure_client: TestClient):
13 """Test GET /api/v1/club/coaches endpoint."""
14 response = secure_client.get("/api/v1/club/coaches")
15 assert response.status_code == status.HTTP_200_OK
18async def test_create_coach(secure_client: TestClient, make_member_in_db):
19 """Test POST /api/v1/club/coaches endpoint."""
20 member = await make_member_in_db()
21 payload = {
22 "data": {
23 "type": "coaches",
24 "attributes": {
25 "name": str(member.name),
26 "description": "Test Coach",
27 "diploma": "Initiator",
28 "active": True,
29 "remark": "",
30 },
31 "relationships": {
32 "member": {"data": {"type": "members", "id": str(member.uuid)}},
33 "user": {"data": None},
34 },
35 }
36 }
37 response = secure_client.post("/api/v1/club/coaches", json=payload)
38 assert response.status_code == status.HTTP_201_CREATED
41async def test_duplicate_coach(secure_client: TestClient, make_coach_in_db):
42 """Test POST /api/v1/club/coaches endpoint for already existing coach."""
43 coach = await make_coach_in_db()
44 payload = {
45 "data": {
46 "type": "coaches",
47 "attributes": {
48 "name": str(coach.member.name),
49 "description": "Test Coach",
50 "diploma": "Initiator",
51 "active": True,
52 "remark": "Updated",
53 },
54 "relationships": {
55 "member": {"data": {"type": "members", "id": str(coach.member.uuid)}},
56 "user": {"data": None},
57 },
58 }
59 }
60 response = secure_client.post("/api/v1/club/coaches", json=payload)
61 assert response.status_code == status.HTTP_409_CONFLICT
64async def test_update_coach(secure_client: TestClient, make_coach_in_db):
65 """Test PATCH /api/v1/club/coaches endpoint."""
66 coach = await make_coach_in_db()
67 payload = {
68 "data": {
69 "type": "coaches",
70 "attributes": {
71 "name": str(coach.member.name),
72 "description": "Test Coach",
73 "diploma": "Initiator",
74 "active": True,
75 "remark": "Updated",
76 },
77 "relationships": {
78 "member": {"data": {"type": "members", "id": str(coach.member.uuid)}},
79 "user": {"data": None},
80 },
81 }
82 }
83 response = secure_client.patch(f"/api/v1/club/coaches/{coach.id}", json=payload)
84 assert response.status_code == status.HTTP_200_OK