88import pytest_asyncio
99from fastapi .testclient import TestClient
1010from PIL import Image
11+ from pytest_mock import MockerFixture
1112
1213from app .core .groups .groups_type import GroupType
1314from app .core .users import models_users
2627 maximize_image ,
2728)
2829from tests .commons import (
30+ add_coredata_to_db ,
2931 add_object_to_db ,
3032 create_api_access_token ,
3133 create_user_with_groups ,
@@ -207,6 +209,14 @@ async def init_objects() -> None:
207209 "data/raid/" + path ,
208210 )
209211
212+ await add_coredata_to_db (
213+ coredata_raid .RaidPrice (
214+ student_price = 50 ,
215+ t_shirt_price = 15 ,
216+ external_price = 90 ,
217+ ),
218+ )
219+
210220
211221def test_get_participant_by_id (client : TestClient ):
212222 response = client .get (
@@ -638,7 +648,7 @@ def test_get_raid_price(client: TestClient):
638648
639649
640650def test_update_raid_price (client : TestClient ):
641- price_data = {"student_price" : 50 , "t_shirt_price" : 15 }
651+ price_data = {"student_price" : 50 , "t_shirt_price" : 15 , "external_price" : 90 }
642652 response = client .patch (
643653 "/raid/price" ,
644654 json = price_data ,
@@ -664,40 +674,38 @@ def test_delete_team(client: TestClient):
664674 assert response .status_code == 204
665675
666676
667- async def test_get_payment_url_no_participant (client : TestClient , mocker ):
677+ async def test_get_payment_url_no_participant (
678+ client : TestClient ,
679+ mocker : MockerFixture ,
680+ ):
668681 # Mock the necessary dependencies
669682 mocker .patch ("app.modules.raid.cruds_raid.get_participant_by_id" , return_value = None )
670- mocker .patch (
671- "app.utils.tools.get_core_data" ,
672- return_value = coredata_raid .RaidPrice (student_price = 50 , t_shirt_price = 15 ),
673- )
674683
675684 mocker .patch ("app.modules.raid.cruds_raid.create_participant_checkout" )
676685
677686 response = client .get (
678687 "/raid/pay" ,
679688 headers = {"Authorization" : f"Bearer { token_simple } " },
680689 )
681- assert response .status_code == 201
682- assert "url" in response .json ()
683- assert response .json ()["url" ] == "https://some.url.fr/checkout"
690+ assert response .status_code == 404
691+ assert response .json ()["detail" ] == "Participant not found."
684692
685693
686- async def test_get_payment_url_participant_no_payment (client : TestClient , mocker ):
687- # Mock the necessary dependencies
694+ async def test_get_payment_url_participant_no_payment (
695+ client : TestClient ,
696+ mocker : MockerFixture ,
697+ ):
698+ # Mock the necessary dependencies test_get_payment_url_participant_already_paid
688699 mocker .patch (
689700 "app.modules.raid.cruds_raid.get_participant_by_id" ,
690701 return_value = Mock (
691702 payment = False ,
692703 t_shirt_size = None ,
693704 t_shirt_payment = False ,
694705 id = str (uuid .uuid4 ()),
706+ validation_progress = 100 ,
695707 ),
696708 )
697- mocker .patch (
698- "app.utils.tools.get_core_data" ,
699- return_value = coredata_raid .RaidPrice (student_price = 50 , t_shirt_price = 15 ),
700- )
701709
702710 mocker .patch ("app.modules.raid.cruds_raid.create_participant_checkout" )
703711
@@ -710,7 +718,10 @@ async def test_get_payment_url_participant_no_payment(client: TestClient, mocker
710718 assert response .json ()["url" ] == "https://some.url.fr/checkout"
711719
712720
713- async def test_get_payment_url_participant_with_tshirt (client : TestClient , mocker ):
721+ async def test_get_payment_url_participant_with_tshirt (
722+ client : TestClient ,
723+ mocker : MockerFixture ,
724+ ):
714725 # Mock the necessary dependencies
715726 mocker .patch (
716727 "app.modules.raid.cruds_raid.get_participant_by_id" ,
@@ -719,12 +730,10 @@ async def test_get_payment_url_participant_with_tshirt(client: TestClient, mocke
719730 t_shirt_size = Mock (value = "L" ),
720731 t_shirt_payment = False ,
721732 id = str (uuid .uuid4 ()),
733+ validation_progress = 100 ,
722734 ),
723735 )
724- mocker .patch (
725- "app.utils.tools.get_core_data" ,
726- return_value = coredata_raid .RaidPrice (student_price = 50 , t_shirt_price = 15 ),
727- )
736+
728737 mocker .patch (
729738 "app.core.payment.payment_tool.PaymentTool.init_checkout" ,
730739 return_value = Mock (
@@ -743,26 +752,32 @@ async def test_get_payment_url_participant_with_tshirt(client: TestClient, mocke
743752 assert response .json ()["url" ] == "https://some.url.fr/checkout"
744753
745754
746- # async def test_get_payment_url_prices_not_set(client: TestClient, mocker):
747- # # Mock the necessary dependencies
748- # mocker.patch(
749- # "app.utils.tools.get_core_data",
750- # return_value=coredata_raid.RaidPrice(student_price=None, t_shirt_price=None),
751- # )
752- # mocker.patch(
753- # "app.core.payment.payment_tool.PaymentTool.init_checkout",
754- # return_value=Mock(id=str(uuid.uuid4()), payment_url="http://mock-url.com"),
755- # )
755+ async def test_get_payment_url_prices_not_set (
756+ client : TestClient ,
757+ mocker : MockerFixture ,
758+ ):
759+ # Mock the necessary dependencies
760+ mocker .patch (
761+ "app.modules.raid.endpoints_raid.get_core_data" ,
762+ return_value = coredata_raid .RaidPrice (student_price = None , t_shirt_price = None ),
763+ )
764+ mocker .patch (
765+ "app.core.payment.payment_tool.PaymentTool.init_checkout" ,
766+ return_value = Mock (id = str (uuid .uuid4 ()), payment_url = "http://mock-url.com" ),
767+ )
756768
757- # response = client.get(
758- # "/raid/pay",
759- # headers={"Authorization": f"Bearer {token_simple}"},
760- # )
761- # assert response.status_code == 404
762- # assert response.json()["detail"] == "Prices not set."
769+ response = client .get (
770+ "/raid/pay" ,
771+ headers = {"Authorization" : f"Bearer { token_simple } " },
772+ )
773+ assert response .status_code == 404
774+ assert response .json ()["detail" ] == "Prices not set."
763775
764776
765- async def test_get_payment_url_participant_already_paid (client : TestClient , mocker ):
777+ async def test_get_payment_url_participant_already_paid (
778+ client : TestClient ,
779+ mocker : MockerFixture ,
780+ ):
766781 # Mock the necessary dependencies
767782 mocker .patch (
768783 "app.modules.raid.cruds_raid.get_participant_by_id" ,
@@ -771,12 +786,9 @@ async def test_get_payment_url_participant_already_paid(client: TestClient, mock
771786 t_shirt_size = None ,
772787 t_shirt_payment = True ,
773788 id = str (uuid .uuid4 ()),
789+ validation_progress = 100 ,
774790 ),
775791 )
776- mocker .patch (
777- "app.utils.tools.get_core_data" ,
778- return_value = coredata_raid .RaidPrice (student_price = 50 , t_shirt_price = 15 ),
779- )
780792
781793 mocker .patch ("app.modules.raid.cruds_raid.create_participant_checkout" )
782794
@@ -967,7 +979,9 @@ def test_html_pdf_writer_init():
967979# assert result == f"data/raid/{mock_participant.id}.pdf"
968980
969981
970- async def test_set_team_number_utility_empty_database (mocker ):
982+ async def test_set_team_number_utility_empty_database (
983+ mocker : MockerFixture ,
984+ ):
971985 """Test the set_team_number utility with an empty database (no existing teams)"""
972986 # Create mock objects
973987 mock_db = mocker .AsyncMock ()
@@ -998,7 +1012,9 @@ async def test_set_team_number_utility_empty_database(mocker):
9981012 assert args [1 ].number == 101 # 100 (sports separator) + 1
9991013
10001014
1001- async def test_set_team_number_utility_existing_teams (mocker ):
1015+ async def test_set_team_number_utility_existing_teams (
1016+ mocker : MockerFixture ,
1017+ ):
10021018 """Test the set_team_number utility with existing teams"""
10031019 # Create mock objects
10041020 mock_db = mocker .AsyncMock ()
@@ -1029,7 +1045,9 @@ async def test_set_team_number_utility_existing_teams(mocker):
10291045 assert args [1 ].number == 221 # 220 + 1
10301046
10311047
1032- async def test_set_team_number_utility_no_difficulty (mocker ):
1048+ async def test_set_team_number_utility_no_difficulty (
1049+ mocker : MockerFixture ,
1050+ ):
10331051 """Test the set_team_number utility with a team without difficulty"""
10341052 # Create mock objects
10351053 mock_db = mocker .AsyncMock ()
@@ -1051,7 +1069,9 @@ async def test_set_team_number_utility_no_difficulty(mocker):
10511069 mock_update_team .assert_not_called ()
10521070
10531071
1054- async def test_set_team_number_utility_discovery_difficulty (mocker ):
1072+ async def test_set_team_number_utility_discovery_difficulty (
1073+ mocker : MockerFixture ,
1074+ ):
10551075 """Test the set_team_number utility with discovery difficulty"""
10561076 # Create mock objects
10571077 mock_db = mocker .AsyncMock ()
0 commit comments