Skip to content

Commit c57e7cf

Browse files
committed
Add boilerplate functions and tests
1 parent 0accdc2 commit c57e7cf

5 files changed

Lines changed: 174 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# Orientation Project - Python
2+

app.py

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,80 @@
11
'''
22
Flask Application
33
'''
4-
from flask import Flask, jsonify
4+
from flask import Flask, jsonify, request
5+
from models import Experience, Education, Skill
56

67
app = Flask(__name__)
78

8-
data = [
9+
data = {
10+
"experience": [
11+
Experience("Software Developer",
12+
"A Cool Company",
13+
"October 2022",
14+
"Present",
15+
"Writing Python Code",
16+
"example-logo.png")
17+
],
18+
"education": [
19+
Education("Computer Science",
20+
"University of Tech",
21+
"September 2019",
22+
"July 2022",
23+
"80%",
24+
"example-logo.png")
25+
],
26+
"skill": [
27+
Skill("Python",
28+
"1-2 Years",
29+
"example-logo.png")
30+
]
31+
}
932

10-
]
1133

12-
'''
13-
Test Function
14-
'''
15-
16-
17-
@app.route('/')
34+
@app.route('/test')
1835
def hello_world():
1936
'''
20-
Returns a JSON message
37+
Returns a JSON test message
2138
'''
2239
return jsonify({"message": "Hello, World!"})
40+
41+
42+
@app.route('/resume/experience', methods=['GET', 'POST'])
43+
def experience():
44+
'''
45+
Handle experience requests
46+
'''
47+
if request.method == 'GET':
48+
return jsonify()
49+
50+
if request.method == 'POST':
51+
return jsonify({})
52+
53+
return jsonify({})
54+
55+
@app.route('/resume/education', methods=['GET', 'POST'])
56+
def education():
57+
'''
58+
Handles education requests
59+
'''
60+
if request.method == 'GET':
61+
return jsonify({})
62+
63+
if request.method == 'POST':
64+
return jsonify({})
65+
66+
return jsonify({})
67+
68+
69+
@app.route('/resume/skill', methods=['GET', 'POST'])
70+
def skill():
71+
'''
72+
Handles Skill requests
73+
'''
74+
if request.method == 'GET':
75+
return jsonify({})
76+
77+
if request.method == 'POST':
78+
return jsonify({})
79+
80+
return jsonify({})

example-logo.png

4.88 KB
Loading

models.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# pylint: disable=R0913
2+
3+
'''
4+
Models for the Resume API. Each class is related to
5+
'''
6+
7+
from dataclasses import dataclass
8+
9+
10+
@dataclass
11+
class Experience:
12+
'''
13+
Experience Class
14+
'''
15+
title: str
16+
company: str
17+
start_date: str
18+
end_date: str
19+
description: str
20+
logo: str
21+
22+
23+
@dataclass
24+
class Education:
25+
'''
26+
Education Class
27+
'''
28+
course: str
29+
school: str
30+
start_date: str
31+
end_date: str
32+
grade: str
33+
logo: str
34+
35+
36+
@dataclass
37+
class Skill:
38+
'''
39+
Skill Class
40+
'''
41+
name: str
42+
proficiency: str
43+
logo: str

test_pytest.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,67 @@ def test_client():
88
'''
99
Makes a request and checks the message received is the same
1010
'''
11-
response = app.test_client().get('/')
11+
response = app.test_client().get('/test')
1212
assert response.status_code == 200
1313
assert response.json['message'] == "Hello, World!"
14+
15+
16+
def test_experience():
17+
'''
18+
Add a new experience and then get all experiences.
19+
20+
Check that it returns the new experience in that list
21+
'''
22+
example_experience = {
23+
"company": "A Cooler Company",
24+
"description": "Writing JavaScript Code",
25+
"end_date": "Present",
26+
"logo": "example-logo.png",
27+
"start_date": "October 2022",
28+
"title": "Software Developer"
29+
}
30+
31+
item_id = app.test_client().post('/resume/experience',
32+
json=example_experience).json['id']
33+
response = app.test_client().get('/resume/experience')
34+
assert response.json[item_id] == example_experience
35+
36+
37+
def test_education():
38+
'''
39+
Add a new education and then get all educations.
40+
41+
Check that it returns the new education in that list
42+
'''
43+
example_education = {
44+
"course": "Engineering",
45+
"school": "NYU",
46+
"start_date": "October 2022",
47+
"end_date": "August 2024",
48+
"grade": "86%",
49+
"logo": "example-logo.png",
50+
}
51+
item_id = app.test_client().post('/resume/education',
52+
json=example_education).json['id']
53+
54+
response = app.test_client().get('/resume/education')
55+
assert response.json[item_id] == example_education
56+
57+
58+
def test_skill():
59+
'''
60+
Add a new skill and then get all skills.
61+
62+
Check that it returns the new skill in that list
63+
'''
64+
example_skill = {
65+
"name": "JavaScript",
66+
"proficiency": "2-4 years",
67+
"logo": "example-logo.png"
68+
}
69+
70+
item_id = app.test_client().post('/resume/skill',
71+
json=example_skill).json['id']
72+
73+
response = app.test_client().get('/resume/skill')
74+
assert response.json[item_id] == example_skill

0 commit comments

Comments
 (0)