-
Notifications
You must be signed in to change notification settings - Fork 1
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
linting (automatic and manual) + pre-commit #2
base: main
Are you sure you want to change the base?
Changes from 5 commits
c99d67d
a6ff16d
4828684
cfcdefa
e5ca4e2
b2274d4
61fcdeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ | |
*.pyo | ||
*.pyd | ||
README.md | ||
.admin/tokens | ||
.admin/tokens |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[flake8] | ||
ignore = D203 | ||
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist | ||
max-complexity = 10 | ||
max-line-length = 88 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.3.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 19.3b0 | ||
hooks: | ||
- id: black | ||
args: ['--skip-string-normalization'] | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
hooks: | ||
- id: flake8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,4 +114,4 @@ | |
] | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
|
||
from firebase_admin import auth | ||
|
||
|
||
def authenticate(request): | ||
""" Identify the user's Firebase account using an ID token. """ | ||
authorization = request.headers["Authorization"] | ||
"""Identify the user's Firebase account using an ID token.""" | ||
authorization = request.headers['Authorization'] | ||
token = authorization.split(' ')[1] | ||
claims = auth.verify_id_token(token) | ||
uid = claims['uid'] | ||
request.session['uid'] = uid # Save user's custom claims in a session? | ||
return claims | ||
request.session['uid'] = uid # Save user's custom claims in a session? | ||
return claims |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,22 +1,24 @@ | ||||||||||
from rest_framework.decorators import api_view | ||||||||||
from rest_framework.response import Response | ||||||||||
|
||||||||||
BASE = "https://api.cannlytics.com" | ||||||||||
ENDPOINTS = ["labs"] | ||||||||||
VERSION = "v1" | ||||||||||
BASE = 'https://api.cannlytics.com' | ||||||||||
ENDPOINTS = ['labs'] | ||||||||||
VERSION = 'v1' | ||||||||||
|
||||||||||
|
||||||||||
@api_view(['GET']) | ||||||||||
def index(request, format=None): | ||||||||||
"""Informational base endpoint.""" | ||||||||||
message = f"Welcome to the Cannlytics API. The current version is {VERSION} and is located at {BASE}/{VERSION}." | ||||||||||
return Response({ "data": message}, content_type="application/json") | ||||||||||
message = 'Welcome to the Cannlytics API.' | ||||||||||
message += f'The current version is {VERSION} and is located at {BASE}/{VERSION}.' | ||||||||||
return Response({'data': message}, content_type='application/json') | ||||||||||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. preference here? |
||||||||||
|
||||||||||
|
||||||||||
@api_view(['GET']) | ||||||||||
def base(request, format=None): | ||||||||||
"""Informational version endpoint.""" | ||||||||||
message = f"Welcome to {VERSION} of the Cannlytics API. Available endpoints:\n\n" | ||||||||||
message = f'Welcome to {VERSION} of the Cannlytics API.' | ||||||||||
message += 'Available endpoints:\n\n' | ||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
for endpoint in ENDPOINTS: | ||||||||||
message += f"{endpoint}\n" | ||||||||||
return Response({ "data": message}, content_type="application/json") | ||||||||||
message += f'{endpoint}\n' | ||||||||||
return Response({'data': message}, content_type='application/json') | ||||||||||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,23 +1,26 @@ | ||||||
from rest_framework import status | ||||||
# from rest_framework import status | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
from rest_framework.decorators import api_view | ||||||
from rest_framework.response import Response | ||||||
|
||||||
from utils.firebase import get_collection, get_document, update_document | ||||||
# from utils.firebase import get_collection, get_document, update_document | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
from utils.firebase import get_collection | ||||||
|
||||||
|
||||||
@api_view(['GET', 'POST']) | ||||||
def lab_results(request, format=None): | ||||||
"""Get lab results data.""" | ||||||
|
||||||
if request.method == 'GET': | ||||||
limit = request.query_params.get("limit", 1000) | ||||||
limit = request.query_params.get('limit', 1000) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if limit: | ||||||
limit = int(limit) | ||||||
order_by = request.query_params.get("order_by", "") | ||||||
order_by = request.query_params.get('order_by', '') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# TODO: Get any filters from dict(request.query_params) | ||||||
docs = get_collection('tests/leaf/lab_results', order_by=order_by, limit=limit, filters=[]) | ||||||
return Response(docs, content_type="application/json") | ||||||
|
||||||
docs = get_collection( | ||||||
'tests/leaf/lab_results', order_by=order_by, limit=limit, filters=[] | ||||||
) | ||||||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I recall another |
||||||
return Response(docs, content_type='application/json') | ||||||
|
||||||
if request.method == 'POST': | ||||||
print('TODO: Create lab results') | ||||||
return NotImplementedError | ||||||
|
@@ -28,12 +31,13 @@ def mmes(request, format=None): | |||||
"""Get licensee (MME) data.""" | ||||||
|
||||||
if request.method == 'GET': | ||||||
limit = request.query_params.get("limit", None) | ||||||
limit = request.query_params.get('limit', None) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if limit: | ||||||
limit = int(limit) | ||||||
order_by = request.query_params.get("order_by", "") | ||||||
order_by = request.query_params.get('order_by', '') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# TODO: Get any filters from dict(request.query_params) | ||||||
# e.g. {"key": "name", "operation": "==", "value": "xyz"} | ||||||
docs = get_collection('tests/leaf/mmes', order_by=order_by, limit=limit, filters=[]) | ||||||
return Response(docs, content_type="application/json") | ||||||
|
||||||
# e.g. {'key': 'name', 'operation': '==', 'value': 'xyz'} | ||||||
docs = get_collection( | ||||||
'tests/leaf/mmes', order_by=order_by, limit=limit, filters=[] | ||||||
) | ||||||
return Response(docs, content_type='application/json') |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,11 @@ | ||||||||
|
||||||||
from datetime import datetime | ||||||||
from rest_framework import status | ||||||||
|
||||||||
# from rest_framework import status | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
from rest_framework.decorators import api_view | ||||||||
from rest_framework.response import Response | ||||||||
from .auth import authenticate | ||||||||
from utils.firebase import get_document, update_document | ||||||||
|
||||||||
# from .auth import authenticate | ||||||||
# from utils.firebase import get_document, update_document | ||||||||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
|
||||||||
@api_view(['GET', 'POST']) | ||||||||
|
@@ -13,30 +14,31 @@ def users(request, format=None): | |||||||
# try: | ||||||||
# claims = authenticate(request) | ||||||||
# except: | ||||||||
# return Response({"error": "Could not authenticate."}, status=status.HTTP_400_BAD_REQUEST) | ||||||||
# return Response({'error': 'Could not authenticate.'}, | ||||||||
# status=status.HTTP_400_BAD_REQUEST) | ||||||||
|
||||||||
# Get user(s). | ||||||||
if request.method == 'GET': | ||||||||
print("Getting user...") | ||||||||
# limit = request.query_params.get("limit", None) | ||||||||
# order_by = request.query_params.get("order_by", "state") | ||||||||
print('Getting user...') | ||||||||
# limit = request.query_params.get('limit', None) | ||||||||
# order_by = request.query_params.get('order_by', 'state') | ||||||||
# # TODO: Get any filters from dict(request.query_params) | ||||||||
# labs = get_collection('labs', order_by=order_by, limit=limit, filters=[]) | ||||||||
user = {} | ||||||||
return Response({ "data": user}, content_type="application/json") | ||||||||
return Response({'data': user}, content_type='application/json') | ||||||||
|
||||||||
# Update or create user(s). | ||||||||
elif request.method == 'POST': | ||||||||
# TODO: Check if user already exists. | ||||||||
# get_document | ||||||||
print("Creating a user...") | ||||||||
print('Creating a user...') | ||||||||
timestamp = datetime.now().isoformat() | ||||||||
email = request.query_params.get("email", "") | ||||||||
email = request.query_params.get('email', '') | ||||||||
user = { | ||||||||
"email": email, | ||||||||
"created_at": timestamp, | ||||||||
# "uid": user.uid, | ||||||||
"photo_url": f"https://robohash.org/${email}?set=set5", | ||||||||
'email': email, | ||||||||
'created_at': timestamp, | ||||||||
# 'uid': user.uid, | ||||||||
'photo_url': f'https://robohash.org/${email}?set=set5', | ||||||||
} | ||||||||
print(user) | ||||||||
return Response({ "success": True}, content_type="application/json") | ||||||||
return Response({'success': True}, content_type='application/json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keeganskeate preference?