WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
18 changes: 18 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def delete_skill(skill_id):
return jsonify({"error": "Skill not found"}), 404


@app.route('/resume/experience/<int:exp_id>', methods=['DELETE'])
def delete_experience(exp_id):
'''Deletes an experience by its index (ID).'''
if 0 <= exp_id < len(data["experience"]):
del data["experience"][exp_id]
return jsonify({"message": f"Experience with id {exp_id} deleted."}), 200
return jsonify({"error": "Experience not found"}), 404

@app.route('/resume/education/<int:edu_id>', methods=['DELETE'])
def delete_education(edu_id):
'''Deletes an education by its ID.'''
Expand All @@ -255,4 +263,14 @@ def edit_experience(exp_id):
exp.description = exp_data.get('description', exp.description)
exp.logo = exp_data.get('logo', exp.logo)
return jsonify(exp.__dict__), 200

return jsonify({"error": "Experience not found"}), 404

# Delete Existing Education by Index
@app.route('/resume/education/<int:edu_id>', methods=['DELETE'])
def delete_education(edu_id):
'''Deletes an education by its index (ID).'''
if 0 <= edu_id < len(data["education"]):
del data["education"][edu_id]
return jsonify({"message": f"Education with id {edu_id} deleted."}), 200
return jsonify({"error": "Education not found"}), 404
48 changes: 47 additions & 1 deletion test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def test_get_skill_by_id():
assert get_response.status_code == 200
assert get_response.get_json()["name"] == "Python"


def test_edit_experience():
'''Test updating an experience by ID'''
# Add a new experience to ensure there is one to update
Expand All @@ -349,7 +350,7 @@ def test_edit_experience():
post_response = app.test_client().post('/resume/experience', json=example_experience)
exp_id = post_response.json['id']

# Update the experience
# Update the experience BEFORE deleting
updated_experience = {
"title": "Updated Developer",
"company": "Updated Company",
Expand All @@ -371,6 +372,16 @@ def test_edit_experience():
expected_experience_no_id.pop("id")
assert expected_experience_no_id in experiences

# Now delete the experience
delete_response = app.test_client().delete(f'/resume/experience/{exp_id}')
assert delete_response.status_code == 200
assert delete_response.json["message"] == f"Experience with id {exp_id} deleted."

# Try to get all experiences and ensure the deleted one is not present
get_response = app.test_client().get('/resume/experience')
experiences = get_response.json
assert expected_experience_no_id not in experiences

def test_edit_education():
'''Test editing an education entry in the resume API.'''
# Add a new education to ensure there is one to update
Expand Down Expand Up @@ -400,6 +411,13 @@ def test_edit_education():
expected_education["id"] = edu_id
assert put_response.json == expected_education

# Get all educations and ensure the updated one is present
get_response = app.test_client().get('/resume/education')
educations = get_response.json
expected_education_no_id = expected_education.copy()
expected_education_no_id.pop("id")
assert expected_education_no_id in educations

# (Optional) Now delete and verify deletion
delete_response = app.test_client().delete(f'/resume/education/{edu_id}')
assert delete_response.status_code == 200
Expand Down Expand Up @@ -432,3 +450,31 @@ def test_delete_education():
get_all_response = app.test_client().get('/resume/education')
educations = get_all_response.json
assert example_education not in educations

def test_delete_experience():
'''Test deleting an experience by ID'''
# Add a new experience to ensure there is one to delete
example_experience = {
"title": "Delete Me",
"company": "Delete Company",
"start_date": "Jan 2025",
"end_date": "Dec 2025",
"description": "To be deleted",
"logo": "example-logo.png"
}
post_response = app.test_client().post('/resume/experience', json=example_experience)
exp_id = post_response.json['id']

# Delete the experience
delete_response = app.test_client().delete(f'/resume/experience/{exp_id}')
assert delete_response.status_code == 200
assert delete_response.json["message"] == f"Experience with id {exp_id} deleted."

# Try to get the deleted experience by ID (should be 404)
get_response = app.test_client().get(f'/resume/experience/{exp_id}')
assert get_response.status_code == 404

# Try to get all experiences and ensure the deleted one is not present
get_all_response = app.test_client().get('/resume/experience')
experiences = get_all_response.json
assert example_experience not in experiences
Loading