Skip to content

Commit

Permalink
feat: reorder section items on the backend (#35)
Browse files Browse the repository at this point in the history
* feat: reorder section items on the backend

* fix pylint issues

* tests for PUT changes

* address failing test cases

* fix linting
  • Loading branch information
Shopiley authored Oct 11, 2024
1 parent f0efad4 commit 0aaeac0
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 32 deletions.
90 changes: 70 additions & 20 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,58 +109,92 @@ def edit_user(body):
return jsonify({"error": "Unsupported request method !"}), 405


@app.route("/resume/experience", methods=["GET", "POST"])
@app.route("/resume/experience", methods=["GET", "POST", 'PUT'])
def experience():
"""
Handle experience requests
"""

if request.method == "GET":
if request.method == 'GET':
return jsonify(
{"experience": [exp.__dict__ for exp in data["experience"]]})

if request.method == "POST":
new_experience = request.json
new_exp = new_experience["data"][0]
experience_instance = Experience(
new_experience["title"],
new_experience["company"],
new_experience["start_date"],
new_experience["end_date"],
new_experience["description"],
new_experience["logo"],
new_exp["title"],
new_exp["company"],
new_exp["start_date"],
new_exp["end_date"],
new_exp["description"],
new_exp["logo"],
)
data["experience"].append(experience_instance)
return jsonify({"id": len(data["experience"]) - 1})

return jsonify({})
if request.method == 'PUT':
body = request.get_json()
new_experience_order = []
for exp in body['data']:
title = exp['title']
company = exp['company']
start_date = exp['start_date']
end_date = exp['end_date']
description = exp['description']
logo = exp['logo']

new_experience_order.append(
Experience(title, company, start_date, end_date, description, logo)
)
data['experience'] = new_experience_order

return_data = [item.__dict__ for item in data['experience']]
return jsonify(return_data), 200

return jsonify({"error": "Unsupported request method !"}), 405

@app.route("/resume/education", methods=["GET", "POST"])
@app.route('/resume/education', methods=['GET', 'POST', 'PUT'])
def education():
"""
Handles education requests
"""
if request.method == "GET":
if request.method == 'GET':
return jsonify(
{"education": [edu.__dict__ for edu in data["education"]]})

if request.method == "POST":
new_education = request.json
new_edu = new_education["data"][0]
education_instance = Education(
new_education["course"],
new_education["school"],
new_education["start_date"],
new_education["end_date"],
new_education["grade"],
new_education["logo"],
new_edu["course"],
new_edu["school"],
new_edu["start_date"],
new_edu["end_date"],
new_edu["grade"],
new_edu["logo"],
)
data["education"].append(education_instance)
return jsonify({"id": len(data["education"]) - 1})

if request.method == 'PUT':
body = request.get_json()
new_education_order = []
for edu in body['data']:
course = edu['course']
school = edu['school']
start_date = edu['start_date']
end_date = edu['end_date']
grade = edu['grade']
logo = edu['logo']
new_education_order.append(Education(course, school, start_date, end_date, grade, logo))
data['education'] = new_education_order

return_data = [item.__dict__ for item in data['education']]
return jsonify(return_data), 200
return jsonify({})


@app.route("/resume/skill", methods=["GET", "POST"])
@app.route("/resume/skill", methods=["GET", "POST", 'PUT'])
def skill():
"""
Handles Skill requests
Expand All @@ -171,12 +205,28 @@ def skill():

if request.method == "POST":
new_skill = request.json
skill_data = new_skill["data"][0]
skill_instance = Skill(
new_skill["name"], new_skill["proficiency"], new_skill["logo"]
skill_data["name"],
skill_data["proficiency"],
skill_data["logo"]
)
data["skill"].append(skill_instance)
return jsonify({"id": len(data["skill"]) - 1})

if request.method == 'PUT':
body = request.get_json()
new_skill_order = []
for _skill in body['data']:
name = _skill['name']
proficiency = _skill['proficiency']
logo = _skill['logo']
new_skill_order.append(Skill(name, proficiency, logo))
data['skill'] = new_skill_order

return_data = [item.__dict__ for item in data['skill']]
return jsonify(return_data), 200

return jsonify({})


Expand Down
88 changes: 76 additions & 12 deletions test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,43 @@ def test_experience():
Check that it returns the new experience in that list
'''
example_experience = {
"title": "Software Developer",
"company": "A Cooler Company",
"start_date": "October 2022",
"end_date": "Present",
"description": "Writing JavaScript Code",
"logo": "example-logo.png"
"data": [
{
"title": "Software Developer",
"company": "A Cooler Company",
"start_date": "October 2022",
"end_date": "Present",
"description": "Writing JavaScript Code",
"logo": "example-logo.png"
}
]
}

item_id = app.test_client().post('/resume/experience',
json=example_experience).json['id']
response = app.test_client().get('/resume/experience')
assert response.json["experience"][item_id] == example_experience
print(response.json)
assert response.json["experience"][item_id] == example_experience['data'][0]

# test PUT request
response = app.test_client().put('/resume/experience', json={"data": [
{
"title": "Software Developer",
"company": "The Coolest Company",
"start_date": "October 2024",
"end_date": "Present",
"description": "Writing Python Code",
"logo": "example-logo.png"
}
]})
assert response.status_code == 200
response_data = response.json[0]
assert response_data['title'] == 'Software Developer'
assert response_data['company'] == 'The Coolest Company'
assert response_data['start_date'] == 'October 2024'
assert response_data['end_date'] == 'Present'
assert response_data['description'] == 'Writing Python Code'
assert response_data['logo'] == 'example-logo.png'


def test_education():
Expand All @@ -82,19 +107,41 @@ def test_education():
Check that it returns the new education in that list
'''
example_education = {
example_education = {"data": [{
"course": "Engineering",
"school": "NYU",
"start_date": "October 2022",
"end_date": "August 2024",
"grade": "86%",
"logo": "example-logo.png"
}
}]}

item_id = app.test_client().post('/resume/education',
json=example_education).json['id']

response = app.test_client().get('/resume/education')
assert response.json["education"][item_id] == example_education
assert response.json["education"][item_id] == example_education['data'][0]

response = app.test_client().put('/resume/education', json={
"data": [
{
"course": "Updated Course",
"school": "Updated University",
"start_date": "September 2020",
"end_date": "June 2023",
"grade": "90%",
"logo": "new-education-logo.png"
}
]
})
assert response.status_code == 200
response_data = response.json[0]
assert response_data['course'] == 'Updated Course'
assert response_data['school'] == 'Updated University'
assert response_data['start_date'] == 'September 2020'
assert response_data['end_date'] == 'June 2023'
assert response_data['grade'] == '90%'
assert response_data['logo'] == 'new-education-logo.png'


def test_skill():
Expand All @@ -103,17 +150,34 @@ def test_skill():
Check that it returns the new skill in that list
'''
example_skill = {
example_skill = { "data":[{
"name": "JavaScript",
"proficiency": "2-4 years",
"logo": "example-logo.png"
}]
}

item_id = app.test_client().post('/resume/skill',
json=example_skill).json['id']

response = app.test_client().get('/resume/skill')
assert response.json["skills"][item_id] == example_skill
assert response.json["skills"][item_id] == example_skill["data"][0]

response = app.test_client().put('/resume/skill', json={
"data": [
{
"name": "Python",
"proficiency": "4-6 years",
"logo": "new-logo.png"
}
]
})
assert response.status_code == 200
response_data = response.json[0]
assert response_data['name'] == 'Python'
assert response_data['proficiency'] == '4-6 years'
assert response_data['logo'] == 'new-logo.png'



def test_get_project():
Expand Down

0 comments on commit 0aaeac0

Please sign in to comment.