Coverage for src/tests/api/v1/club/coaches/test_endpoints.py: 100%

26 statements  

« 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.""" 

2 

3import pytest 

4 

5from fastapi import status 

6from fastapi.testclient import TestClient 

7 

8 

9pytestmark = [pytest.mark.api, pytest.mark.db] 

10 

11 

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 

16 

17 

18async def test_get_coach(secure_client: TestClient, make_coach_in_db): 

19 """Test GET /api/v1/club/coaches/<uuid> endpoint.""" 

20 coach = await make_coach_in_db() 

21 response = secure_client.get(f"/api/v1/club/coaches/{coach.uuid}") 

22 assert response.status_code == status.HTTP_200_OK 

23 

24 

25async def test_create_coach(secure_client: TestClient, make_member_in_db): 

26 """Test POST /api/v1/club/coaches endpoint.""" 

27 member = await make_member_in_db() 

28 payload = { 

29 "data": { 

30 "type": "coaches", 

31 "attributes": { 

32 "name": str(member.name), 

33 "description": "Test Coach", 

34 "diploma": "Initiator", 

35 "active": True, 

36 "head": False, 

37 "remark": "", 

38 }, 

39 "relationships": { 

40 "member": {"data": {"type": "members", "id": str(member.uuid)}}, 

41 "user": {"data": None}, 

42 }, 

43 } 

44 } 

45 response = secure_client.post("/api/v1/club/coaches", json=payload) 

46 assert response.status_code == status.HTTP_201_CREATED 

47 

48 

49async def test_duplicate_coach(secure_client: TestClient, make_coach_in_db): 

50 """Test POST /api/v1/club/coaches endpoint for already existing coach.""" 

51 coach = await make_coach_in_db() 

52 payload = { 

53 "data": { 

54 "type": "coaches", 

55 "attributes": { 

56 "name": str(coach.member.name), 

57 "description": "Test Coach", 

58 "diploma": "Initiator", 

59 "active": True, 

60 "head": False, 

61 "remark": "Updated", 

62 }, 

63 "relationships": { 

64 "member": {"data": {"type": "members", "id": str(coach.member.uuid)}}, 

65 "user": {"data": None}, 

66 }, 

67 } 

68 } 

69 response = secure_client.post("/api/v1/club/coaches", json=payload) 

70 assert response.status_code == status.HTTP_409_CONFLICT 

71 

72 

73async def test_update_coach(secure_client: TestClient, make_coach_in_db): 

74 """Test PATCH /api/v1/club/coaches endpoint.""" 

75 coach = await make_coach_in_db() 

76 payload = { 

77 "data": { 

78 "type": "coaches", 

79 "attributes": { 

80 "name": str(coach.member.name), 

81 "description": "Test Coach", 

82 "diploma": "Initiator", 

83 "active": True, 

84 "remark": "Updated", 

85 "head": False, 

86 }, 

87 "relationships": { 

88 "member": {"data": {"type": "members", "id": str(coach.member.uuid)}}, 

89 "user": {"data": None}, 

90 }, 

91 } 

92 } 

93 response = secure_client.patch(f"/api/v1/club/coaches/{coach.uuid}", json=payload) 

94 assert response.status_code == status.HTTP_200_OK, response.text