Skip to content

Commit

Permalink
Merge pull request #26 from Lend-it/devel
Browse files Browse the repository at this point in the history
Release - 02/05/2021 - Quicksand v1.2.0
  • Loading branch information
youssef-md authored May 3, 2021
2 parents 8cff5b2 + cebfb04 commit 7160f1a
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 47 deletions.
64 changes: 33 additions & 31 deletions .github/workflows/automatic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
/tmp/sonar_cloud_gateway.json
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
4 changes: 2 additions & 2 deletions project/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 23 additions & 6 deletions project/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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__)
Expand Down Expand Up @@ -57,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(
[
Expand Down Expand Up @@ -94,12 +95,16 @@ def get_all_request():
def get_all_available_requests():
usermail = request.args.get("usermail")

today_date = datetime.now().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()
]

Expand All @@ -113,17 +118,29 @@ def get_all_available_requests():
return jsonify(response), 200


@request_blueprint.route("/requests/<productcategoryid>", methods=["GET"])
def get_filtered_request(productcategoryid):
@request_blueprint.route("/requests/available/<productcategoryid>", methods=["GET"])
def get_requests_filtered_by_category(productcategoryid):
usermail = request.args.get("usermail")

today_date = datetime.now().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},
Expand Down
85 changes: 81 additions & 4 deletions project/tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
REQUEST_BASE_URL = "/requests"
Expand Down Expand Up @@ -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!",
"[email protected]",
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="[email protected]",
)

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(
Expand Down Expand Up @@ -151,8 +226,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,
Expand All @@ -171,7 +246,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)
Expand Down

0 comments on commit 7160f1a

Please sign in to comment.