From c84d8729273bb43aa3db3baa7346d647d9a17e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= Date: Wed, 27 Mar 2024 15:20:10 +0100 Subject: [PATCH] before rendu --- Makefile | 9 ++ PROJET.md | 4 +- athlete/__pycache__/app.cpython-311.pyc | Bin 8825 -> 0 bytes athlete/__pycache__/athlete.cpython-311.pyc | Bin 3465 -> 0 bytes .../conftest.cpython-311-pytest-8.1.1.pyc | Bin 1852 -> 0 bytes athlete/athlete.py | 2 +- athlete/conftest.py | 1 + ...st_delAthlete.cpython-311-pytest-8.1.1.pyc | Bin 2132 -> 2132 bytes ...st_getAthlete.cpython-311-pytest-8.1.1.pyc | Bin 2916 -> 2916 bytes ..._listeAthlete.cpython-311-pytest-8.1.1.pyc | Bin 11730 -> 11730 bytes ..._ping_athlete.cpython-311-pytest-8.1.1.pyc | Bin 1451 -> 1451 bytes ...t_postAthlete.cpython-311-pytest-8.1.1.pyc | Bin 3084 -> 3084 bytes .../conftest.cpython-311-pytest-8.1.1.pyc | Bin 1881 -> 0 bytes .../__pycache__/discipline.cpython-311.pyc | Bin 3191 -> 0 bytes discipline/app.py | 11 +- discipline/{discipline.py => models.py} | 10 +- .../conftest.cpython-311-pytest-8.1.1.pyc | Bin 1250 -> 0 bytes ...st_delAthlete.cpython-311-pytest-8.1.1.pyc | Bin 2132 -> 0 bytes ...delDiscipline.cpython-311-pytest-8.1.1.pyc | Bin 2141 -> 2141 bytes ...st_getAthlete.cpython-311-pytest-8.1.1.pyc | Bin 2916 -> 0 bytes ...getDiscipline.cpython-311-pytest-8.1.1.pyc | Bin 3065 -> 3068 bytes .../test_gettest.cpython-311-pytest-8.1.1.pyc | Bin 1462 -> 0 bytes ..._listeAthlete.cpython-311-pytest-8.1.1.pyc | Bin 11730 -> 0 bytes ...steDiscipline.cpython-311-pytest-8.1.1.pyc | Bin 4072 -> 4086 bytes .../test_ping.cpython-311-pytest-8.1.1.pyc | Bin 1435 -> 0 bytes ...ng_discipline.cpython-311-pytest-8.1.1.pyc | Bin 1460 -> 1460 bytes ...t_postAthlete.cpython-311-pytest-8.1.1.pyc | Bin 3084 -> 0 bytes ...ostDiscipline.cpython-311-pytest-8.1.1.pyc | Bin 3248 -> 3251 bytes discipline/tests/test_getDiscipline.py | 2 +- discipline/tests/test_listeDiscipline.py | 8 +- discipline/tests/test_postDiscipline.py | 2 +- .../conftest.cpython-311-pytest-8.1.1.pyc | Bin 1858 -> 0 bytes medaille/app.py | 118 +++++++++--------- medaille/models.py | 60 +++++++++ medaille/static/swagger.yaml | 9 +- medaille/tests/test_delMedaille.py | 6 + medaille/tests/test_getMedaille.py | 13 ++ medaille/tests/test_listeMedaille.py | 8 ++ medaille/tests/test_ping_medaille.py | 3 + medaille/tests/test_postMedaille.py | 30 +++++ sample/disciplines.json | 4 +- sample/medailles.json | 44 +++++++ 42 files changed, 261 insertions(+), 83 deletions(-) create mode 100644 Makefile delete mode 100644 athlete/__pycache__/app.cpython-311.pyc delete mode 100644 athlete/__pycache__/athlete.cpython-311.pyc delete mode 100644 athlete/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/__pycache__/discipline.cpython-311.pyc rename discipline/{discipline.py => models.py} (82%) delete mode 100644 discipline/tests/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_delAthlete.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_getAthlete.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_gettest.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_listeAthlete.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_ping.cpython-311-pytest-8.1.1.pyc delete mode 100644 discipline/tests/__pycache__/test_postAthlete.cpython-311-pytest-8.1.1.pyc delete mode 100644 medaille/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc create mode 100644 medaille/models.py create mode 100644 medaille/tests/test_delMedaille.py create mode 100644 medaille/tests/test_getMedaille.py create mode 100644 medaille/tests/test_listeMedaille.py create mode 100644 medaille/tests/test_ping_medaille.py create mode 100644 medaille/tests/test_postMedaille.py create mode 100644 sample/medailles.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1828e92 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: test + +test: + pytest -v ./athlete/tests + pytest -v ./medaille/tests + pytest -v ./discipline/tests + +clear_before_rendreTP: + rm -rf ./data ./__pycache__ ./athlete/__pycache__ ./medaille/__pycache__ ./discipline/__pycache__ \ No newline at end of file diff --git a/PROJET.md b/PROJET.md index 12fe38c..38d2423 100644 --- a/PROJET.md +++ b/PROJET.md @@ -34,7 +34,9 @@ python app.py ## How to test ```bash -pytest -vvv . +pytest -v athlete/tests +pytest -v discipline/tests +pytest -v medaille/tests ``` ## How to build the docker images diff --git a/athlete/__pycache__/app.cpython-311.pyc b/athlete/__pycache__/app.cpython-311.pyc deleted file mode 100644 index 99dcc32be7f70e133113744ac97a9509f7f3a2e0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8825 zcmdT}YiJzT6~6P>_pB^w^sppLSwCcX^_HKBBs;Yw`4vYsmfaBHRID{4Y1jKuW=3`_ zVUvd(&B#`oPhDKo_lw9c4t?z zWYZFIcjoM!d+#~-G3R{u+%tdldff<8q=p^aSBlWT@IyA)Gnq%b8H7GS0urb&icrH; zgdV0N%rHaYGCIsgY{NE^XTtVjJCw0uN5nbojJSqfq}&#EM?AxxOdD>Pqmf97-rE#H zAH$ta!zED4g*IiM1v@<3#8PXkP+7JN!!6mrIskjFV} z0r{fg2+6T%aO{fVki<8qL|O4u275Z7Obq&IgF6+J74fh#5f&BEaAY#jqIz6ZM&!$Z z@o`a_3XWU|Pl=OKFsc~b;j_n24V)bqIeOyMfWZm@B{1y;X;^^Vj{BO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qsZ@qtoMAl8rFrUkOt8nKBn@kVhwx4R6* zBnA36=})`(1-M`=2w4K3hcN5o*36LCfFnl9Bys4Hd`tO)EJ+gif=KYxHLkYpKSFq) zL|nXdjbiLtIgZ6~OQh~AO7p)1(-xEbB>RNZW@^D?d~f!_!=D2BVp-D)8~L5aNEKN2 zp`n$&OAXf$RNT(r)Nf=MkHE^J0gu`_X7N5~codm|kD=((bI@&w2=aO_L5i5O-Ai`f zGCtzm=AN44;47-~17OXM;}EIAV}4jE<~0X{PAp3Vqo=j=&dOl>4ckFUhhdoW0-#80 zUA|!SdGA2UxHq&uR3l30!p2w64;)%w-t4_sSTB@l_3$WAQtt%;rOVa+gX^=;`Xk@> zN51*IeDpljM@#j0rT@LH{`bnF0!zUV72FA*0$!l^R|wmE`%150zus3T6t8~>ke(yR zmeFl^uJxAR8mnl>x3uHswu+<~1((iQ*!Azbr%#Z3A54!ZPkK5*d@@3(kNBS)QBaOZ zC?6H_iNTA0<)1zYP$ZBYp@|$JLbC|M|B{GB;K>kptsvQKg&??U6&HiQQ4ARZPu@H5 zL=sl=c`*I&!eD0-7WW5l_WzxO>-St0H=OswGQfOj%DM zm{V3p_Pwl_S;ukEbpXhp+V1>$;1GWQNdc>ut6I<6>@#indu{kHpO;5sP&b$A?}`@R z(&A-N@j}#x2*#g_cJLAK&)-47_^9teWIo&j{~5w4!XyGNTI{UhGVYtOYQDhUSKF%iK?!#ICX_C`z}{DTsKo030}#e1b^rhX diff --git a/athlete/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc b/athlete/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index a5c712bd9fee807cc7d5d8dee75065eabcad9a05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1852 zcmb_dU1%d!6h3!;(@c}5``1nFhA#eKq%iMoW@#7@7Gy!+vUGjfC(oU9lE&bItoP2Gd;adZ z-#zCH^KB#&1{^;=uRA^(|Y)jk??&Q--GW7Kn4ir#6~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qY+rulDkvKh=S449cVj9guqZI52J$yD=nYtAFn9WveH s6tYBm!00{?-0`7q7P$CPM?xOy0g|B`(@0}pXPMX8qh5VYpbpObHz_WJ`~Uy| diff --git a/discipline/__pycache__/discipline.cpython-311.pyc b/discipline/__pycache__/discipline.cpython-311.pyc deleted file mode 100644 index 02e6bcb399aaafd322ab8915979ed7126f2cab6a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3191 zcmbVOQEwAR5Z=4nv(Ju0lEyS7gvL=4f+I=_q%R>w0#Z;=lOiY&SgowXw;`9FeP-_r zByvSK2ntyMWI-l3$TUN_MB>`txHK+%q0_pIz_H|_v=KwPOR zAY|6(^U@>WpZenkDK9P8Tk(}10r%7&jgzn5{}R?M$P0=a^ruOlbIZwTzTRG-Xm_WO4J{i93FzyVeb!H7;m;?WK`U1CSS;}>WzqoKTd2!_EN5h8y zf$P{K**UKj_dUz)^m*`N91bwQzxKh8Gzwc_S7#DPfxO;BTBCR8ANH@b^sKh@EYecf z2fqycIP}BepAMIa6gnu#cjp(+EbU#3v@eZ6?0cA7i43ep28yDWmFl7mFi582VNXjY zGkTgOlU_KPOxp&;7Vwc|@_J6Uwj{x1(y&v>BoBcSM|67%1ftiHOzN484c7+1azIUS zT+a7_{0ZTR7T$qGs}j_7ZUHIOJ!M%|wK72xAe~)>(~H_t``zXu?S#HUJ4<`o3X_G& z+moemb77(|aeJcF7A;cjD>Uj)mT5>mxO}Nh;I%8MIEDV~jQ-OgsYm}cl2906zYh5U zLlTIVSr8Dd0HQU63SJfH4nTMZy%tO{toBts${`hbG^@Ka+pvi@DzF&^7>Fa*gE zpGUCkQ-5bj-+<^oa+EmqrhH4eLT*YDxk4m(DiSwRv)@m6yF^@!>8)loc#gWLcav0X z#cA#vSn9*~ow*`5ZKh^S#&^yYc=@A{Y*^aN#Ejhb#RzO{yCjYI_On~2A@I4KyP;pT z81Dto;+jY8EX(j#7+?<84c?DzK+nRoA;RBlJ8N2O%68A%xs35C=Qj7$EC*Y0l}BMU zA3zmpE9(ToQ;WIGLBt5R1d_Z+eR7!ZZV0k%sRL_@vks&{%6kH#_*&cECF5S#{jM@m zn#UeqU+dU^e{Q+$UjBZ5iI#f$Aa%5j39@vq6y0}!;$^h|MYR97L~&pg`X7Up_e%7{ zYV<@=bjT*4qJlYLQ;>DE{t8KLZdYz|b8}aj5Ny8INNX=pCX4IGA)s;MCu?oEjqcPM$iTJZo(N_Spe?syFzoS3$mCLViH-L!GCC%AWxVsL1%+ z(21EsptAtXf2o`Tdop0p$H}sfLNMhw7xBN<3>mN|?~FZBHI-Zrmi{{=Y_FOkgfO`O zchRhbx+;R4w}BfX#(5k$yrsBO31cjp{6ioPo)@;PlmM&=^RaiuE7rjw)Vl-(N?oL} z)OGB~5Ev0;@mwj=dUxVwr29pr`{zXQz%l5L2P^ND$nn+4@uKJ$6BQMa`k~DrKq%xfqfoNYHO_^ty7^hjU2KlA{AD)IFsGJ%#bb{>Ay#a95G`KwqIf zWw}|6FSnNoyc$WjrjB6Ug4eF3vODe>4|!U4&d}j+V2a}va|*-@z`sE=b4}D{E>45l zsB$FXFJ`LR8Qy4Pl~R9_9|HlD9^(821g=YxN+e#~sh3D^ai?A)O$G6kX}biq_ieJ& bxsJ21YNDZi5}fvJvShB~?5iC_!ux*!Jg(u} diff --git a/discipline/app.py b/discipline/app.py index b8c9635..f7e1eb7 100644 --- a/discipline/app.py +++ b/discipline/app.py @@ -1,13 +1,14 @@ from flask import Flask, jsonify, request from pathlib import Path import json -from discipline import Discipline, ListeDiscipline +from models import Discipline, ListeDiscipline # noinspection PyUnresolvedReferences from flask_swagger_ui import get_swaggerui_blueprint import os app = Flask(__name__) app.config['DISCIPLINE_FILE'] = os.getenv('DISCIPLINE_FILE', Path(__file__).parent.parent / 'data' / 'disciplines.json') +print(app.config['DISCIPLINE_FILE']) @app.route('/ping', methods=["GET"]) def ping(): @@ -50,9 +51,9 @@ def deleteDiscipline(id: int): """ listeDisciplines = ListeDiscipline() listeDisciplines.loadFromJson(app.config['DISCIPLINE_FILE']) - for athlete in listeDisciplines.root: - if athlete.id == id: - listeDisciplines.root.remove(athlete) + for discipline in listeDisciplines.root: + if discipline.id == id: + listeDisciplines.root.remove(discipline) with open(app.config['DISCIPLINE_FILE'], 'w') as f: json.dump(listeDisciplines.model_dump(), f, indent=4) return jsonify({"message": "Discipline supprimé"}), 200 @@ -102,7 +103,7 @@ def addDiscipline(): listeDisciplines = ListeDiscipline() listeDisciplines.loadFromJson(app.config['DISCIPLINE_FILE']) discipline = Discipline(**json.loads(request.data)) - discipline.id = max([athlete.id for athlete in listeDisciplines.root]) + 1 + discipline.id = max([discipline.id for discipline in listeDisciplines.root]) + 1 listeDisciplines.root.append(discipline) with open(app.config['DISCIPLINE_FILE'], 'w') as f: json.dump(listeDisciplines.model_dump(), f, indent=4) diff --git a/discipline/discipline.py b/discipline/models.py similarity index 82% rename from discipline/discipline.py rename to discipline/models.py index 96cc3bd..9fe252b 100644 --- a/discipline/discipline.py +++ b/discipline/models.py @@ -35,10 +35,10 @@ class ListeDiscipline(RootModel): try: with open(path) as f: data = json.load(f) - for athlete in data: - self.root.append(Discipline(**athlete)) + for discipline in data: + self.root.append(Discipline(**discipline)) except FileNotFoundError: - print("Fichier introuvable") + print(f"Le fichier {path} n'existe pas") def loadFromJsonData(self, data: str): """ Charge les données depuis une chaine json @@ -46,5 +46,5 @@ class ListeDiscipline(RootModel): :return: None """ data = json.loads(data) - for athlete in data: - self.root.append(Discipline(**athlete)) \ No newline at end of file + for discipline in data: + self.root.append(Discipline(**discipline)) \ No newline at end of file diff --git a/discipline/tests/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index 6a8c86dc2b42349753e13818caedc6bfacdb0104..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1250 zcmb_a&ubGw6n?Y2-Q8xBw5e@Xs3FBuq%;nlh0*(t#unIM6Bo)v>{3;>Bmz~XJVe41wXE8bExTG(FY5#(pz8W?bkza^gz<&;Z}KlCKW%lQvm_ymrbp6i<0(c@iWnMophq%tphC#i60#x{a&1 zitrQ&Chuc$qR}t?9lVA0_;foeT0|DRO>D^_JILCLnFPOk0b7KZ52eY)Kr203DJ>Nr zm+~^>5(3q#*H)cZf!b`?sB@PDGD`LM6}j_;!gG%@uTV9qTUc&cYbL8Mv-&!w#nS8_sHJ{9OMn~v){H7`is zZ?r10ceB!HiEf!5cG`F9wOK|tnB&u6I1U9`6ieX8LYv6~H8cYa-^(nn@I7g(&KtkU zXxMvRIL1Zpf>0vLdamEA*6pTC7g!dLcq_ec2wj;F(&2ghW2V|-b|AOk|2rWg?a9sT w0m&SZOjpuLx(f(rGDu@_H@-F7LVuytZB}gzRU_EA}q4{0}u!W1poj5 diff --git a/discipline/tests/__pycache__/test_delAthlete.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_delAthlete.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index f6967234b76525c3d6a23b6c0bdee97bb236385c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2132 zcmeHH%}*0S6rb7MwzLQhQ4>v68iMFvTFQrLVvQU~JQ1RJ;oxTJOrdqR+srHqb(;|5 ziHjE#IC$WMQ4;?Sk76((b29P7jfBJ)PQKY~x7~vA=0&HSH}B*3-psstZ{PLxr4S6` zhg$jw>vt)%hSFq?M}XNx1QBeZ1?;bitriuGY;7Ti5m8>Dg*d^Fkggs|r`aNI`pP8% zQ-yi_1n4I6&^8FC2f;hwwHtaiu!k#cNg+x@^%PHi>YuBjc^d!V#@cZzau0tH)zeCt zXcApgb~K0zvuTUD$rg`LCG_6`u{<@j3h{p7b|05in{}?6Cf0c6yDm4M*LpN*4D;!o_f(_GKGxfMs=R$ zuIa9Dqv#NtYGew5VN&O!hf!X0s+{VoPys8+m?V?+ev@;`TtCJXKtVZGegmDV_lh{7 z7ImrU?FcMV_iJk|<*s2eF<=x;%Q6_Pv7%$wOh&~yFdK_2Wy>vBxrkd1Ah@_>@MUMk zB0khuvYbWJGODIcMbhAAiOL9~f7(Av*{RMj<}h*IC^^hFU4yRHEVF95U=ivPb@haZ z7p*d_x=gmR=#_g0_sDk&6P?0%AOsRt*!ks3z)v$CcwurP)V}AwJ z42p)Ol*iRj+m>)mptt3HsNo*G$-woXneqq?%PC)s`#ECE1>afDp*BSgHgo z>6#-{@KjIrVWsG)D18ZSen*NFcvW~c=n84rNNpnppNOiV5>{t@qJ}E_xezDcCo1&G zqCg+%lmFlPzFePFi>rlC-c{mtui+)U9M)#LP=ASCs24pIrTi{LRgByRvY$aDLuTa8#D2nJMuK44QAZvp31lbVe!lY#}MraVH z(S@K;)VSMu@++(=Bz*24vSWc2>@u?tNj^_)U1z#N#gU_@#Ku63^~pjm#(4+<%JX`Y zD+3Zxaoh6R^GdlY%HXy4{c%88U|N(fntjW0OiFwT+vHo6@CHnqH+O9(ut$t*jt2r4JzGQBD)U^VW-0>Z2WCbw8 z>$&3e2G{zIO-2D-7IiI&jO!wSq^xdUIF}dB=Y{n|NP@kSRFDYWf`?unw~-evFmdgy z=Ek$j#;34*%y2E@7}v)A9gDixs5d12fEhQgbkvqM_gDyY4^3Mu-%P%qeE;Ty*6ByB(|cE*YN&N;T5n8&HkPK%m1*GMGCWMam^?86iQ{No%ZGfbGwJi%mQ z-YQdOelpEb*ip=XIr%A=a2uoq&$!(4ia2EcRpEY=)86Az&YkzVDM^sv)6K*3)%lk1_K96>m;ZAxxa zJAk8}sl@#o>*(uX6QA4ox{15{Cqy@dwg=={ZCKP5G%cycwjBBRCRx!igJvKJUo(B#|P FasV=V50O}@u12LPeR B4(0#= diff --git a/discipline/tests/__pycache__/test_gettest.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_gettest.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index 9e5b477a831461dbb44bb0977c23a930d77a1210..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1462 zcmZ`(%WD%s7@yhQY#wb5r3$_dAtJgUNo!kEM8yh%r&4@ea#^<7NxETQ%xr6u?m`ex zUOd)=2Tv6(^l!0Hq0H5jw?c0{`OR*!dDPBkzWsi``M%#gzS(@AnJFM>tB2>L2k$=u z44Tw;&MM&SArqO{Ms*y&B}Z;Z7&%HkgOd@puA0(ERL`3D4btSlB6+QW`x@evg)T!s zI|OzQh3FfAi_OIQFn*9`M%a`hDa7p|BZpEbZ=*;F74|d83^m$9KW?TRDot!EBC;v% zE1(EHX=52F8%pEznwel~kbzKJ9r*j;91H;3M(paCp4esF!ijy*@wnl<6LBtvnMe0D zjFcxDe-B;b9{pmp4XYtB!c175UFo$S$1H#jH|W>!Hi$m*`~K;n{k%jvb_z%)?LFP z{K{%Px8=DnDfK9y)0-Z3j6f$lzHPWh03%wKs}0*CZa_t~_>`Ca0_*O&S5KzFl9?UoS1pSB+rPCIP96LtwGh z;dBJ5_#K{)&qfrD-U4ayX)pvIQ4gIIuYK-*>VCO*R4gAC%e_}8O6^ztJ03U*Ozm%_ zcG=KTJd_3`5E2t6g((A0N?y$RZ&;E7cJv1#N$`Y7Dn1%K>Yu?uAT7spg9|~6K=2!S za+@ki4WYsnO5Rf|fSZ(3Jlp5!w8&ADl=ysqAbJ}(dK1if?up}>TQ+${?*J74Tx=E0 asf;l`5hb|fnd!yPsUqQ(Q*_b9Q~U$<^Kl>m diff --git a/discipline/tests/__pycache__/test_listeAthlete.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_listeAthlete.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index 9a21fcd789c0da6fc0d6554082581678e52d4a95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11730 zcmeHN&2JmW72hR?6h-RGv7N+8+ei%@h_NGzQfxUzBh)~fek2Hteq4MZHr$m>WyvLG z*R7>4VWVh)wkXgPD9|2q@S$*#`tQh{6iAd*R(w2$-%q4t^m1YDksP~f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U=6SO((vGp$>kxr+$Wbu zydFpwT2wibHbem?@G7bdl`AmH1%POQS~aFy1ka>gh-$gGMRlPX1velP0Ho#7o5khLw0S_ra7FRF;GED_7K&7z>P7RFRF{uqntuJeA zfSoQQgw&z~9#ViTu3!LUnhIKgN@Ek88W_7{c~Xm08_sTJfSoR*$pCSEP=GA1;0L7E zk!S%bjZJWBVC;VBrc)o1dY{BKHo#7o5khLw0S_ra7FRF;GED_7K&7z>P7RFRG1(cC zoxZHG0d~5K5K@Z{ct`=VxPk$YX)0&|DveEWYGCY+$@Y+J_hpR@u+wFPkXm%WLkf_^ z6%2q(Q$Y(*X>5X117mkgHil%QFKcXooh~DU)S?3(Qh+S3U;t#A3R-|lV-uVj7`tQg z#*nC!Ev;dXHCO9=PcE{xEkX-G{8XI7XawH9K zM+m6^!Wi(70%UPjVwwtCfJ$Q%oEjLrV^STGYG2ma09%wJX@EOINCgnafQJ+yi>ngT zRL}xc8k^wMz}Ov=H;3fSzO1nUwkSu^0C$9t3LuOD4=F$vS0$#YparNjHo>WZvHPW) z&Xpm#(kF3^4X{Nyk_NaVgj4`w40uQZvbZWSO$9ALrLhT44UFBfyvvJc1GvK~L)~qU z&|O>Ird3oKSsnvaI=;XE7oQ5mV4lI-s8OAdO7cSkWq*4bU22F=6C2_^9zGXrQ0Hf~ z6~Jc()x^FB@HWc+s4$v~---FB5B{qAnL)n+5qblv=cRA9J^P;P?9!XyvcF{Z--qgH c-ZafIdmBFaU*A~O%G2BhbL***u6Sqv2H9%GO8@`> diff --git a/discipline/tests/__pycache__/test_listeDiscipline.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_listeDiscipline.cpython-311-pytest-8.1.1.pyc index 83b75ba912f5c959556c92efd1522ee2a027eff8..d7229a87685198aad9d4cf4160b0c615893370d8 100644 GIT binary patch delta 537 zcmaDM|4p8EIWI340}!lHVM(jl$ji*i$Uj+-Rg+zyh9!+LMR2ksYdf#d9Of!E28LSx z6yX$+$WO)wh$tyW57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pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_ping_discipline.cpython-311-pytest-8.1.1.pyc index 0b74945cb76a458c31c4d43bd9b01821f0637a62..f5620aac265cb196a075f4b6227fc78473f76394 100644 GIT binary patch delta 19 ZcmdnOy@i`=IWI340}#wn*~qnu6#y>V1bzSj delta 19 ZcmdnOy@i`=IWI340}x!4+Q_wv6#y^i1gQW3 diff --git a/discipline/tests/__pycache__/test_postAthlete.cpython-311-pytest-8.1.1.pyc b/discipline/tests/__pycache__/test_postAthlete.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index 8678aaee30a49610156135297400e5f8cd02c2dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3084 zcmdT_&1>976rYi_-?rBq$4=5vFr*II2E5+Hv7JzdhJGZZ5JJ*W@I@#)V|%yKO3cWu zz1D&$Ih0(IL!p7XkdsU69D3^C(4!q3x(pNwJ>}+*(t~^H8)+p=YbOMH>a6tkef;LV zH*emIe(3MdBN*#{tMe}~LVrpj97>mYc@CIw5kUl-Xb$`Tilx>Rj4W*~g{4I?(^h6K z1H5_<&1DI`jmp|{>EK2gi_8^w(WEY|L5OI`z$&~if7YaXH)bQ4C`2V1Ns%JcJ24?hl*-&X^-0qI3ivQ&1LOVi@RLGM)FEx)zzeLX~8?c^Dc!NO(-2RYh*O?rFcYzY;sT9IoQu!Z1?|3tgmI znj-z-l4Cbrq20N4`?kQ>T0@Jj>s+c-2(|2Sx@=gENtx`na#kpHBGL|{P1_QxB${Ka zaG`O!Ohu}084FYtNS)W}j#+O~E;5YPY)1GVuE1rgHMre;{;Twb_mtV$GH#t8JL9aJ zEA#wnml>TMmE1&`k8{^>m$+WD3C*`hX9L59G8b7!IV8<#SrsZ^B{?U_h1P(I0;ZeLRHy=`tD1xyElAGP$&%&d+h@x8w#XR42cw)~ z#~>^_4n$@#Dan*1Gp%AQ$ttWA%D4jmMJBIs5Nz&>{Jv*Vh*d)5-*;AA%3a-HqNLXh z)6^MtSk1N^gHh23X8rC`-E`|sF4CqA2riE6e9>Mqi4WBmO#7~3>P^Fo=Oj5 z;EG?ny50PUF`J1Yecoo4;p%kRF^#6-f`tvqMahB+b%DC&K9R1Ob=q{U$1T#FYOdBtzGMAr+2i|Tgm5XOni12Ai!^jrT`O(V2x%)%7dDN zutPE6p(njS1K=Kf6srdhVyATCo3|giJEeEluHL&26@1XT-`aZX-A4=S4fum+yLfh| zcy{gDAKJu@HnHVD5d-3OOb_DI5CiR!Iw9ee=dGRY)0}^K=!il!7a9A(#z~Ji1Mq$KLN6;unVv hP`WfH)vm~LatM!}p6mq%6!d|GkJ01<1114B0|3Tp9UA}u delta 85 zcmdlixj~Y5IWI340}$j&v!qSl$g9A^S|keOPB!IHWVDzZ&ZDQNc!2>0ePH2ZH2J`Q KNfa3YH39%e@DpYL diff --git a/discipline/tests/test_getDiscipline.py b/discipline/tests/test_getDiscipline.py index b69ed1f..c86ec33 100644 --- a/discipline/tests/test_getDiscipline.py +++ b/discipline/tests/test_getDiscipline.py @@ -1,4 +1,4 @@ -from discipline import Discipline +from models import Discipline def test_getDiscipline(client): response = client.get("/1") diff --git a/discipline/tests/test_listeDiscipline.py b/discipline/tests/test_listeDiscipline.py index 778fb6a..64069a1 100644 --- a/discipline/tests/test_listeDiscipline.py +++ b/discipline/tests/test_listeDiscipline.py @@ -1,9 +1,9 @@ -from discipline import ListeDiscipline -def test_listeAthlete(client): +from models import ListeDiscipline +def test_listeDiscipline(client): response = client.get("/") listeDiscipline = ListeDiscipline() listeDiscipline.loadFromJsonData(response.data) assert listeDiscipline.root is not None assert len(listeDiscipline.root) > 0 - assert listeDiscipline.root[0].id == 0 - assert listeDiscipline.root[0].nom is not None + assert listeDiscipline.root[0].id == 1 + assert listeDiscipline.root[0].intitule is not None diff --git a/discipline/tests/test_postDiscipline.py b/discipline/tests/test_postDiscipline.py index bd288e5..40f7070 100644 --- a/discipline/tests/test_postDiscipline.py +++ b/discipline/tests/test_postDiscipline.py @@ -1,4 +1,4 @@ -from discipline import Discipline +from models import Discipline def test_postDiscipline(client): discipline = Discipline( diff --git a/medaille/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc b/medaille/__pycache__/conftest.cpython-311-pytest-8.1.1.pyc deleted file mode 100644 index 32d37cf0a0a3b4df6b11f1c0056a2ecbbd9a646c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1858 zcmb_dU2NM_6u#HKw$pe?)BO`l)rp@iQ7Atw%S(da+V2guon!Mr_Ig^P0Y~j@)@!HJA>DhdKMtNm6Ka&}v1j0jr<+@{-0V!2$Yn0VCh$+gF zVd{z!h&7e!mJ^7js1CZZfHqhPp(T^rRnP|Lx zm&BWwZjc*qf1dmz>8GCdQxmsVz0{=p{G6AX`}yMS*WdZE@KeFhtFE@<Q~vDSwEfo?zERa?_S7z>3mz@Pl#;<fO7n^@q`!R26P|KUPkO@S9+}!DQy!W2$+R0?`*09c z>UKW}tUp=;V84Q zoHo!MIr-Vt$5Wm>>dT`p8Kunje?X$gArOEXjzB52Zdp1V1olAxIQTPgHbW2s+mpw3 z=;M&3?57Y&HTWKy#?`RdJFOSK3DT0W>eQ)D8A{6FZle%WnBe=d3ze!? zH}x0jGhkvxwReHEd5kgqNgDq)6OC}TP?tIBqQ0wz(r*8C2M;%nH^)3Y;^UDvC*zlJ p8!>v1N8I6_E{(XME>yiPH%QwO~|nou2{`ER9SfkXfR diff --git a/medaille/app.py b/medaille/app.py index ebbf072..5a2c7f4 100644 --- a/medaille/app.py +++ b/medaille/app.py @@ -1,7 +1,7 @@ from flask import Flask, jsonify, request from pathlib import Path import json -from athlete import ListeAthlete, Athlete +from models import ListeMedaille, Medaille from flask_swagger_ui import get_swaggerui_blueprint import os @@ -11,98 +11,102 @@ app.config['MEDAILLE_FILE'] = os.getenv('MEDAILLE_FILE', Path(__file__).parent.p def ping(): return jsonify({"message": "pong"}), 200 @app.route('/', methods=["GET"]) -def listeAthlete(): +def listeMedaille(): """ - Renvoie la liste des athlètes + Renvoie la liste des médilles """ # Offset / Limit offset = request.args.get('offset', 0) limit = request.args.get('limit', 10) - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) if limit != 0: - listeAthletes.root = listeAthletes.root[int(offset):int(offset)+int(limit)] + listeMedailles.root = listeMedailles.root[int(offset):int(offset)+int(limit)] else: - listeAthletes.root = listeAthletes.root[int(offset):] + listeMedailles.root = listeMedailles.root[int(offset):] - return jsonify(listeAthletes.model_dump()), 200 + return jsonify(listeMedailles.model_dump()), 200 @app.route('/', methods=["GET"]) -def getAthlete(id: int): +def getMedaille(id: int): """ - Renvoie un athlète par son id + Renvoie un médille par son id """ - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) - for athlete in listeAthletes.root: - if athlete.id == id: - return jsonify(athlete.model_dump()), 200 - return jsonify({"message": "Athlete introuvable"}), 404 + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) + for medaille in listeMedailles.root: + if medaille.id == id: + return jsonify(medaille.model_dump()), 200 + return jsonify({"message": "Medaille introuvable"}), 404 @app.route('/', methods=["DELETE"]) -def deleteAthlete(id: int): +def deleteMedaille(id: int): """ - Supprime un athlète par son id + Supprime un médille par son id """ - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) - for athlete in listeAthletes.root: - if athlete.id == id: - listeAthletes.root.remove(athlete) + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) + for medaille in listeMedailles.root: + if medaille.id == id: + listeMedailles.root.remove(medaille) with open(app.config['MEDAILLE_FILE'], 'w') as f: - json.dump(listeAthletes.model_dump(), f, indent=4) - return jsonify({"message": "Athlete supprimé"}), 200 - return jsonify({"message": "Athlete introuvable"}), 404 + json.dump(listeMedailles.model_dump(), f, indent=4) + return jsonify({"message": "Medaille supprimé"}), 200 + return jsonify({"message": "Medaille introuvable"}), 404 @app.route('/', methods=["PUT"]) -def updateAthlete(id: int): +def updateMedaille(id: int): """ - Met à jour un athlète par son id + Met à jour un médille par son id """ - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) - for athlete in listeAthletes.root: - if athlete.id == id: + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) + for medaille in listeMedailles.root: + if medaille.id == id: data = json.loads(request.data) for key, value in data.items(): - setattr(athlete, key, value) + setattr(medaille, key, value) with open(app.config['MEDAILLE_FILE'], 'w') as f: - json.dump(listeAthletes.model_dump(), f, indent=4) - return jsonify({"message": "Athlete mis à jour"}), 200 - return jsonify({"message": "Athlete introuvable"}), 404 + json.dump(listeMedailles.model_dump(), f, indent=4) + return jsonify({"message": "Medaille mis à jour"}), 200 + return jsonify({"message": "Medaille introuvable"}), 404 @app.route('/', methods=["PATCH"]) -def patchAthlete(id: int): +def patchMedaille(id: int): """ - Met à jour un athlète par son id + Met à jour un médille par son id """ - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) - for athlete in listeAthletes.root: - if athlete.id == id: + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) + for medaille in listeMedailles.root: + if medaille.id == id: data = json.loads(request.data) - data["id"] = athlete.id # On ne peut pas changer l'id + data["id"] = medaille.id # On ne peut pas changer l'id for key, value in data.items(): - if hasattr(athlete, key): - setattr(athlete, key, value) + if hasattr(medaille, key): + setattr(medaille, key, value) + if not medaille.validate(): + return jsonify({"message": "Données invalides"}), 400 with open(app.config['MEDAILLE_FILE'], 'w') as f: - json.dump(listeAthletes.model_dump(), f, indent=4) - return jsonify({"message": "Athlete mis à jour"}), 200 - return jsonify({"message": "Athlete introuvable"}), 404 + json.dump(listeMedailles.model_dump(), f, indent=4) + return jsonify({"message": "Medaille mis à jour"}), 200 + return jsonify({"message": "Medaille introuvable"}), 404 @app.route('/', methods=["POST"]) -def addAthlete(): +def addMedaille(): """ - Ajoute un athlète + Ajoute un médille """ - listeAthletes = ListeAthlete() - listeAthletes.loadFromJson(app.config['MEDAILLE_FILE']) - athlete = Athlete(**json.loads(request.data)) - athlete.id = max([athlete.id for athlete in listeAthletes.root]) + 1 - listeAthletes.root.append(athlete) + listeMedailles = ListeMedaille() + listeMedailles.loadFromJson(app.config['MEDAILLE_FILE']) + medaille = Medaille(**json.loads(request.data)) + if not medaille.validate(): + return jsonify({"message": "Données invalides"}), 400 + medaille.id = max([medaille.id for medaille in listeMedailles.root]) + 1 + listeMedailles.root.append(medaille) with open(app.config['MEDAILLE_FILE'], 'w') as f: - json.dump(listeAthletes.model_dump(), f, indent=4) - return jsonify(athlete.model_dump()), 200 + json.dump(listeMedailles.model_dump(), f, indent=4) + return jsonify(medaille.model_dump()), 200 swaggerui_blueprint = get_swaggerui_blueprint( "/swagger", diff --git a/medaille/models.py b/medaille/models.py new file mode 100644 index 0000000..28421ee --- /dev/null +++ b/medaille/models.py @@ -0,0 +1,60 @@ +from pydantic import BaseModel, RootModel +from typing import Optional, List +import json + +class Medaille(BaseModel): + """ + Modèle Medaille + """ + id: Optional[int] = 0 + type: str # Or, Argent, Bronze + sport: str + categorie: str # ex : 80kg pour le judo + pays: str # Nom FR du pays + + def loadFromJsonData(self, data: str): + """ + Charge les données depuis une chaine json + + :param data: Données json + :return: None + """ + data = json.loads(data) + for key, value in data.items(): + setattr(self, key, value) + + def validate(self) -> bool: + """ + Valide les données + + :return: True si les données sont valides, False sinon + """ + if self.type not in ["Or", "Argent", "Bronze"]: + return False + return True + +class ListeMedaille(RootModel): + root: List[Medaille] = [] + def loadFromJson(self, path: str): + """ + Charge les données depuis un fichier json + + :param path: Chemin du fichier json + :return: None + """ + try: + with open(path) as f: + data = json.load(f) + for discipline in data: + self.root.append(Medaille(**discipline)) + except FileNotFoundError: + print(f"Le fichier {path} n'existe pas") + def loadFromJsonData(self, data: str): + """ + Charge les données depuis une chaine json + :param data: Données json + :return: None + """ + data = json.loads(data) + for discipline in data: + self.root.append(Medaille(**discipline)) \ No newline at end of file diff --git a/medaille/static/swagger.yaml b/medaille/static/swagger.yaml index 7d18542..28a2d46 100644 --- a/medaille/static/swagger.yaml +++ b/medaille/static/swagger.yaml @@ -118,15 +118,12 @@ components: sport: type: integer example: 1234567 - disclipine: - type: integer - example: 1234567 + categorie: + type: str + example: +80kg pays: type: string example: France - logo: - type: string - example: https://olympics.com/images/static/sports/pictograms/v2/kte.svg requestBodies: User: description: Objet médaille à ajouter diff --git a/medaille/tests/test_delMedaille.py b/medaille/tests/test_delMedaille.py new file mode 100644 index 0000000..d13d995 --- /dev/null +++ b/medaille/tests/test_delMedaille.py @@ -0,0 +1,6 @@ +def test_delMedaille(client): + response = client.delete("/1") + assert response.status_code == 200 + + response = client.get("/1") + assert response.status_code == 404 \ No newline at end of file diff --git a/medaille/tests/test_getMedaille.py b/medaille/tests/test_getMedaille.py new file mode 100644 index 0000000..07fdc1b --- /dev/null +++ b/medaille/tests/test_getMedaille.py @@ -0,0 +1,13 @@ +from models import Medaille + +def test_getMedaille(client): + response = client.get("/1") + medaille = Medaille( + id=1, + type="Or", + sport="Judo", + categorie="80kg", + pays="France" + ) + assert medaille.model_dump() == response.json + assert response.status_code == 200 diff --git a/medaille/tests/test_listeMedaille.py b/medaille/tests/test_listeMedaille.py new file mode 100644 index 0000000..673106e --- /dev/null +++ b/medaille/tests/test_listeMedaille.py @@ -0,0 +1,8 @@ +from models import ListeMedaille +def test_listeMedaille(client): + response = client.get("/") + listeMedailles = ListeMedaille() + listeMedailles.loadFromJsonData(response.data) + assert listeMedailles.root is not None + assert len(listeMedailles.root) > 0 + assert listeMedailles.root[0].id == 1 diff --git a/medaille/tests/test_ping_medaille.py b/medaille/tests/test_ping_medaille.py new file mode 100644 index 0000000..e825694 --- /dev/null +++ b/medaille/tests/test_ping_medaille.py @@ -0,0 +1,3 @@ +def test_ping_medaille(client): + response = client.get("/ping") + assert b"{\"message\":\"pong\"}\n" in response.data diff --git a/medaille/tests/test_postMedaille.py b/medaille/tests/test_postMedaille.py new file mode 100644 index 0000000..28e5af6 --- /dev/null +++ b/medaille/tests/test_postMedaille.py @@ -0,0 +1,30 @@ +from models import Medaille + +def test_postMedaille(client): + medaille = Medaille( + id=1, + type="Argent", + sport="Escrime", + categorie="Fleuret", + pays="Italie" + ) + + response = client.post("/", json=medaille.model_dump()) + assert response.status_code == 200 + medaille.id = response.json["id"] + response = client.get(f"/{medaille.id}") + + assert response.json == medaille.model_dump() + +def test_postMedaille_erreur(client): + medaille = Medaille( + id=1, + type="NexistePas", + sport="Escrime", + categorie="Fleuret", + pays="Italie" + ) + + response = client.post("/", json=medaille.model_dump()) + assert response.status_code == 400 + assert response.json == {'message': 'Données invalides'} diff --git a/sample/disciplines.json b/sample/disciplines.json index c9684f1..c458b43 100644 --- a/sample/disciplines.json +++ b/sample/disciplines.json @@ -18,13 +18,13 @@ "intitule": "100m", "type": "Course", "description": "Le 100 mètres est une épreuve de sprint en athlétisme. C'est l'épreuve reine des sprinteurs.", - "logo": "https://upload.wikimedia.org/wikipedia/commons/1/1b/Athletics_pictogram.svg", + "logo": "https://upload.wikimedia.org/wikipedia/commons/1/1b/Athletics_pictogram.svg" }, { "id": 4, "intitule": "Natation", "type": "Nage", "description": "La natation est un sport consistant à parcourir une certaine distance dans l'eau, en utilisant les bras et les jambes.", - "logo": "https://upload.wikimedia.org/wikipedia/commons/0/0d/Swimming_pictogram.svg", + "logo": "https://upload.wikimedia.org/wikipedia/commons/0/0d/Swimming_pictogram.svg" } ] \ No newline at end of file diff --git a/sample/medailles.json b/sample/medailles.json new file mode 100644 index 0000000..7e019c7 --- /dev/null +++ b/sample/medailles.json @@ -0,0 +1,44 @@ +[ + { + "id": 1, + "type": "Or", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + }, + { + "id": 2, + "type": "Argent", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + }, + { + "id": 3, + "type": "Bronze", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + }, + { + "id": 4, + "type": "Or", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + }, + { + "id": 5, + "type": "Argent", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + }, + { + "id": 6, + "type": "Bronze", + "sport": "Judo", + "categorie": "80kg", + "pays": "France" + } +] \ No newline at end of file