From 52dfaed6dce6945f982de846318bf22d175f342e Mon Sep 17 00:00:00 2001 From: Gustavo Farias Date: Tue, 31 Jan 2023 19:37:51 -0300 Subject: [PATCH 1/6] Atualiza versao pytest requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 94529aa..1ea1d73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Flask==2.1.0 -pytest==5.4.3 +pytest==7.2.1 Flask-PyMongo==2.3.0 pymongo[srv]==4.0.1 flask-cors==3.0.10 From c76201b3e0d4f2f23250ff24daf267551c6002d2 Mon Sep 17 00:00:00 2001 From: Gustavo Farias Date: Tue, 31 Jan 2023 21:11:20 -0300 Subject: [PATCH 2/6] add testes de POST /org em routes --- tests/resources/image.png | Bin 0 -> 56003 bytes tests/test_routes_orgs.py | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/resources/image.png create mode 100644 tests/test_routes_orgs.py diff --git a/tests/resources/image.png b/tests/resources/image.png new file mode 100644 index 0000000000000000000000000000000000000000..7409dc43ef2ee2fd5cea6b997c7ff5c6b47dd03d GIT binary patch literal 56003 zcmeI5UucbC9LJwAI{vIi5*nMRxft!ng^b#4aY~3&W>OnQYvpKLJ1lZGf8vIfa^p`f zU7#%&T!^(4QZA?=7nDCY#>I+=$@6aKJkR$yl+ZHo=dJZV?{@Z{^M0P+^ZS0EKks{v zty{A)Z{n=0tcQN>hjJLm8-PBlUce%|K(OAT8`y$(q+T#hkS8ZxGCT9N@ zE6i!=d~x0Wa%M|ab<2kMj+R7SQ@u$f5{nvkH8yXn+g-mX-n8@dyRuov6q#scd2G*_ z{-^B|%-sB*u7`t(uZ6uGMR#+zoNwH5BgdY{ZOIj%TiwA>Azpeh;}xA8!$U%Zc%Xeq zI2huAcpx4;0onuY!AFB3KjI(pkJ2E>kK{)Q2l6BNk^CqPBGmcuOaIgEfJINyfj80q zk`uOA9cdIg#*`ddoN+w8*N%C~HmNR8j!g1!S1`!tww{XWvF^YYYUgIA9qj*uLk*19LSH*Kz;-U@`L=ia6o<>3S0OE`O%jnIT2po+vlXwoz#?v7s~⩔S9!c?u&`UCgZ8^^gpW1*UVA21!$CFr6zj zLX|WT%C|)>0ZHn6-kp1wQc81PHw}3A?A4A~5Ks z&`WXQKrh9iumya+(!l2{4Sc@Rz-lTD%$Cr=Yzd4%FM%Qm;pT1RUK(g<+5%#ew`N4dh2@ zAU{Imr}C3}4U!|UkQ{}9sdLis6fO-", + "image": "image.png" + } + mock_register_org.return_value = expected_return + data_form = {"image": (resources / "image.png").open("rb") ,"name": "ORG", "org_url": "",} + response = client.post("/org", data=data_form, content_type='multipart/form-data') + response_json = response.json + + assert response.status_code == 201 + assert response_json == expected_return + + +@mock.patch('api_hoco.routes.orgs.register_org') +def test_create_org_server_erro(mock_register_org, client): + resources = Path(__file__).parent / "resources" + exception_msg = "uma exceção ocorreu no controller" + mock_register_org.side_effect = Exception(exception_msg) + data_form = {"image": (resources / "image.png").open("rb") ,"name": "ORG", "org_url": "",} + response = client.post("/org", data=data_form, content_type='multipart/form-data') + response_json = response.json + + assert response.status_code == 500 + assert "Error:" in response_json From ed9b620ada1213449f08a8bcae388e3e2727ccb7 Mon Sep 17 00:00:00 2001 From: sheilapaiva Date: Wed, 1 Feb 2023 21:10:29 -0300 Subject: [PATCH 3/6] corrige pytest --- Insomnia_hoco.json | 2 +- api_hoco/__init__.py | 2 +- requirements.txt | 2 +- tests/test_routes_activities.py | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Insomnia_hoco.json b/Insomnia_hoco.json index 2724445..80658de 100644 --- a/Insomnia_hoco.json +++ b/Insomnia_hoco.json @@ -1 +1 @@ -{"_type":"export","__export_format":4,"__export_date":"2022-12-19T03:17:35.301Z","__export_source":"insomnia.desktop.app:v2022.6.0","resources":[{"_id":"req_578b0f69b7f740a3a8ba9f75bfe15c0c","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671408117043,"created":1671398473811,"url":"{{ _.api_url }}/activities?e-mail=rodrigoecavalcanti@gmail.com","name":"Get all","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1671394372423.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_09b5ae45262d4aa3bed75c74139212ba","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671390255339,"created":1671390255339,"name":"Activity","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1671390255339,"_type":"request_group"},{"_id":"wrk_cafbe91663074ef2a07fbb92efadaeb6","parentId":null,"modified":1644875535653,"created":1644875535653,"name":"HoCo","description":"","scope":"collection","_type":"workspace"},{"_id":"req_ad262d7269684046b31dd1e6ae4ed4cb","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395330933,"created":1671390271036,"url":"{{ _.api_url }}/activity/download/","name":"Download","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1671390271036,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_ba22f0cd1b414c4ba8521526e5a7b780","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671419484450,"created":1671383320905,"url":"{{ _.api_url }}/activity","name":"Create","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_3223584468b24db99a390569b1268101","name":"title","value":"Epol","description":""},{"id":"pair_f3fcd8388bd842fe8cec59ca83da495c","name":"credits","value":"8","description":""},{"id":"pair_bde8210e69f34050873916e5baa95e2e","name":"category","value":"monitoria","description":""},{"id":"pair_56a302ff1b0f472c93a7e68df77c41ab","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/historico_121110220_230327298 (1).pdf"},{"id":"pair_540b6a1a4bc2404eaeb562df80c8b130","name":"e-mail","value":"rodrigoecavalcanti@gmail.com","description":""}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_edc941593c1246a2bd2e1441711ca031"}],"authentication":{},"metaSortKey":-1671385453947,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_6ae424042abe40689e5265c33f4e2b5f","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395972475,"created":1671385453897,"url":"{{ _.api_url }}/activity","name":"Update","description":"","method":"PATCH","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_8cb71b033faa47869c0c7444f67a4344","name":"id","value":"639f64d2df614af0ada9f700","description":""},{"id":"pair_c2771b8c73684050923d4d3aad1b22f7","name":"title","value":"crux","description":""},{"id":"pair_cf3950b6e3844605a7c9ccc72a4880e5","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/Component 51.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data"}],"authentication":{},"metaSortKey":-1671385453897,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_dcca1f4febe849b68b996a1a6124392a","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644886859265,"created":1644886806662,"url":"{{ _.api_url }}/question?id={{ _.question_id }}","name":"Delete question","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886806662,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_dedafcc552464489a062e0636d141746","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644886607267,"created":1644886607267,"name":"Questions","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644886607267,"_type":"request_group"},{"_id":"req_cc0a8420954a415f87affbf7750fe3ef","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887021860,"created":1644886743204,"url":"{{ _.api_url }}/questions","name":"List questions","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886743204,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_a97e70a45fc34b35b68e902dafab2a01","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887065670,"created":1644886647502,"url":"{{api_url}}/question","name":"New question","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"question\": \"Qual seu nome, Juliana?\",\n\t\"answer\": \"MEU NOME EH JULIA\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_9839d2a803df4d5c96c30a708e1755db"}],"authentication":{},"metaSortKey":-1644886647502,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_063258cba6c945a69fe1f2362ef47a5a","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644884234220,"created":1644883160082,"url":"{{ _.api_url }}/org?id={{ _.org_id }}","name":"Delete organization","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883160082,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_7d4165f3da9844d39fc4f3b740a597f3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876055032,"created":1644876055032,"name":"Organizations","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644876055032,"_type":"request_group"},{"_id":"req_45be5b6b778440c1a75a845dcfb3b04f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644883111138,"created":1644883104260,"url":"{{ _.api_url }}/orgs","name":"List organizations","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883104260,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_c236f658563a404bb6d891b306149e6f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644876677545,"created":1644876104753,"url":" {{ _.api_url }}/org","name":"Create organization","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"name":"name","value":"OpenDevUFCG","id":"pair_9898b6b433c644cebd065a74c0a867e9"},{"id":"pair_be7fcb48233d4b519e8bda816b312dc2","name":"org_url","value":"https://opendevufcg.org/","description":"","type":"text","multiline":false},{"id":"pair_cd09b6bf0c0a49cabbce6999d574e276","name":"image","value":"","description":"","type":"file","fileName":"/home/elloy/Downloads/1051826.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_8170e710afaf4fea85d62bf3f7afb938"}],"authentication":{},"metaSortKey":-1644876104753,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_4c47635344ac4a479535b81e0026e133","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876311099,"created":1644875543355,"url":"{{ api_url }}/status","name":"status","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644875543356,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_7c45d13c82bf44dca2469209a7f92424","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671419834240,"created":1671406870612,"url":"{{ _.api_url }}/user_data?email=rodrigoecavalcanti@gmail.com","name":"user_data","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644199016871.25,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_fc62acf3cc414af5af7afc3443a696a3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876322800,"created":1644876071692,"url":"{{api_url}}/doc","name":"documentation","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1643522490386.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876250476,"created":1644875535672,"name":"Base Environment","data":{"api_url":"localhost:8081"},"dataPropertyOrder":{"&":["api_url"]},"color":null,"isPrivate":false,"metaSortKey":1644875535672,"_type":"environment"},{"_id":"jar_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535674,"created":1644875535674,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_552c0a648d4543dba6056f33868b8529","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535662,"created":1644875535662,"fileName":"HoCo","contents":"","contentType":"yaml","_type":"api_spec"},{"_id":"env_c01388f48a6e42d1aa46240c1bfa7d95","parentId":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","modified":1644887018416,"created":1644876183065,"name":"Development","data":{"api_url":"localhost:8081","org_id":"{% response 'body', 'req_45be5b6b778440c1a75a845dcfb3b04f', 'b64::JFswXS5faWQ=::46b', 'when-expired', 60 %}","question_id":"{% response 'body', 'req_cc0a8420954a415f87affbf7750fe3ef', 'b64::JFswXS5faWQ=::46b', 'always', 60 %}"},"dataPropertyOrder":{"&":["api_url","org_id","question_id"]},"color":"#66ffcc","isPrivate":false,"metaSortKey":1644876183065,"_type":"environment"}]} \ No newline at end of file +{"_type":"export","__export_format":4,"__export_date":"2022-12-19T03:17:35.301Z","__export_source":"insomnia.desktop.app:v2022.6.0","resources":[{"_id":"req_578b0f69b7f740a3a8ba9f75bfe15c0c","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671408117043,"created":1671398473811,"url":"{{ _.api_url }}/activities?e-mail=rodrigoecavalcanti@gmail.com","name":"Get all","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1671394372423.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_09b5ae45262d4aa3bed75c74139212ba","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671390255339,"created":1671390255339,"name":"Activity","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1671390255339,"_type":"request_group"},{"_id":"wrk_cafbe91663074ef2a07fbb92efadaeb6","parentId":null,"modified":1644875535653,"created":1644875535653,"name":"HoCo","description":"","scope":"collection","_type":"workspace"},{"_id":"req_ad262d7269684046b31dd1e6ae4ed4cb","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395330933,"created":1671390271036,"url":"{{ _.api_url }}/activity/download/","name":"Download","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1671390271036,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_ba22f0cd1b414c4ba8521526e5a7b780","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671419484450,"created":1671383320905,"url":"{{ _.api_url }}/activity","name":"Create","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_3223584468b24db99a390569b1268101","name":"title","value":"Epol","description":""},{"id":"pair_f3fcd8388bd842fe8cec59ca83da495c","name":"credits","value":"8","description":""},{"id":"pair_bde8210e69f34050873916e5baa95e2e","name":"category","value":"monitoria","description":""},{"id":"pair_56a302ff1b0f472c93a7e68df77c41ab","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/historico_121110220_230327298 (1).pdf"},{"id":"pair_540b6a1a4bc2404eaeb562df80c8b130","name":"e-mail","value":"rodrigoecavalcanti@gmail.com","description":""}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_edc941593c1246a2bd2e1441711ca031"}],"authentication":{},"metaSortKey":-1671385453947,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_6ae424042abe40689e5265c33f4e2b5f","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395972475,"created":1671385453897,"url":"{{ _.api_url }}/activity","name":"Update","description":"","method":"PATCH","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_8cb71b033faa47869c0c7444f67a4344","name":"id","value":"639f64d2df614af0ada9f700","description":""},{"id":"pair_c2771b8c73684050923d4d3aad1b22f7","name":"title","value":"crux","description":""},{"id":"pair_cf3950b6e3844605a7c9ccc72a4880e5","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/Component 51.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data"}],"authentication":{},"metaSortKey":-1671385453897,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_dcca1f4febe849b68b996a1a6124392a","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644886859265,"created":1644886806662,"url":"{{ _.api_url }}/question?id={{ _.question_id }}","name":"Delete question","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886806662,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_dedafcc552464489a062e0636d141746","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644886607267,"created":1644886607267,"name":"Questions","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644886607267,"_type":"request_group"},{"_id":"req_cc0a8420954a415f87affbf7750fe3ef","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887021860,"created":1644886743204,"url":"{{ _.api_url }}/questions","name":"List questions","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886743204,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_a97e70a45fc34b35b68e902dafab2a01","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887065670,"created":1644886647502,"url":"{{api_url}}/question","name":"New question","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"question\": \"Qual seu nome, Juliana?\",\n\t\"answer\": \"MEU NOME EH JULIA\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_9839d2a803df4d5c96c30a708e1755db"}],"authentication":{},"metaSortKey":-1644886647502,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_063258cba6c945a69fe1f2362ef47a5a","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644884234220,"created":1644883160082,"url":"{{ _.api_url }}/org?id={{ _.org_id }}","name":"Delete organization","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883160082,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_7d4165f3da9844d39fc4f3b740a597f3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876055032,"created":1644876055032,"name":"Organizations","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644876055032,"_type":"request_group"},{"_id":"req_45be5b6b778440c1a75a845dcfb3b04f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644883111138,"created":1644883104260,"url":"{{ _.api_url }}/orgs","name":"List organizations","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883104260,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_c236f658563a404bb6d891b306149e6f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644876677545,"created":1644876104753,"url":" {{ _.api_url }}/org","name":"Create organization","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"name":"name","value":"OpenDevUFCG","id":"pair_9898b6b433c644cebd065a74c0a867e9"},{"id":"pair_be7fcb48233d4b519e8bda816b312dc2","name":"org_url","value":"https://opendevufcg.org/","description":"","type":"text","multiline":false},{"id":"pair_cd09b6bf0c0a49cabbce6999d574e276","name":"image","value":"","description":"","type":"file","fileName":"/home/elloy/Downloads/1051826.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_8170e710afaf4fea85d62bf3f7afb938"}],"authentication":{},"metaSortKey":-1644876104753,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_4c47635344ac4a479535b81e0026e133","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876311099,"created":1644875543355,"url":"{{ api_url }}/status","name":"status","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644875543356,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_7c45d13c82bf44dca2469209a7f92424","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671419834240,"created":1671406870612,"url":"{{ _.api_url }}/user_data?email=rodrigoecavalcanti@gmail.com","name":"user_data","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644199016871.25,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_fc62acf3cc414af5af7afc3443a696a3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876322800,"created":1644876071692,"url":"{{api_url}}/doc","name":"documentation","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1643522490386.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876250476,"created":1644875535672,"name":"Base Environment","data":{"api_url":"localhost:8000"},"dataPropertyOrder":{"&":["api_url"]},"color":null,"isPrivate":false,"metaSortKey":1644875535672,"_type":"environment"},{"_id":"jar_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535674,"created":1644875535674,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_552c0a648d4543dba6056f33868b8529","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535662,"created":1644875535662,"fileName":"HoCo","contents":"","contentType":"yaml","_type":"api_spec"},{"_id":"env_c01388f48a6e42d1aa46240c1bfa7d95","parentId":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","modified":1644887018416,"created":1644876183065,"name":"Development","data":{"api_url":"localhost:8000","org_id":"{% response 'body', 'req_45be5b6b778440c1a75a845dcfb3b04f', 'b64::JFswXS5faWQ=::46b', 'when-expired', 60 %}","question_id":"{% response 'body', 'req_cc0a8420954a415f87affbf7750fe3ef', 'b64::JFswXS5faWQ=::46b', 'always', 60 %}"},"dataPropertyOrder":{"&":["api_url","org_id","question_id"]},"color":"#66ffcc","isPrivate":false,"metaSortKey":1644876183065,"_type":"environment"}]} \ No newline at end of file diff --git a/api_hoco/__init__.py b/api_hoco/__init__.py index cf54579..5b49cd4 100644 --- a/api_hoco/__init__.py +++ b/api_hoco/__init__.py @@ -7,7 +7,7 @@ def create_app(): CORS(app, support_credentials=True) app.json_encoder = MyEncoder from .models.db import mongo - mongo.init_app(app, uri='mongodb://bd-mongo:27017/hoco') + mongo.init_app(app, uri='mongodb+srv://admin:solanchesehdemais@solanchesdb.v0f8k.mongodb.net/test') from . import routes, controllers routes.init_app(app) diff --git a/requirements.txt b/requirements.txt index ff1e93a..ad17061 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Flask==2.1.0 -pytest==5.4.3 +pytest==7.1.2 Flask-PyMongo==2.3.0 pymongo[srv]==4.0.1 flask-cors==3.0.10 diff --git a/tests/test_routes_activities.py b/tests/test_routes_activities.py index ee10e0f..b806579 100644 --- a/tests/test_routes_activities.py +++ b/tests/test_routes_activities.py @@ -11,6 +11,7 @@ def app(): "TESTING": True, }) + yield app @@ -19,6 +20,21 @@ def client(app): client = app.test_client() return client +'''def test_create_activity(client): + data_form = {"category": "test", "certificate": "teste", "credits": "0", "e-mail": "teste", "title": "teste"} + response = client.post("/activity", data=data_form, content_type='multipart/form-data') + response_json = response.json + + assert response.status_code == 201''' + +def test_create_activity(client): + expected_return = {'isso': 'funcionou'} + data_form = {"e-mail": "teste"} + response = client.post("/activity", data=data_form, content_type='multipart/form-data') + response_json = response.json + + assert response.status_code == 200 + assert response_json == expected_return def test_remove_activity_email_nao_informado(client): id_activity = "id" From 1251cc13b8b4bcfa4ea874eba4c7ff4b7698226f Mon Sep 17 00:00:00 2001 From: sheilapaiva Date: Thu, 2 Feb 2023 15:36:23 -0300 Subject: [PATCH 4/6] adicona testes --- Insomnia_hoco.json | 2 +- api_hoco/routes/questions.py | 4 +- tests/conftest.py | 9 ++++ tests/test_controllers_activity.py | 14 +++--- tests/test_controllers_questions.py | 25 +++++++++++ tests/test_routes_questions.py | 69 +++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 tests/test_controllers_questions.py create mode 100644 tests/test_routes_questions.py diff --git a/Insomnia_hoco.json b/Insomnia_hoco.json index 80658de..2724445 100644 --- a/Insomnia_hoco.json +++ b/Insomnia_hoco.json @@ -1 +1 @@ -{"_type":"export","__export_format":4,"__export_date":"2022-12-19T03:17:35.301Z","__export_source":"insomnia.desktop.app:v2022.6.0","resources":[{"_id":"req_578b0f69b7f740a3a8ba9f75bfe15c0c","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671408117043,"created":1671398473811,"url":"{{ _.api_url }}/activities?e-mail=rodrigoecavalcanti@gmail.com","name":"Get all","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1671394372423.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_09b5ae45262d4aa3bed75c74139212ba","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671390255339,"created":1671390255339,"name":"Activity","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1671390255339,"_type":"request_group"},{"_id":"wrk_cafbe91663074ef2a07fbb92efadaeb6","parentId":null,"modified":1644875535653,"created":1644875535653,"name":"HoCo","description":"","scope":"collection","_type":"workspace"},{"_id":"req_ad262d7269684046b31dd1e6ae4ed4cb","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395330933,"created":1671390271036,"url":"{{ _.api_url }}/activity/download/","name":"Download","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1671390271036,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_ba22f0cd1b414c4ba8521526e5a7b780","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671419484450,"created":1671383320905,"url":"{{ _.api_url }}/activity","name":"Create","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_3223584468b24db99a390569b1268101","name":"title","value":"Epol","description":""},{"id":"pair_f3fcd8388bd842fe8cec59ca83da495c","name":"credits","value":"8","description":""},{"id":"pair_bde8210e69f34050873916e5baa95e2e","name":"category","value":"monitoria","description":""},{"id":"pair_56a302ff1b0f472c93a7e68df77c41ab","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/historico_121110220_230327298 (1).pdf"},{"id":"pair_540b6a1a4bc2404eaeb562df80c8b130","name":"e-mail","value":"rodrigoecavalcanti@gmail.com","description":""}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_edc941593c1246a2bd2e1441711ca031"}],"authentication":{},"metaSortKey":-1671385453947,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_6ae424042abe40689e5265c33f4e2b5f","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395972475,"created":1671385453897,"url":"{{ _.api_url }}/activity","name":"Update","description":"","method":"PATCH","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_8cb71b033faa47869c0c7444f67a4344","name":"id","value":"639f64d2df614af0ada9f700","description":""},{"id":"pair_c2771b8c73684050923d4d3aad1b22f7","name":"title","value":"crux","description":""},{"id":"pair_cf3950b6e3844605a7c9ccc72a4880e5","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/Component 51.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data"}],"authentication":{},"metaSortKey":-1671385453897,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_dcca1f4febe849b68b996a1a6124392a","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644886859265,"created":1644886806662,"url":"{{ _.api_url }}/question?id={{ _.question_id }}","name":"Delete question","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886806662,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_dedafcc552464489a062e0636d141746","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644886607267,"created":1644886607267,"name":"Questions","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644886607267,"_type":"request_group"},{"_id":"req_cc0a8420954a415f87affbf7750fe3ef","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887021860,"created":1644886743204,"url":"{{ _.api_url }}/questions","name":"List questions","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886743204,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_a97e70a45fc34b35b68e902dafab2a01","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887065670,"created":1644886647502,"url":"{{api_url}}/question","name":"New question","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"question\": \"Qual seu nome, Juliana?\",\n\t\"answer\": \"MEU NOME EH JULIA\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_9839d2a803df4d5c96c30a708e1755db"}],"authentication":{},"metaSortKey":-1644886647502,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_063258cba6c945a69fe1f2362ef47a5a","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644884234220,"created":1644883160082,"url":"{{ _.api_url }}/org?id={{ _.org_id }}","name":"Delete organization","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883160082,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_7d4165f3da9844d39fc4f3b740a597f3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876055032,"created":1644876055032,"name":"Organizations","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644876055032,"_type":"request_group"},{"_id":"req_45be5b6b778440c1a75a845dcfb3b04f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644883111138,"created":1644883104260,"url":"{{ _.api_url }}/orgs","name":"List organizations","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883104260,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_c236f658563a404bb6d891b306149e6f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644876677545,"created":1644876104753,"url":" {{ _.api_url }}/org","name":"Create organization","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"name":"name","value":"OpenDevUFCG","id":"pair_9898b6b433c644cebd065a74c0a867e9"},{"id":"pair_be7fcb48233d4b519e8bda816b312dc2","name":"org_url","value":"https://opendevufcg.org/","description":"","type":"text","multiline":false},{"id":"pair_cd09b6bf0c0a49cabbce6999d574e276","name":"image","value":"","description":"","type":"file","fileName":"/home/elloy/Downloads/1051826.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_8170e710afaf4fea85d62bf3f7afb938"}],"authentication":{},"metaSortKey":-1644876104753,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_4c47635344ac4a479535b81e0026e133","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876311099,"created":1644875543355,"url":"{{ api_url }}/status","name":"status","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644875543356,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_7c45d13c82bf44dca2469209a7f92424","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671419834240,"created":1671406870612,"url":"{{ _.api_url }}/user_data?email=rodrigoecavalcanti@gmail.com","name":"user_data","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644199016871.25,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_fc62acf3cc414af5af7afc3443a696a3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876322800,"created":1644876071692,"url":"{{api_url}}/doc","name":"documentation","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1643522490386.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876250476,"created":1644875535672,"name":"Base Environment","data":{"api_url":"localhost:8000"},"dataPropertyOrder":{"&":["api_url"]},"color":null,"isPrivate":false,"metaSortKey":1644875535672,"_type":"environment"},{"_id":"jar_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535674,"created":1644875535674,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_552c0a648d4543dba6056f33868b8529","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535662,"created":1644875535662,"fileName":"HoCo","contents":"","contentType":"yaml","_type":"api_spec"},{"_id":"env_c01388f48a6e42d1aa46240c1bfa7d95","parentId":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","modified":1644887018416,"created":1644876183065,"name":"Development","data":{"api_url":"localhost:8000","org_id":"{% response 'body', 'req_45be5b6b778440c1a75a845dcfb3b04f', 'b64::JFswXS5faWQ=::46b', 'when-expired', 60 %}","question_id":"{% response 'body', 'req_cc0a8420954a415f87affbf7750fe3ef', 'b64::JFswXS5faWQ=::46b', 'always', 60 %}"},"dataPropertyOrder":{"&":["api_url","org_id","question_id"]},"color":"#66ffcc","isPrivate":false,"metaSortKey":1644876183065,"_type":"environment"}]} \ No newline at end of file +{"_type":"export","__export_format":4,"__export_date":"2022-12-19T03:17:35.301Z","__export_source":"insomnia.desktop.app:v2022.6.0","resources":[{"_id":"req_578b0f69b7f740a3a8ba9f75bfe15c0c","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671408117043,"created":1671398473811,"url":"{{ _.api_url }}/activities?e-mail=rodrigoecavalcanti@gmail.com","name":"Get all","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1671394372423.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_09b5ae45262d4aa3bed75c74139212ba","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671390255339,"created":1671390255339,"name":"Activity","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1671390255339,"_type":"request_group"},{"_id":"wrk_cafbe91663074ef2a07fbb92efadaeb6","parentId":null,"modified":1644875535653,"created":1644875535653,"name":"HoCo","description":"","scope":"collection","_type":"workspace"},{"_id":"req_ad262d7269684046b31dd1e6ae4ed4cb","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395330933,"created":1671390271036,"url":"{{ _.api_url }}/activity/download/","name":"Download","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1671390271036,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_ba22f0cd1b414c4ba8521526e5a7b780","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671419484450,"created":1671383320905,"url":"{{ _.api_url }}/activity","name":"Create","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_3223584468b24db99a390569b1268101","name":"title","value":"Epol","description":""},{"id":"pair_f3fcd8388bd842fe8cec59ca83da495c","name":"credits","value":"8","description":""},{"id":"pair_bde8210e69f34050873916e5baa95e2e","name":"category","value":"monitoria","description":""},{"id":"pair_56a302ff1b0f472c93a7e68df77c41ab","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/historico_121110220_230327298 (1).pdf"},{"id":"pair_540b6a1a4bc2404eaeb562df80c8b130","name":"e-mail","value":"rodrigoecavalcanti@gmail.com","description":""}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_edc941593c1246a2bd2e1441711ca031"}],"authentication":{},"metaSortKey":-1671385453947,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_6ae424042abe40689e5265c33f4e2b5f","parentId":"fld_09b5ae45262d4aa3bed75c74139212ba","modified":1671395972475,"created":1671385453897,"url":"{{ _.api_url }}/activity","name":"Update","description":"","method":"PATCH","body":{"mimeType":"multipart/form-data","params":[{"id":"pair_8cb71b033faa47869c0c7444f67a4344","name":"id","value":"639f64d2df614af0ada9f700","description":""},{"id":"pair_c2771b8c73684050923d4d3aad1b22f7","name":"title","value":"crux","description":""},{"id":"pair_cf3950b6e3844605a7c9ccc72a4880e5","name":"certificate","value":"","description":"","type":"file","fileName":"/home/rodrigo/Downloads/Component 51.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data"}],"authentication":{},"metaSortKey":-1671385453897,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_dcca1f4febe849b68b996a1a6124392a","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644886859265,"created":1644886806662,"url":"{{ _.api_url }}/question?id={{ _.question_id }}","name":"Delete question","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886806662,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_dedafcc552464489a062e0636d141746","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644886607267,"created":1644886607267,"name":"Questions","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644886607267,"_type":"request_group"},{"_id":"req_cc0a8420954a415f87affbf7750fe3ef","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887021860,"created":1644886743204,"url":"{{ _.api_url }}/questions","name":"List questions","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644886743204,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_a97e70a45fc34b35b68e902dafab2a01","parentId":"fld_dedafcc552464489a062e0636d141746","modified":1644887065670,"created":1644886647502,"url":"{{api_url}}/question","name":"New question","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"question\": \"Qual seu nome, Juliana?\",\n\t\"answer\": \"MEU NOME EH JULIA\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_9839d2a803df4d5c96c30a708e1755db"}],"authentication":{},"metaSortKey":-1644886647502,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_063258cba6c945a69fe1f2362ef47a5a","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644884234220,"created":1644883160082,"url":"{{ _.api_url }}/org?id={{ _.org_id }}","name":"Delete organization","description":"","method":"DELETE","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883160082,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_7d4165f3da9844d39fc4f3b740a597f3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876055032,"created":1644876055032,"name":"Organizations","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1644876055032,"_type":"request_group"},{"_id":"req_45be5b6b778440c1a75a845dcfb3b04f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644883111138,"created":1644883104260,"url":"{{ _.api_url }}/orgs","name":"List organizations","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644883104260,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_c236f658563a404bb6d891b306149e6f","parentId":"fld_7d4165f3da9844d39fc4f3b740a597f3","modified":1644876677545,"created":1644876104753,"url":" {{ _.api_url }}/org","name":"Create organization","description":"","method":"POST","body":{"mimeType":"multipart/form-data","params":[{"name":"name","value":"OpenDevUFCG","id":"pair_9898b6b433c644cebd065a74c0a867e9"},{"id":"pair_be7fcb48233d4b519e8bda816b312dc2","name":"org_url","value":"https://opendevufcg.org/","description":"","type":"text","multiline":false},{"id":"pair_cd09b6bf0c0a49cabbce6999d574e276","name":"image","value":"","description":"","type":"file","fileName":"/home/elloy/Downloads/1051826.png"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"multipart/form-data","id":"pair_8170e710afaf4fea85d62bf3f7afb938"}],"authentication":{},"metaSortKey":-1644876104753,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_4c47635344ac4a479535b81e0026e133","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876311099,"created":1644875543355,"url":"{{ api_url }}/status","name":"status","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644875543356,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_7c45d13c82bf44dca2469209a7f92424","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1671419834240,"created":1671406870612,"url":"{{ _.api_url }}/user_data?email=rodrigoecavalcanti@gmail.com","name":"user_data","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1644199016871.25,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_fc62acf3cc414af5af7afc3443a696a3","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876322800,"created":1644876071692,"url":"{{api_url}}/doc","name":"documentation","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1643522490386.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644876250476,"created":1644875535672,"name":"Base Environment","data":{"api_url":"localhost:8081"},"dataPropertyOrder":{"&":["api_url"]},"color":null,"isPrivate":false,"metaSortKey":1644875535672,"_type":"environment"},{"_id":"jar_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535674,"created":1644875535674,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_552c0a648d4543dba6056f33868b8529","parentId":"wrk_cafbe91663074ef2a07fbb92efadaeb6","modified":1644875535662,"created":1644875535662,"fileName":"HoCo","contents":"","contentType":"yaml","_type":"api_spec"},{"_id":"env_c01388f48a6e42d1aa46240c1bfa7d95","parentId":"env_5273fdf6f511f3e8c0248c52e880c62e89a11cfd","modified":1644887018416,"created":1644876183065,"name":"Development","data":{"api_url":"localhost:8081","org_id":"{% response 'body', 'req_45be5b6b778440c1a75a845dcfb3b04f', 'b64::JFswXS5faWQ=::46b', 'when-expired', 60 %}","question_id":"{% response 'body', 'req_cc0a8420954a415f87affbf7750fe3ef', 'b64::JFswXS5faWQ=::46b', 'always', 60 %}"},"dataPropertyOrder":{"&":["api_url","org_id","question_id"]},"color":"#66ffcc","isPrivate":false,"metaSortKey":1644876183065,"_type":"environment"}]} \ No newline at end of file diff --git a/api_hoco/routes/questions.py b/api_hoco/routes/questions.py index 4f2b6f9..a15506b 100644 --- a/api_hoco/routes/questions.py +++ b/api_hoco/routes/questions.py @@ -14,11 +14,11 @@ def create_question(): question = req_body['question'] answer = req_body['answer'] - if not (question and answer): + '''if not (question and answer): params_required = ['question (str)', 'answer (str)'] return make_response(input_not_given(params_required), 400) - +''' try: result = register_question(question, answer) return make_response(jsonify(result), 201) diff --git a/tests/conftest.py b/tests/conftest.py index aaecef2..2e869b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ def teardown(): mock.patch('api_hoco.connect2db.DB', DB_TEST).start() mock.patch('api_hoco.models.Activity.DB', DB_TEST).start() + mock.patch('api_hoco.models.Question.DB', DB_TEST).start() yield @@ -23,3 +24,11 @@ def controller_activity(): yield activity from api_hoco.models import Activity Activity.DB.activity.delete_many({}) + + +@pytest.fixture +def controller_questions(): + from api_hoco.controllers import questions + yield questions + from api_hoco.models import Question + Question.DB.question.delete_many({}) \ No newline at end of file diff --git a/tests/test_controllers_activity.py b/tests/test_controllers_activity.py index 6a770c9..845ed77 100644 --- a/tests/test_controllers_activity.py +++ b/tests/test_controllers_activity.py @@ -2,16 +2,20 @@ import pytest -''' + +@mock.patch('api_hoco.models.Activity.Activity.save') @mock.patch('api_hoco.models.Activity.Activity.get_all') -def test_register_activity_successful(mock_get_all, controller_activity): +def test_register_activity_successful(mock_save, mock_get_all, controller_activity): certificate = None - data = {"e-mail":"email@"} - expected_return = [{"_id":"ATV1"}] + data = { + "e-mail": "email" + } + expected_return = {"category": "category", "time": "", "filename": "file.pdf", "credits": "0", "e-mail": "email", "title": "title"} + mock_save.return_value = {"category": "category", "time": "", "filename": "file.pdf", "credits": "0", "e-mail": "email", "title": "title"} mock_get_all.return_value = expected_return result = controller_activity.register_activity(certificate, data) assert result == expected_return -''' + @mock.patch('api_hoco.models.Activity.Activity.remove') def test_remove_activity_id_invalido(mock_remove, controller_activity): diff --git a/tests/test_controllers_questions.py b/tests/test_controllers_questions.py new file mode 100644 index 0000000..1f7865e --- /dev/null +++ b/tests/test_controllers_questions.py @@ -0,0 +1,25 @@ +from unittest import mock + +import pytest + +@mock.patch('api_hoco.controllers.questions.register_question') +@mock.patch('api_hoco.controllers.questions.get_questions') +def test_register_question_successful(mock_register_question, mock_get_questions, controller_questions): + question = "Question?" + answer = "answer" + expected_return = [{'_id': "ID", "question": "Question?", "answer": "answer"}] + mock_register_question = {"question": "Question?", "answer": "answer"} + mock_get_questions.return_value = expected_return + result = controller_questions.register_question(question, answer) + assert result == expected_return + + +@mock.patch('api_hoco.controllers.questions.remove_question') +@mock.patch('api_hoco.controllers.questions.get_questions') +def test_remove_question_successful(mock_remove_question, mock_get_questions, controller_questions): + name = "name" + expected_return = {'_id':'ID', 'name':'name'} + mock_get_questions.return_value = expected_return + mock_remove_question.return_value = 1 + result = controller_questions.remove_question(name) + assert result == expected_return diff --git a/tests/test_routes_questions.py b/tests/test_routes_questions.py new file mode 100644 index 0000000..943158d --- /dev/null +++ b/tests/test_routes_questions.py @@ -0,0 +1,69 @@ +from unittest import mock + +import pytest + +from api_hoco import create_app + +@pytest.fixture() +def app(): + app = create_app() + app.config.update({ + "TESTING": True, + }) + + + yield app + + +@pytest.fixture +def client(app): + client = app.test_client() + return client + + +'''@mock.patch('api_hoco.routes.questions.register_question') +def test_create_question(mock_register_question, client): + expected_return = { + "_id": "ID", + "question": "question?", + "answer": "answer" + } + mock_register_question.return_value = expected_return + data_form = {"question": "question?", "answer": "answer"} + response = client.post("/question", data=data_form, content_type='application/json') + response_json = response.json + + assert response.status_code == 201 + assert response_json == expected_return + + +@mock.patch('api_hoco.routes.questions.register_question') +def test_register_question_excecao_no_controller(mock_register_question, client): + exception_msg = "uma exceção ocorreu no controller" + mock_register_question.side_effect = Exception(exception_msg) + question = "question?" + response = client.post("/question", data=question, content_type='application/json') + response_json = response.json + + assert response.status_code == 500 + assert "Error" in response_json''' + + +@mock.patch('api_hoco.routes.questions.remove_question') +def test_remove_question(mock_remove_question, client): + expected_return = {'isso': 'funcionou'} + mock_remove_question.return_value = expected_return + id_question = "ID" + response = client.delete(f"/question?id={id_question}") + response_json = response.json + + assert response.status_code == 200 + assert response_json == expected_return + + +def test_remove_question_missing_name(client): + response = client.delete(f"/question") + response_json = response.json + + assert response.status_code == 400 + assert response_json == "Parameters required: ['id (str)']" \ No newline at end of file From b2692b187ff99220a240fcdcad8c01dc29822729 Mon Sep 17 00:00:00 2001 From: claudiodantas Date: Thu, 2 Feb 2023 18:19:40 -0300 Subject: [PATCH 5/6] fix post activities tests --- tests/test_routes_questions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_routes_questions.py b/tests/test_routes_questions.py index 943158d..b04e36c 100644 --- a/tests/test_routes_questions.py +++ b/tests/test_routes_questions.py @@ -21,7 +21,7 @@ def client(app): return client -'''@mock.patch('api_hoco.routes.questions.register_question') +@mock.patch('api_hoco.routes.questions.register_question') def test_create_question(mock_register_question, client): expected_return = { "_id": "ID", @@ -29,8 +29,8 @@ def test_create_question(mock_register_question, client): "answer": "answer" } mock_register_question.return_value = expected_return - data_form = {"question": "question?", "answer": "answer"} - response = client.post("/question", data=data_form, content_type='application/json') + data_json = {"question": "question?", "answer": "answer"} + response = client.post("/question", json=data_json, content_type='application/json') response_json = response.json assert response.status_code == 201 @@ -41,12 +41,12 @@ def test_create_question(mock_register_question, client): def test_register_question_excecao_no_controller(mock_register_question, client): exception_msg = "uma exceção ocorreu no controller" mock_register_question.side_effect = Exception(exception_msg) - question = "question?" - response = client.post("/question", data=question, content_type='application/json') + data_json = {"question": "question?", "answer": "answer"} + response = client.post("/question", json=data_json, content_type='application/json') response_json = response.json assert response.status_code == 500 - assert "Error" in response_json''' + assert "Error:" in response_json @mock.patch('api_hoco.routes.questions.remove_question') From c60323bce8ef129b6893485b7b4c249d70119104 Mon Sep 17 00:00:00 2001 From: sheilapaiva Date: Thu, 2 Feb 2023 22:05:22 -0300 Subject: [PATCH 6/6] adiciona testes --- api_hoco/routes/questions.py | 4 ++-- tests/test_routes_questions.py | 44 ++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/api_hoco/routes/questions.py b/api_hoco/routes/questions.py index a15506b..4f2b6f9 100644 --- a/api_hoco/routes/questions.py +++ b/api_hoco/routes/questions.py @@ -14,11 +14,11 @@ def create_question(): question = req_body['question'] answer = req_body['answer'] - '''if not (question and answer): + if not (question and answer): params_required = ['question (str)', 'answer (str)'] return make_response(input_not_given(params_required), 400) -''' + try: result = register_question(question, answer) return make_response(jsonify(result), 201) diff --git a/tests/test_routes_questions.py b/tests/test_routes_questions.py index 943158d..177362c 100644 --- a/tests/test_routes_questions.py +++ b/tests/test_routes_questions.py @@ -21,7 +21,7 @@ def client(app): return client -'''@mock.patch('api_hoco.routes.questions.register_question') +@mock.patch('api_hoco.routes.questions.register_question') def test_create_question(mock_register_question, client): expected_return = { "_id": "ID", @@ -29,24 +29,42 @@ def test_create_question(mock_register_question, client): "answer": "answer" } mock_register_question.return_value = expected_return - data_form = {"question": "question?", "answer": "answer"} - response = client.post("/question", data=data_form, content_type='application/json') + data_json = {"question": "question?", "answer": "answer"} + response = client.post("/question", json=data_json, content_type='application/json') response_json = response.json assert response.status_code == 201 assert response_json == expected_return +def test_create_question_missing_question(client): + data_json = {"question": "", "answer": "answer"} + response = client.post("/question", json=data_json, content_type='application/json') + response_json = response.json + + assert response.status_code == 400 + assert response_json == "Parameters required: ['question (str)', 'answer (str)']" + + +def test_create_question_missing_answer(client): + data_json = {"question": "question?", "answer": ""} + response = client.post("/question", json=data_json, content_type='application/json') + response_json = response.json + + assert response.status_code == 400 + assert response_json == "Parameters required: ['question (str)', 'answer (str)']" + + @mock.patch('api_hoco.routes.questions.register_question') def test_register_question_excecao_no_controller(mock_register_question, client): exception_msg = "uma exceção ocorreu no controller" mock_register_question.side_effect = Exception(exception_msg) - question = "question?" - response = client.post("/question", data=question, content_type='application/json') + data_json = {"question": "question?", "answer": "answer"} + response = client.post("/question", json=data_json, content_type='application/json') response_json = response.json assert response.status_code == 500 - assert "Error" in response_json''' + assert "Error:" in response_json @mock.patch('api_hoco.routes.questions.remove_question') @@ -66,4 +84,16 @@ def test_remove_question_missing_name(client): response_json = response.json assert response.status_code == 400 - assert response_json == "Parameters required: ['id (str)']" \ No newline at end of file + assert response_json == "Parameters required: ['id (str)']" + + +@mock.patch('api_hoco.routes.questions.remove_question') +def test_remove_question_excecao_no_controller(mock_remove_question, client): + exception_msg = "uma exceção ocorreu no controller" + mock_remove_question.side_effect = Exception(exception_msg) + id_question = "ID" + response = client.delete(f"/question?id={id_question}") + response_json = response.json + + assert response.status_code == 500 + assert "Error:" in response_json