From e622f2e14e298625b5ed8d7b1131c8cab803640a Mon Sep 17 00:00:00 2001 From: Ramirez-Christopher Date: Sat, 10 Feb 2024 17:19:59 -0800 Subject: [PATCH] created workflows directory --- .coverage | Bin 53248 -> 53248 bytes .github/workflows/workflow.yml | 0 github/workflows/workflow.yml | 12 ++++ src/__pycache__/counter.cpython-39.pyc | Bin 673 -> 1253 bytes src/__pycache__/status.cpython-39.pyc | Bin 358 -> 318 bytes src/counter.py | 58 ++++++++++++++++++ tests/__pycache__/test_counter.cpython-39.pyc | Bin 730 -> 2575 bytes tests/test_counter.py | 54 ++++++++++++++++ 8 files changed, 124 insertions(+) create mode 100644 .github/workflows/workflow.yml create mode 100644 github/workflows/workflow.yml create mode 100644 src/counter.py diff --git a/.coverage b/.coverage index 877ad7d3709da1ae777a5b5c756395508e52e0b7..470a242f90af1e2126e63b69951f9dadcace183f 100644 GIT binary patch delta 376 zcmZozz}&Eac|sCXw9&?tnflBodWM?}SOhqj_-8WkpW&amSx}&tzuu6EnITg@BR@A) zzc{-nv!Fyjx!A%gGC*nfPBb@PFoi4Gf$6{EBQ$ER39dOn;KxHrZdDwue7@3$@fQmR5B^UqzKLl&l delta 244 zcmZozz}&Eac|sDCf9=MUnflDedIp;eSOnM@`Ij*8FWD?8FpEDeijjq((NaIOIJKx) zKdH1hGcP?=-z7h}G&eP`q*&j;z#!DmCk#mEq$Zb?7Nr*JC+DZ6#;0eNWRxc9L#X() z%)G=L{gRXv{oCEU+W`5L|#d04Ai^k{$`9!X?uQ1RBQTkgVHkihAj56a&?^9)* zn#Wq3FjGNvH>tWHYb427n5kLQiYIuexDz^AQ`7Ype>34yIVy6xX);UgIC1VZmon_} zTiZ)#aHeG^96%X6clf)$R8nBWwOp)+<8f>aqF#@S*yxXrquBPEM-9K;Y6~4|;+1E< ze;90SJPf>MLj3KeTur$4R# zgWVG-`CoRZ=s&b-PRlKjnKLKVwK=Jx1ZNuFaeko^ci{D670us9EaJV{fcKzEB0^$R z4HSo12ftA(bj)M?iG>EoSO_VfFTgIA=nwA2Ad>(9 delta 361 zcmYjMyG{c!5cK*UaS%CP5)~avk?QgRQ5p~xL_#PaU2}5c&2exK$&Ush8fZa^?h7dS z13E;-Kcq*9U!cN18n&4A*gNCd&+c;&@m_C@*y_K1i4Rytd#5AI1QAe>5)uG+rUgwX z0($q5_&MPL`d6Xwgr9*39;paL=YiO_j-Y2`z`mW~09L_K!PWI-`TE4R4kU7osyTrH zD^V$);Z1V~W3~#F=Gv&{9r{x%@+)5A3z3oa__>Iu3Z;r?M&(t8@nJnTC01I+!{Kl` zIX<_&z_~UORXnc+rdh5p%`EnU~6gURU+K<+OQAT|l!7q}2S&0Au diff --git a/src/__pycache__/status.cpython-39.pyc b/src/__pycache__/status.cpython-39.pyc index 32cda55f5f2898b905cdc08a197d1e97b76fafa2..5c774eb16355ae933848cac6337d9e60115f0274 100644 GIT binary patch delta 96 zcmaFHw2z4=k(ZZ?0SMx{j;BuKNo2e=G0zxCEHbdYCFl_n5)f}Wc1@8{;@=^V0> tp@;*h7EJuo)6dAyP1P^XF3Kz@(N8WmF*njLNlA%!&M3+(o@~yj4*-4f9drNy delta 136 zcmdnT^o)rok(ZZ?0SL-h-A4z4l78UC!l@@2_rKjq<l+vtg!=h}0qLC7 +# let Flask know that the only methods that is allowed to called +# on this function is "POST". +@app.route('/counters/', methods=['POST']) +def create_counter(name): + """Create a counter""" + app.logger.info(f"Request to create counter: {name}") + global COUNTERS + + if name in COUNTERS: + return {"Message":f"Counter {name} already exists"}, status.HTTP_409_CONFLICT + + COUNTERS[name] = 0 + return {name: COUNTERS[name]}, status.HTTP_201_CREATED + +@app.route('/counters/', methods=['PUT']) +def update_counter(name): + """Update Counter""" + + app.logger.info(f"Request to update counter: {name}") + global COUNTERS + + if not name in COUNTERS: + return {"Message":f"Counter {name} does not exist"}, status.HTTP_404_NOT_FOUND + + COUNTERS[name] += 1 + return {name: COUNTERS[name]}, status.HTTP_200_OK + +@app.route('/counters/', methods=['GET']) +def read_counter(name): + + """Read a counter""" + app.logger.info(f"Request to read counter: {name}") + + global COUNTERS + + if not name in COUNTERS: + return {"Message":f"Counter {name} does not exist"}, status.HTTP_404_NOT_FOUND + + return {name: COUNTERS[name]}, status.HTTP_200_OK + + + + + + + + + + diff --git a/tests/__pycache__/test_counter.cpython-39.pyc b/tests/__pycache__/test_counter.cpython-39.pyc index 715442c3da5e1b21815c8805a8bebc0b86e3c9ee..73301a296c7c1e25cd46769707f919b81eed56fc 100644 GIT binary patch literal 2575 zcmah~TW{1x6rQoYUS}^fL8V;OO4ACVu2ixVA=*l)D%yk=6>U&hgk-6*9M5dliPttW zV?tKT6TJ0LB#-?i{SSWa6A%3ZJoTLM-U6X`wR7>A%Xhx>o#U|GZV-6>{qt`Tt`YJN zPF5cWCcnU6-Ghb`pK!{pgpMuWqByn_d+hj*89PaB?D{SxzY<>K?i<2gVZFBfIJ8JQP_rmZ*`W|Q zyw@^}4p}y2<08>gaExF|hq_Rk`7s;D ziP&ThvLwll;&dOaO0fMR<|2txp}u3sSz&G+hlhYhsbZY#I7<}^_p(AaM%fY58LUVW zbMz7TFh?Aw9Crw**%5+|HB+OkNH~*17c$)hpaXy-Ql4jVy08LfJWp`eU2*BzNTe)6 zRuE`7_qIZ4d{w!K;^DEuk%nWz;?#`uP>=Agts+n22w6p|stBr}nDf#hm^BkpLQtZN zi#fo#Lvu#MJzyKWE^=PQXacJ65 ziDdW}k&t2J-QDge8;h0fP$mD>|hoK-VdKWlhP6J+%%TT|013F{3ST$DUk!xDcdK z9p>T;$)vpyW_Orn{Z8F@E?qdkbn;B;vRMg#`*{&2WwVMQIKqWQH0AnlgTdqA_O0)O z-tPAO!S)uA=Yc`i(dtT}AgK*iRf7epyi^fu3PTXiY55XN3U4NsM;mnV^(rCf?l?mb z(zqZ93*3|(Kx7Ry6sWPL^uX56K@F+-h;5a&ZG+&tT+l7|!n8`YGt`^dCHW*c)`LinMiHh`L%K>xyxGaov)yZ(yB5u8Gy6 z>$F8D*FRwFoNZ@FL&9qCH>!FGgO3oiB+XrD%>u02QT1=U?8+`dev)_k@g z+~p4F)HcDe&E7SmQ%t*Be{x|dM)bLKuzid9`fkP4fBNWAr}6(3mv&xgzd6(9tzhT( z(%Tn0I8a$yUYyZ?C+P1Cf(JWK`&%7n$-m#Ks^PAYZrMzWB$@I0erPHkSId`i=>T9; zSWH|nHWq{S96i6k^Gs+kEDJrq_(W*5%dOXRi~O;UWdL+v$1qXy{JNQWCTKI_Pu3tv zHU!C91jaLgaZF$w6PU(oU^bS4NyX6sqk`!C`fMgI!K~B#L`-TjO!tNS0@ju`L_=PN zk-UOiYfJh|`m(gsVl1&XzEAju$p!rC%!|fdSfwy+=44+0sy|1%zxp5NgYo!+i z`27rmvJnL1j28)xTS0)eZf2 KPP=8p&-xFJE}m@w delta 183 zcmeAdxy5Rc$ji&c00hkkpQlJNF)%y^agYHckmCTv#T-B)g&~R|g)x{xlWAj)I8&UT zCgUyk`1q9kn#=daAxlesXDUYFE-5WaE!I!YPf3kW&n(F(P11)@@oAZPi8+%eGD{0_*yQG?l;)(`f!y&Kh#3Hn CK`#LS diff --git a/tests/test_counter.py b/tests/test_counter.py index 3da6a8e4..8e536efa 100644 --- a/tests/test_counter.py +++ b/tests/test_counter.py @@ -10,3 +10,57 @@ - The service must be able to update a counter by name. - The service must be able to read the counter """ + +from unittest import TestCase + +# we need to import the unit under test - counter +from src.counter import app + +# we need to import the file that contains the status codes +from src import status + +class CounterTest(TestCase): + """Counter tests""" + + def setUp(self): + self.client = app.test_client() + + def test_create_a_counter(self): + """It should create a counter""" + client = app.test_client() + result = client.post('/counters/foo') + self.assertEqual(result.status_code, status.HTTP_201_CREATED) + + def test_duplicate_a_counter(self): + """It should return an error for duplicates""" + result = self.client.post('/counters/bar') + self.assertEqual(result.status_code, status.HTTP_201_CREATED) + result = self.client.post('/counters/bar') + self.assertEqual(result.status_code, status.HTTP_409_CONFLICT) + + def test_update_a_counter(self): + + result = self.client.post('/counters/test') + self.assertEqual(result.status_code, status.HTTP_201_CREATED) + + updateResult = self.client.put('/counters/test') + self.assertEqual(updateResult.status_code, status.HTTP_200_OK) + + self.assertEqual(result.get_json()['test'] + 1, updateResult.get_json()['test']) + + nullCounter = self.client.put('/counters/NULL') + self.assertEqual(nullCounter.status_code, status.HTTP_404_NOT_FOUND) + + def test_read_counter(self): + + result = self.client.post('/counters/newTest') + self.assertEqual(result.status_code, status.HTTP_201_CREATED) + + for x in range(5): + self.client.put('/counters/newTest') + + num = self.client.get('/counters/newTest') + self.assertEqual(num.get_json()['newTest'], 5) + + nullCounter = self.client.get('/counters/NULL') + self.assertEqual(nullCounter.status_code, status.HTTP_404_NOT_FOUND)