Coverage for src/tests/api/v1/trainings/coaches/test_coaches.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing the api/v1/trainings/coaches endpoints.""" 

2 

3import pytest 

4 

5from fastapi import status 

6from fastapi.testclient import TestClient 

7 

8 

9pytestmark = pytest.mark.api 

10 

11 

12def test_get_coaches(secure_client: TestClient): 

13 """Test get coaches api.""" 

14 response = secure_client.get("/api/v1/trainings/coaches") 

15 assert response.status_code == status.HTTP_200_OK 

16 

17 

18async def test_get_coaches_from_training( 

19 secure_client: TestClient, make_training_in_db 

20): 

21 """Test get coaches from training api.""" 

22 training = await make_training_in_db() 

23 response = secure_client.get(f"/api/v1/trainings/{training.id}/coaches") 

24 assert response.status_code == status.HTTP_200_OK 

25 

26 

27async def test_add_coach( 

28 secure_client: TestClient, make_training_in_db, make_coach_in_db 

29): 

30 """Test add coach to a training.""" 

31 training = await make_training_in_db() 

32 coach = await make_coach_in_db() 

33 response = secure_client.post( 

34 f"/api/v1/trainings/{training.id}/coaches", 

35 json={ 

36 "data": { 

37 "type": "training_coaches", 

38 "attributes": { 

39 "payed": False, 

40 "present": False, 

41 "head": True, 

42 "remark": "", 

43 }, 

44 "relationships": { 

45 "coach": { 

46 "data": { 

47 "type": "coaches", 

48 "id": str(coach.uuid), 

49 } 

50 } 

51 }, 

52 } 

53 }, 

54 ) 

55 assert response.status_code == status.HTTP_201_CREATED 

56 

57 

58async def test_delete_coach( 

59 secure_client: TestClient, make_training_in_db, make_coach_in_db 

60): 

61 """Test delete a coach.""" 

62 training = await make_training_in_db() 

63 training_coach = list(training.coaches)[0] 

64 response = secure_client.delete( 

65 f"/api/v1/trainings/{training.id}/coaches/{training_coach.coach.uuid}" 

66 ) 

67 assert response.status_code == status.HTTP_200_OK