generated from MLH-Fellowship/orientation-project-python
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dc5416a
Showing
9 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.pyc | ||
.venv | ||
.pytest_cache/ | ||
__pycache__ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flask | ||
pytest | ||
pylint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |