Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MLHProgram authored Nov 8, 2024
0 parents commit dc5416a
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pylint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
linter:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
30 changes: 30 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Pytest

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pytest test_pytest.py
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pyc
.venv
.pytest_cache/
__pycache__
.vscode
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Orientation Project - Python

Refer to the Fellowship LMS for information!

## Setup

```
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

## Run
```
flask run
```

### Run tests
```
pytest test_pytest.py
```

### Run Linter
```
pylint *.py
```
80 changes: 80 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'''
Flask Application
'''
from flask import Flask, jsonify, request
from models import Experience, Education, Skill

app = Flask(__name__)

data = {
"experience": [
Experience("Software Developer",
"A Cool Company",
"October 2022",
"Present",
"Writing Python Code",
"example-logo.png")
],
"education": [
Education("Computer Science",
"University of Tech",
"September 2019",
"July 2022",
"80%",
"example-logo.png")
],
"skill": [
Skill("Python",
"1-2 Years",
"example-logo.png")
]
}


@app.route('/test')
def hello_world():
'''
Returns a JSON test message
'''
return jsonify({"message": "Hello, World!"})


@app.route('/resume/experience', methods=['GET', 'POST'])
def experience():
'''
Handle experience requests
'''
if request.method == 'GET':
return jsonify()

if request.method == 'POST':
return jsonify({})

return jsonify({})

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

if request.method == 'POST':
return jsonify({})

return jsonify({})


@app.route('/resume/skill', methods=['GET', 'POST'])
def skill():
'''
Handles Skill requests
'''
if request.method == 'GET':
return jsonify({})

if request.method == 'POST':
return jsonify({})

return jsonify({})
Binary file added example-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# pylint: disable=R0913

'''
Models for the Resume API. Each class is related to
'''

from dataclasses import dataclass


@dataclass
class Experience:
'''
Experience Class
'''
title: str
company: str
start_date: str
end_date: str
description: str
logo: str


@dataclass
class Education:
'''
Education Class
'''
course: str
school: str
start_date: str
end_date: str
grade: str
logo: str


@dataclass
class Skill:
'''
Skill Class
'''
name: str
proficiency: str
logo: str
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask
pytest
pylint
74 changes: 74 additions & 0 deletions test_pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
Tests in Pytest
'''
from app import app


def test_client():
'''
Makes a request and checks the message received is the same
'''
response = app.test_client().get('/test')
assert response.status_code == 200
assert response.json['message'] == "Hello, World!"


def test_experience():
'''
Add a new experience and then get all experiences.
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"
}

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


def test_education():
'''
Add a new education and then get all educations.
Check that it returns the new education in that list
'''
example_education = {
"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[item_id] == example_education


def test_skill():
'''
Add a new skill and then get all skills.
Check that it returns the new skill in that list
'''
example_skill = {
"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[item_id] == example_skill

0 comments on commit dc5416a

Please sign in to comment.