Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run mypy, run unittests on GitHub #2

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run python only unit tests

on:
push:
workflow_dispatch:

jobs:
test-povertyscale:
runs-on: ubuntu-latest
name: Run python only unit tests
env:
ISUNITTEST: true
steps:
- run: sudo apt-get update && sudo apt-get -y install libcurl4-openssl-dev build-essential python3-dev libldap2-dev libsasl2-dev slapd ldap-utils tox lcov valgrind libzbar0
- name: Check
uses: actions/checkout@v2
- run: pip install virtualenv
- run: virtualenv -p python3.8 .venv
- run: .venv/bin/pip install -r docassemble/PovertyScale/requirements.txt
- run: .venv/bin/pip install --editable .
- run: .venv/bin/python3 -m mypy .
- run: .venv/bin/python3 -m unittest discover
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
20 changes: 10 additions & 10 deletions docassemble/PovertyScale/poverty_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_poverty_guidelines():
if results:
return jsonify(results)
else:
return Response("{'error': 'Unable to load poverty guidelines from disk.'}", status=503, mimetype="application/json")
return Response('{"error": "Unable to load poverty guidelines from disk."}', status=503, mimetype="application/json")

@app.route("/poverty_guidelines/household_size/<household_size>", methods=['GET'])
def get_household_poverty_guideline(household_size:int):
Expand All @@ -22,7 +22,7 @@ def get_household_poverty_guideline(household_size:int):
state = None
if (request.args) and request.args.get('multiplier'):
try:
multiplier = float(request.args.get('multiplier'))
multiplier = float(request.args.get('multiplier', 1.0))
except :
multiplier = 1.0
else:
Expand All @@ -36,23 +36,23 @@ def get_household_poverty_guideline(household_size:int):
if results:
return jsonify({'amount': results, 'update_year': update_year})
else:
return Response("{'error': 'Unable to retrieve poverty guidelines.'}", status=503, mimetype="application/json")
return Response('{"error": "Unable to retrieve poverty guidelines."}', status=503, mimetype="application/json")

@app.route("/poverty_guidelines/qualifies/household_size/<household_size>", methods=['GET'])
def get_household_qualifies(household_size:int):
if not request.args or not request.args.get('income'):
return Response("{'error': 'Income is required'}", 400, mimetype="application/json")
if not request.args or not 'income' in request.args:
return Response('{"error": "Income is required"}', 400, mimetype="application/json")
try:
income = int(request.args.get('income'))
income = int(request.args['income'])
except ValueError:
return Response("{'error': 'Invalid income value. Please provide an integer.'}", 400, mimetype="application/json")
return Response('{"error": "Invalid income value. Please provide an integer."}', 400, mimetype="application/json")
if str(request.args.get('state')).lower() in ['ak','hi']:
state = str(request.args.get('state')).lower()
else:
state = None
if request.args.get('multiplier'):
if 'multiplier' in request.args:
try:
multiplier = float(request.args.get('multiplier'))
multiplier = float(request.args['multiplier'])
except :
multiplier = 1.0
else:
Expand All @@ -66,5 +66,5 @@ def get_household_qualifies(household_size:int):
if not results is None:
return jsonify({'qualifies': results, 'update_year': update_year})
else:
return Response("{'error': 'Unable to retrieve poverty guidelines.'}", status=503, mimetype="application/json")
return Response('{"error": "Unable to retrieve poverty guidelines."}', status=503, mimetype="application/json")

3 changes: 3 additions & 0 deletions docassemble/PovertyScale/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docassemble.base>=1.3
docassemble.webapp
mypy
13 changes: 13 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# globals options

[mypy]
exclude = (?x)(
^setup.py$
)

# per-module options:
[mypy-docassemble.webapp.*]
ignore_missing_imports = True

[mypy-docassemble.base.*]
ignore_missing_imports = True