Skip to content

Commit 179dff0

Browse files
authored
Merge pull request #23 from anandkaranubc/feat/delete-edu
feat: add `DELETE` support for `/resume/education`
2 parents 2550f0e + 1515b89 commit 179dff0

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ def education():
6666
return jsonify({})
6767

6868

69+
@app.route('/resume/education/<int:index>', methods=['DELETE'])
70+
def delete_education(index):
71+
"""
72+
Deletes an education entry at the specified index.
73+
74+
Parameters
75+
----------
76+
index : int
77+
The index of the education entry to delete.
78+
79+
Returns
80+
-------
81+
Response
82+
JSON response indicating success (with `deleted: True`) or
83+
failure (with an error message and 404 status code).
84+
"""
85+
if 0 <= index < len( data[ "education" ] ):
86+
data[ "education" ].pop( index )
87+
return jsonify( { "message": "Education has been deleted" } ), 200
88+
return jsonify( { "error": "Index out of range" } ), 404
89+
90+
6991
@app.route('/resume/skill', methods=['GET', 'POST'])
7092
def skill():
7193
'''

test_pytest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,40 @@ def test_education():
5555
assert response.json[item_id] == example_education
5656

5757

58+
def test_delete_education():
59+
'''
60+
Add and delete an education entry by index.
61+
62+
Check that the entry is deleted successfully and the response is correct.
63+
'''
64+
example_education = {
65+
"course": "Computer Science",
66+
"school": "UBC",
67+
"start_date": "January 2022",
68+
"end_date": "June 2026",
69+
"grade": "90%",
70+
"logo": "example-logo.png"
71+
}
72+
73+
client = app.test_client()
74+
75+
# Add new education:
76+
# TODO: Implement the '/resume/education' POST route in `app.py` before running this test. # pylint: disable=fixme
77+
post_resp = client.post('/resume/education', json=example_education)
78+
assert post_resp.status_code == 200
79+
item_id = post_resp.json['id']
80+
81+
# Delete the education using the ID:
82+
del_resp = client.delete(f'/resume/education/{item_id}')
83+
assert del_resp.status_code == 200
84+
assert del_resp.json['message'] == "Education has been deleted"
85+
86+
# Delete again to check if it fails:
87+
del_resp = client.delete(f'/resume/education/{item_id}')
88+
assert del_resp.status_code == 404
89+
assert del_resp.json['error'] == "Index out of range"
90+
91+
5892
def test_skill():
5993
'''
6094
Add a new skill and then get all skills.

0 commit comments

Comments
 (0)