Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari committed Sep 22, 2024
1 parent 4261fa5 commit ab99a1b
Show file tree
Hide file tree
Showing 51 changed files with 195 additions and 255 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ reset_db:
ruff-all:
ruff check .

ruff-fix-all:
ruff check --fix .

ruff:
ruff check --fix $(shell git diff --name-only --staged | grep -E '\.py$$|\/pyproject.toml$$')

Expand Down
8 changes: 4 additions & 4 deletions care/abdm/api/viewsets/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def post(self, request, *args, **kwargs):
map(
lambda consultation: {
"id": str(consultation.external_id),
"name": f"Encounter: {str(consultation.created_date.date())}",
"name": f"Encounter: {consultation.created_date.date()!s}",
},
PatientConsultation.objects.filter(patient=patient),
)
Expand Down Expand Up @@ -213,7 +213,7 @@ def post(self, request, *args, **kwargs):
map(
lambda consultation: {
"id": str(consultation.external_id),
"name": f"Encounter: {str(consultation.created_date.date())}",
"name": f"Encounter: {consultation.created_date.date()!s}",
},
PatientConsultation.objects.filter(patient=patient),
)
Expand Down Expand Up @@ -251,7 +251,7 @@ def post(self, request, *args, **kwargs):

consent_id = data["hiRequest"]["consent"]["id"]
consent = json.loads(cache.get(consent_id)) if consent_id in cache else None
if not consent or not consent["notification"]["status"] == "GRANTED":
if not consent or consent["notification"]["status"] != "GRANTED":
return Response({}, status=status.HTTP_401_UNAUTHORIZED)

# TODO: check if from and to are in range and consent expiry is greater than today
Expand All @@ -269,7 +269,7 @@ def post(self, request, *args, **kwargs):
{"request_id": data["requestId"], "transaction_id": data["transactionId"]}
)

if not on_data_request_response.status_code == 202:
if on_data_request_response.status_code != 202:
return Response({}, status=status.HTTP_202_ACCEPTED)
return Response(
on_data_request_response, status=status.HTTP_400_BAD_REQUEST
Expand Down
4 changes: 2 additions & 2 deletions care/abdm/api/viewsets/hip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import datetime, timezone
from datetime import UTC, datetime

from rest_framework import status
from rest_framework.decorators import action
Expand Down Expand Up @@ -118,7 +118,7 @@ def share(self, request, *args, **kwargs):
payload = {
"requestId": str(uuid.uuid4()),
"timestamp": str(
datetime.now(tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
datetime.now(tz=UTC).strftime("%Y-%m-%dT%H:%M:%S.000Z")
),
"acknowledgement": {
"status": "SUCCESS",
Expand Down
4 changes: 2 additions & 2 deletions care/abdm/api/viewsets/monitoring.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from rest_framework import status
from rest_framework.generics import GenericAPIView
Expand All @@ -14,7 +14,7 @@ def get(self, request, *args, **kwargs):
return Response(
{
"timestamp": str(
datetime.now(tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
datetime.now(tz=UTC).strftime("%Y-%m-%dT%H:%M:%S.000Z")
),
"status": "UP",
"error": None,
Expand Down
26 changes: 13 additions & 13 deletions care/abdm/service/gateway.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import datetime, timezone
from datetime import UTC, datetime

from django.conf import settings
from django.db.models import Q
Expand All @@ -18,7 +18,7 @@ def __init__(self):
def consent_requests__init(self, consent: ConsentRequest):
data = {
"requestId": str(consent.external_id),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"consent": {
Expand All @@ -42,14 +42,14 @@ def consent_requests__init(self, consent: ConsentRequest):
"permission": {
"accessMode": consent.access_mode,
"dateRange": {
"from": consent.from_time.astimezone(timezone.utc).strftime(
"from": consent.from_time.astimezone(UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"to": consent.to_time.astimezone(timezone.utc).strftime(
"to": consent.to_time.astimezone(UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
},
"dataEraseAt": consent.expiry.astimezone(timezone.utc).strftime(
"dataEraseAt": consent.expiry.astimezone(UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"frequency": {
Expand All @@ -67,7 +67,7 @@ def consent_requests__init(self, consent: ConsentRequest):
def consent_requests__status(self, consent_request_id: str):
data = {
"requestId": str(uuid.uuid4()),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"consentRequestId": consent_request_id,
Expand All @@ -80,7 +80,7 @@ def consent_requests__status(self, consent_request_id: str):
def consents__hiu__on_notify(self, consent: ConsentRequest, request_id: str):
data = {
"requestId": str(uuid.uuid4()),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"resp": {"requestId": request_id},
Expand All @@ -104,7 +104,7 @@ def consents__hiu__on_notify(self, consent: ConsentRequest, request_id: str):
def consents__fetch(self, consent_artefact_id: str):
data = {
"requestId": str(uuid.uuid4()),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"consentId": consent_artefact_id,
Expand All @@ -121,7 +121,7 @@ def health_information__cm__request(self, artefact: ConsentArtefact):

data = {
"requestId": request_id,
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"hiRequest": {
Expand All @@ -132,7 +132,7 @@ def health_information__cm__request(self, artefact: ConsentArtefact):
"cryptoAlg": artefact.key_material_algorithm,
"curve": artefact.key_material_curve,
"dhPublicKey": {
"expiry": artefact.expiry.astimezone(timezone.utc).strftime(
"expiry": artefact.expiry.astimezone(UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"parameters": f"{artefact.key_material_curve}/{artefact.key_material_algorithm}",
Expand Down Expand Up @@ -169,13 +169,13 @@ def get_hf_id_by_health_id(self, health_id):
def health_information__notify(self, artefact: ConsentArtefact):
data = {
"requestId": str(uuid.uuid4()),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"notification": {
"consentId": str(artefact.artefact_id),
"transactionId": str(artefact.transaction_id),
"doneAt": datetime.now(tz=timezone.utc).strftime(
"doneAt": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"notifier": {
Expand All @@ -198,7 +198,7 @@ def health_information__notify(self, artefact: ConsentArtefact):
def patients__find(self, abha_number: AbhaNumber):
data = {
"requestId": str(uuid.uuid4()),
"timestamp": datetime.now(tz=timezone.utc).strftime(
"timestamp": datetime.now(tz=UTC).strftime(
"%Y-%m-%dT%H:%M:%S.000Z"
),
"query": {
Expand Down
Loading

0 comments on commit ab99a1b

Please sign in to comment.