Skip to content

Commit a51cbdd

Browse files
authored
Initial commit
0 parents  commit a51cbdd

File tree

9 files changed

+286
-0
lines changed

9 files changed

+286
-0
lines changed

.github/workflows/pylint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Pylint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
linter:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python 3.10
16+
uses: actions/setup-python@v3
17+
with:
18+
python-version: "3.10"
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r requirements.txt
23+
- name: Analysing the code with pylint
24+
run: |
25+
pylint $(git ls-files '*.py')

.github/workflows/pytest.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Pytest
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python 3.10
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: "3.10"
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
- name: Test with pytest
29+
run: |
30+
pytest test_pytest.py

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.pyc
2+
.venv
3+
.pytest_cache/
4+
__pycache__
5+
.vscode

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Orientation Project - Python
2+
3+
Refer to the Fellowship LMS for information!
4+
5+
## Setup
6+
7+
```
8+
python3 -m venv .venv
9+
source .venv/bin/activate
10+
pip install -r requirements.txt
11+
```
12+
13+
## Run
14+
```
15+
flask run
16+
```
17+
18+
### Run tests
19+
```
20+
pytest test_pytest.py
21+
```
22+
23+
### Run Linter
24+
```
25+
pylint *.py
26+
```

app.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'''
2+
Flask Application
3+
'''
4+
from flask import Flask, jsonify, request
5+
from models import Experience, Education, Skill
6+
7+
app = Flask(__name__)
8+
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+
}
32+
33+
34+
@app.route('/test')
35+
def hello_world():
36+
'''
37+
Returns a JSON test message
38+
'''
39+
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

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask
2+
pytest
3+
pylint

test_pytest.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'''
2+
Tests in Pytest
3+
'''
4+
from app import app
5+
6+
7+
def test_client():
8+
'''
9+
Makes a request and checks the message received is the same
10+
'''
11+
response = app.test_client().get('/test')
12+
assert response.status_code == 200
13+
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+
"title": "Software Developer",
24+
"company": "A Cooler Company",
25+
"start_date": "October 2022",
26+
"end_date": "Present",
27+
"description": "Writing JavaScript Code",
28+
"logo": "example-logo.png"
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)