From 1e028ac6954b202da6ddb3f31533416f86a3f7bf Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Thu, 22 Apr 2021 23:47:18 -0300 Subject: [PATCH 1/6] feat: fga-eps-mds/2020.2-Lend.it#138 Added end date as filter in the get_all_available_requests Co-authored-by: Thiago Mesquita Co-authored-by: Mateus Maia --- project/api/models.py | 4 ++-- project/api/views.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/project/api/models.py b/project/api/models.py index bbb6a44..01b5392 100755 --- a/project/api/models.py +++ b/project/api/models.py @@ -62,8 +62,8 @@ def to_json(self): return { "requestid": self.requestid, "productname": self.productname, - "startdate": self.startdate, - "enddate": self.enddate, + "startdate": self.startdate.isoformat(), + "enddate": self.enddate.isoformat(), "description": self.description, "requester": self.requester, "finalized": self.finalized, diff --git a/project/api/views.py b/project/api/views.py index b6481f4..117e159 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -4,12 +4,17 @@ from project.api.models import db from project.api.models import Category from project.api.utils import get_category_name - +from datetime import datetime, date category_blueprint = Blueprint("categories", __name__) request_blueprint = Blueprint("requests", __name__) +def convert_enddate(enddate): + parsed_date = date.fromisoformat(enddate) + return parsed_date + + @category_blueprint.route("/product_category", methods=["GET"]) def get_all_categories(): response = { @@ -94,12 +99,18 @@ def get_all_request(): def get_all_available_requests(): usermail = request.args.get("usermail") + today_date = datetime.now() + today_date = today_date.replace(hour=0, minute=0, second=0, microsecond=0) + today_date.isoformat() + error_response = {"status": "fail", "message": "Request not found"} available_requests = [ request.to_json() for request in Request.query.filter( - Request.lender == None, Request.requester != usermail + Request.lender == None, + Request.requester != usermail, + Request.enddate >= today_date, ).all() ] From d2f1ce817d488acc83b5bbd2791ad8768ba550f2 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 23 Apr 2021 20:20:33 -0300 Subject: [PATCH 2/6] refactor: fga-eps-mds/2020.2-Lend.it#138 Refactored get requests filtered by category route Co-authored-by: Thiago Mesquita Co-authored-by: Mateus Maia --- project/api/views.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 117e159..807e62f 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -10,11 +10,6 @@ request_blueprint = Blueprint("requests", __name__) -def convert_enddate(enddate): - parsed_date = date.fromisoformat(enddate) - return parsed_date - - @category_blueprint.route("/product_category", methods=["GET"]) def get_all_categories(): response = { @@ -62,6 +57,7 @@ def add_categories(): def get_all_request(): requester = request.args.get("requester") lender = request.args.get("lender") + if requester: requests = get_category_name( [ @@ -124,17 +120,31 @@ def get_all_available_requests(): return jsonify(response), 200 -@request_blueprint.route("/requests/", methods=["GET"]) -def get_filtered_request(productcategoryid): +@request_blueprint.route("/requests/available/", methods=["GET"]) +def get_requests_filtered_by_category(productcategoryid): + usermail = request.args.get("usermail") + + today_date = datetime.now() + today_date = today_date.replace(hour=0, minute=0, second=0, microsecond=0) + today_date.isoformat() + + error_response = {"status": "fail", "message": "Request not found"} + requests = get_category_name( [ request.to_json() - for request in Request.query.filter_by( - productcategoryid=productcategoryid + for request in Request.query.filter( + Request.lender == None, + Request.requester != usermail, + Request.enddate >= today_date, + Request.productcategoryid == productcategoryid, ).all() ] ) + if not requests: + return jsonify(error_response), 404 + response = { "status": "success", "data": {"requests": requests}, From 1563bfa07ba91f752cabdffc77fe38bc658d2468 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 23 Apr 2021 22:35:06 -0300 Subject: [PATCH 3/6] test: fga-eps-mds/2020.2-Lend.it#138 Route and name changed in the test get requests filtered by category Co-authored-by: Thiago Mesquita Co-authored-by: Mateus Maia --- project/tests/test_request.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/project/tests/test_request.py b/project/tests/test_request.py index 04f7e9c..09d14cc 100644 --- a/project/tests/test_request.py +++ b/project/tests/test_request.py @@ -10,7 +10,7 @@ FAKE_DESCRIPTION = ( "Queria um Uno emprestado para jogar com meus amigos neste fim de semana!" ) -FAKE_ENDDATE = "2020-09-30 00:00:00.000" +FAKE_ENDDATE = "2021-09-30 00:00:00.000" FAKE_STARTDATE = "2020-09-12 00:00:00.000" FAKE_REQUESTER = "matheus@email.com" REQUEST_BASE_URL = "/requests" @@ -151,8 +151,8 @@ def test_get_all_requests_lender(self): self.assertEqual(len(data["data"]["requests"]), 1) - def test_get_filtered_requests(self): - add_category("Eletrodomésticos") + def test_get_requests_filtered_by_category(self): + add_category("Jogos") add_request( "Jogo da vida", FAKE_STARTDATE, @@ -171,7 +171,9 @@ def test_get_filtered_requests(self): ) with self.client: - response = self.client.get(f"{REQUEST_BASE_URL}/1") + response = self.client.get( + f"{REQUEST_BASE_URL}/available/1?usermail={FAKE_EMAIL}" + ) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) From 8b7263d360d132da6873273a760f6a5452e5cb9f Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 23 Apr 2021 22:53:38 -0300 Subject: [PATCH 4/6] test: fga-eps-mds/2020.2-Lend.it#138 Created test for get all available requests and not available requests Co-authored-by: Thiago Mesquita Co-authored-by: Mateus Maia --- project/tests/test_request.py | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/project/tests/test_request.py b/project/tests/test_request.py index 09d14cc..f4be415 100644 --- a/project/tests/test_request.py +++ b/project/tests/test_request.py @@ -91,6 +91,81 @@ def test_get_all_requests(self): self.assertEqual(len(data["data"]["requests"]), 3) + def test_get_all_available_requests(self): + add_category("Eletrodomésticos") + add_request( + "Banco Imobiliario", + FAKE_STARTDATE, + FAKE_ENDDATE, + "Queria um banco imobiliário emprestado para jogar com meus amigos neste fim de semana!", + FAKE_REQUESTER, + 1, + ) + add_request( + "Jogo da vida", + FAKE_STARTDATE, + FAKE_ENDDATE, + "Queria um jogo da vida emprestado para jogar com meus amigos neste fim de semana!", + FAKE_REQUESTER, + 1, + ) + add_request( + "War", + FAKE_STARTDATE, + FAKE_ENDDATE, + "Queria um war emprestado para jogar com meus amigos neste fim de semana!", + FAKE_REQUESTER, + 1, + ) + + with self.client: + response = self.client.get( + f"{REQUEST_BASE_URL}/available?usermail={FAKE_EMAIL}" + ) + data = json.loads(response.data.decode()) + + self.assertEqual(response.status_code, 200) + self.assertIn("success", data["status"]) + + self.assertEqual(len(data["data"]["available requests"]), 3) + + def test_not_available_requests(self): + add_category("Eletrodomésticos") + add_request( + "Banco Imobiliario", + FAKE_STARTDATE, + FAKE_ENDDATE, + "Queria um banco imobiliário emprestado para jogar com meus amigos neste fim de semana!", + "tah_tu@email.com", + 1, + ) + add_request( + "Jogo da vida", + FAKE_STARTDATE, + "2021-01-30 00:00:00.000", + "Queria um jogo da vida emprestado para jogar com meus amigos neste fim de semana!", + FAKE_REQUESTER, + 1, + ) + add_request( + "War", + FAKE_STARTDATE, + FAKE_ENDDATE, + "Queria um war emprestado para jogar com meus amigos neste fim de semana!", + FAKE_REQUESTER, + 1, + lender="jose@email.com", + ) + + with self.client: + response = self.client.get( + f"{REQUEST_BASE_URL}/available?usermail={FAKE_EMAIL}" + ) + data = json.loads(response.data.decode()) + + self.assertEqual(response.status_code, 404) + self.assertIn("fail", data["status"]) + def test_get_all_requests_requester(self): add_category("Eletrodomésticos") add_request( From 8316ace2c042a722c4b7204aa9824fbc27a9d466 Mon Sep 17 00:00:00 2001 From: Lucas Dutra Date: Wed, 28 Apr 2021 23:01:24 -0300 Subject: [PATCH 5/6] perf: fga-eps-mds/2020.2-Lend.it#138 Update datetime now method Co-authored-by: Thais Reboucas Co-authored-by: Thiago Mesquita Co-authored-by: Mateus Maia --- Makefile | 8 ++++---- project/api/views.py | 8 ++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 7530dc8..6d2eae1 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ run-build: fi test: - sudo docker-compose -f docker-compose.dev.yml run request python manage.py test + sudo docker-compose -f docker-compose.dev.yml run --rm request python manage.py test lint: - sudo docker-compose -f docker-compose.dev.yml run request black . + sudo docker-compose -f docker-compose.dev.yml run --rm request black . check-db: sudo docker-compose -f docker-compose.dev.yml exec db psql -U postgres @@ -47,8 +47,8 @@ down: sudo docker-compose -f docker-compose.dev.yml down recreate-db: - sudo docker-compose -f docker-compose.dev.yml run request python manage.py recreate-db + sudo docker-compose -f docker-compose.dev.yml run --rm request python manage.py recreate-db cov-html: - sudo docker-compose -f docker-compose.dev.yml run request python manage.py cov; + sudo docker-compose -f docker-compose.dev.yml run --rm request python manage.py cov; google-chrome $(CURRENT_DIR)/htmlcov/index.html; diff --git a/project/api/views.py b/project/api/views.py index 807e62f..a6f779a 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -95,9 +95,7 @@ def get_all_request(): def get_all_available_requests(): usermail = request.args.get("usermail") - today_date = datetime.now() - today_date = today_date.replace(hour=0, minute=0, second=0, microsecond=0) - today_date.isoformat() + today_date = datetime.now().date().isoformat() error_response = {"status": "fail", "message": "Request not found"} @@ -124,9 +122,7 @@ def get_all_available_requests(): def get_requests_filtered_by_category(productcategoryid): usermail = request.args.get("usermail") - today_date = datetime.now() - today_date = today_date.replace(hour=0, minute=0, second=0, microsecond=0) - today_date.isoformat() + today_date = datetime.now().date().isoformat() error_response = {"status": "fail", "message": "Request not found"} From cebfb04e15ede8c7d3d2af2993ebe8dc0c0434c0 Mon Sep 17 00:00:00 2001 From: youssef-md Date: Sun, 2 May 2021 22:08:42 -0300 Subject: [PATCH 6/6] ci: update sonar metrics uri --- .github/workflows/automatic-release.yml | 64 +++++++++++++------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/.github/workflows/automatic-release.yml b/.github/workflows/automatic-release.yml index 99947eb..dcd4a59 100644 --- a/.github/workflows/automatic-release.yml +++ b/.github/workflows/automatic-release.yml @@ -3,45 +3,47 @@ on: push: branches: - "release-candidate" - + jobs: pre-release: name: "Pre Release" runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v2 - - run: mkdir -p /tmp/ - - run: curl --location --request GET 'https://sonarcloud.io/api/measures/search_history?component=Lend-it_Request&metrics=new_technical_debt,blocker_violations,bugs,classes,code_smells,cognitive_complexity,comment_lines,comment_lines_density,complexity_in_classes,complexity_in_functions,branch_coverage,new_branch_coverage,new_conditions_to_cover,confirmed_issues,coverage,new_coverage,complexity,development_cost,new_development_cost,duplicated_blocks,new_duplicated_blocks,duplicated_files,duplicated_lines,duplicated_lines_density,new_duplicated_lines_density,new_duplicated_lines,duplications_data,effort_to_reach_maintainability_rating_a,false_positive_issues,file_complexity_distribution,files,function_complexity_distribution,functions,generated_lines,generated_ncloc,info_violations,violations,line_coverage,new_line_coverage,ncloc,ncloc_language_distribution,lines_to_cover,new_lines_to_cover,sqale_rating,new_maintainability_rating,major_violations,minor_violations,new_blocker_violations,new_bugs,new_code_smells,new_critical_violations,new_info_violations,new_violations,new_lines,new_major_violations,new_minor_violations,new_security_hotspots,new_vulnerabilities,open_issues,quality_profiles,projects,public_api,public_documented_api_density,quality_gate_details,alert_status,reliability_rating,new_reliability_rating,reliability_remediation_effort,new_reliability_remediation_effort,reopened_issues,security_hotspots,security_hotspots_reviewed,new_security_hotspots_reviewed,security_rating,new_security_rating,security_remediation_effort,new_security_remediation_effort,security_review_rating,new_security_review_rating,security_hotspots_reviewed_status,new_security_hotspots_reviewed_status,security_hotspots_to_review_status,new_security_hotspots_to_review_status,skipped_tests,statements,sqale_index,sqale_debt_ratio,new_sqale_debt_ratio' > /tmp/sonar_cloud_request.json - - uses: actions/upload-artifact@v2 - with: - name: sonar_cloud_request.json - path: /tmp/sonar_cloud_request.json - - run: curl --location --request GET 'https://sonarcloud.io/api/measures/search_history?component=Lend-it_Rating&metrics=new_technical_debt,blocker_violations,bugs,classes,code_smells,cognitive_complexity,comment_lines,comment_lines_density,complexity_in_classes,complexity_in_functions,branch_coverage,new_branch_coverage,new_conditions_to_cover,confirmed_issues,coverage,new_coverage,complexity,development_cost,new_development_cost,duplicated_blocks,new_duplicated_blocks,duplicated_files,duplicated_lines,duplicated_lines_density,new_duplicated_lines_density,new_duplicated_lines,duplications_data,effort_to_reach_maintainability_rating_a,false_positive_issues,file_complexity_distribution,files,function_complexity_distribution,functions,generated_lines,generated_ncloc,info_violations,violations,line_coverage,new_line_coverage,ncloc,ncloc_language_distribution,lines_to_cover,new_lines_to_cover,sqale_rating,new_maintainability_rating,major_violations,minor_violations,new_blocker_violations,new_bugs,new_code_smells,new_critical_violations,new_info_violations,new_violations,new_lines,new_major_violations,new_minor_violations,new_security_hotspots,new_vulnerabilities,open_issues,quality_profiles,projects,public_api,public_documented_api_density,quality_gate_details,alert_status,reliability_rating,new_reliability_rating,reliability_remediation_effort,new_reliability_remediation_effort,reopened_issues,security_hotspots,security_hotspots_reviewed,new_security_hotspots_reviewed,security_rating,new_security_rating,security_remediation_effort,new_security_remediation_effort,security_review_rating,new_security_review_rating,security_hotspots_reviewed_status,new_security_hotspots_reviewed_status,security_hotspots_to_review_status,new_security_hotspots_to_review_status,skipped_tests,statements,sqale_index,sqale_debt_ratio,new_sqale_debt_ratio' > /tmp/sonar_cloud_rating.json - - uses: actions/upload-artifact@v2 - with: - name: sonar_cloud_rating.json - path: /tmp/sonar_cloud_rating.json - - run: curl --location --request GET 'https://sonarcloud.io/api/measures/search_history?component=Lend-it_User&metrics=new_technical_debt,blocker_violations,bugs,classes,code_smells,cognitive_complexity,comment_lines,comment_lines_density,complexity_in_classes,complexity_in_functions,branch_coverage,new_branch_coverage,new_conditions_to_cover,confirmed_issues,coverage,new_coverage,complexity,development_cost,new_development_cost,duplicated_blocks,new_duplicated_blocks,duplicated_files,duplicated_lines,duplicated_lines_density,new_duplicated_lines_density,new_duplicated_lines,duplications_data,effort_to_reach_maintainability_rating_a,false_positive_issues,file_complexity_distribution,files,function_complexity_distribution,functions,generated_lines,generated_ncloc,info_violations,violations,line_coverage,new_line_coverage,ncloc,ncloc_language_distribution,lines_to_cover,new_lines_to_cover,sqale_rating,new_maintainability_rating,major_violations,minor_violations,new_blocker_violations,new_bugs,new_code_smells,new_critical_violations,new_info_violations,new_violations,new_lines,new_major_violations,new_minor_violations,new_security_hotspots,new_vulnerabilities,open_issues,quality_profiles,projects,public_api,public_documented_api_density,quality_gate_details,alert_status,reliability_rating,new_reliability_rating,reliability_remediation_effort,new_reliability_remediation_effort,reopened_issues,security_hotspots,security_hotspots_reviewed,new_security_hotspots_reviewed,security_rating,new_security_rating,security_remediation_effort,new_security_remediation_effort,security_review_rating,new_security_review_rating,security_hotspots_reviewed_status,new_security_hotspots_reviewed_status,security_hotspots_to_review_status,new_security_hotspots_to_review_status,skipped_tests,statements,sqale_index,sqale_debt_ratio,new_sqale_debt_ratio' > /tmp/sonar_cloud_user.json - - uses: actions/upload-artifact@v2 - with: - name: sonar_cloud_user.json - path: /tmp/sonar_cloud_user.json + - uses: actions/checkout@v2 + - run: mkdir -p /tmp/ + - run: curl --location --request GET 'https://sonarcloud.io/api/measures/component_tree?component=Lend-it_Request&metricKeys=files,functions,complexity,coverage,ncloc,comment_lines_density,duplicated_lines_density,security_rating,tests,test_success_density,test_execution_time,reliability_rating&ps=500' > /tmp/sonar_cloud_request.json + - uses: actions/upload-artifact@v2 + with: + name: sonar_cloud_request.json + path: /tmp/sonar_cloud_request.json + + - run: curl --location --request GET 'https://sonarcloud.io/api/measures/component_tree?component=Lend-it_Rating&metricKeys=files,functions,complexity,coverage,ncloc,comment_lines_density,duplicated_lines_density,security_rating,tests,test_success_density,test_execution_time,reliability_rating&ps=500' > /tmp/sonar_cloud_rating.json + - uses: actions/upload-artifact@v2 + with: + name: sonar_cloud_rating.json + path: /tmp/sonar_cloud_rating.json + + - run: curl --location --request GET 'https://sonarcloud.io/api/measures/component_tree?component=Lend-it_User&metricKeys=files,functions,complexity,coverage,ncloc,comment_lines_density,duplicated_lines_density,security_rating,tests,test_success_density,test_execution_time,reliability_rating&ps=500' > /tmp/sonar_cloud_user.json + - uses: actions/upload-artifact@v2 + with: + name: sonar_cloud_user.json + path: /tmp/sonar_cloud_user.json - - run: curl --location --request GET 'https://sonarcloud.io/api/measures/search_history?component=Lend-it_Gateway&metrics=new_technical_debt,blocker_violations,bugs,classes,code_smells,cognitive_complexity,comment_lines,comment_lines_density,complexity_in_classes,complexity_in_functions,branch_coverage,new_branch_coverage,new_conditions_to_cover,confirmed_issues,coverage,new_coverage,complexity,development_cost,new_development_cost,duplicated_blocks,new_duplicated_blocks,duplicated_files,duplicated_lines,duplicated_lines_density,new_duplicated_lines_density,new_duplicated_lines,duplications_data,effort_to_reach_maintainability_rating_a,false_positive_issues,file_complexity_distribution,files,function_complexity_distribution,functions,generated_lines,generated_ncloc,info_violations,violations,line_coverage,new_line_coverage,ncloc,ncloc_language_distribution,lines_to_cover,new_lines_to_cover,sqale_rating,new_maintainability_rating,major_violations,minor_violations,new_blocker_violations,new_bugs,new_code_smells,new_critical_violations,new_info_violations,new_violations,new_lines,new_major_violations,new_minor_violations,new_security_hotspots,new_vulnerabilities,open_issues,quality_profiles,projects,public_api,public_documented_api_density,quality_gate_details,alert_status,reliability_rating,new_reliability_rating,reliability_remediation_effort,new_reliability_remediation_effort,reopened_issues,security_hotspots,security_hotspots_reviewed,new_security_hotspots_reviewed,security_rating,new_security_rating,security_remediation_effort,new_security_remediation_effort,security_review_rating,new_security_review_rating,security_hotspots_reviewed_status,new_security_hotspots_reviewed_status,security_hotspots_to_review_status,new_security_hotspots_to_review_status,skipped_tests,statements,sqale_index,sqale_debt_ratio,new_sqale_debt_ratio' > /tmp/sonar_cloud_gateway.json - - uses: actions/upload-artifact@v2 - with: - name: sonar_cloud_gateway.json - path: /tmp/sonar_cloud_gateway.json + - run: curl --location --request GET 'https://sonarcloud.io/api/measures/component_tree?component=Lend-it_Gateway&metricKeys=files,functions,complexity,coverage,ncloc,comment_lines_density,duplicated_lines_density,security_rating,tests,test_success_density,test_execution_time,reliability_rating&ps=500' > /tmp/sonar_cloud_gateway.json + - uses: actions/upload-artifact@v2 + with: + name: sonar_cloud_gateway.json + path: /tmp/sonar_cloud_gateway.json - - uses: "marvinpinto/action-automatic-releases@latest" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest" - prerelease: false - title: "Automatic Release-Candidate release" - files: | + - uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest" + prerelease: false + title: "Automatic Release-Candidate release" + files: | /tmp/sonar_cloud_request.json /tmp/sonar_cloud_rating.json /tmp/sonar_cloud_user.json - /tmp/sonar_cloud_gateway.json \ No newline at end of file + /tmp/sonar_cloud_gateway.json