Skip to content

Commit

Permalink
feat: add dummy function as basis for further AHJO features
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke committed Oct 5, 2023
1 parent 3f3c91e commit ae01290
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
import logging
import os
import zipfile
Expand All @@ -9,12 +10,16 @@
import jinja2
import pdfkit
from django.db.models import QuerySet
from django.conf import settings


from applications.enums import ApplicationStatus
from applications.models import Application
from applications.models import Application, AhjoSetting
from applications.services.applications_csv_report import ApplicationsCsvService
from companies.models import Company

from applications.services.ahjo_authentication import AhjoConnector


@dataclass
class ExportFileInfo:
Expand Down Expand Up @@ -350,3 +355,42 @@ def export_application_batch(batch) -> bytes:

pdf_files: List[ExportFileInfo] = prepare_pdf_files(apps)
return generate_zip(pdf_files)


def dummy_ahjo_request():
"""Dummy function for preliminary testing of Ahjo integration"""
ahjo_api_url = settings.AHJO_REST_API_URL
try:
ahjo_auth_code = AhjoSetting.objects.get(name="ahjo_code").data
LOGGER.info(f"Retrieved auth code: {ahjo_auth_code}")
except Exception as e:
LOGGER.error(f"Error retrieving auth code: {e}")
return

connector = AhjoConnector(requests)

if not connector.is_configured():
LOGGER.warning("AHJO connector is not configured")
return
try:
ahjo_token = connector.get_access_token(ahjo_auth_code["code"])
except Exception as e:
LOGGER.warning(f"Error retrieving access token: {e}")
return
headers = {
'Authorization': f'Bearer {ahjo_token.access_token}',
}
print(headers)
try:
response = requests.get(f"{ahjo_api_url}/cases", headers=headers, timeout=connector.timout)
response.raise_for_status()
print(response.json())
except requests.exceptions.HTTPError as e:
# Handle the HTTP error
LOGGER.error(f"HTTP error occurred: {e}")
except requests.exceptions.RequestException as e:
# Handle the network error
LOGGER.errror(f"Network error occurred: {e}")
except Exception as e:
# Handle any other error
LOGGER.error(f"Error occurred: {e}")

0 comments on commit ae01290

Please sign in to comment.