MIRA_LABS_AI / demo-backend /loan-service /tests /test_dashboard_router.py
ans123's picture
Initial upload from Colab
ef1ad9e verified
from .test_payloads.payload_application_router import *
# fetch consumer dashboard details
def test_get_dashboard_info(test_client, consumer_header, application_id):
url = f"/dashboard/loan_info/{application_id}"
response = test_client.get(url, headers=consumer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Applications not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Dashboard Info fetched successfully!"
# fetch loan officer dashboard details
def test_get_dashboard_info_loan_officer(test_client, loan_officer_header):
url = "/dashboard/dashboard_info"
response = test_client.get(url, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Dashboard Info fetched successfully!"
# fetching lead information for loan officer
def test_get_lead_info_loan_officer(test_client, loan_officer_header):
payload = {"loanOfficerIds": []}
url = "/dashboard/lead_info?page=1&page_size=10&pipeline_mode=false"
response = test_client.post(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "No users found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Lead Info fetched successfully!"
# fetching pipeline information for loan officer
def test_get_pipeline_info_loan_officer(test_client, loan_officer_header):
payload = {"loanOfficerIds": []}
url = "/dashboard/lead_info?page=1&page_size=10&pipeline_mode=true"
response = test_client.post(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "No users found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Lead Info fetched successfully!"
# create new user profile
def test_add_personal_details_loan_officer(test_client, loan_officer_header):
payload = add_profile_payload
url = "/dashboard/personal_details"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "Personal details updated successfully!":
assert response["message"] == "Personal details updated successfully!"
elif response["message"] == "Personal Details saved successfully!":
assert response["message"] == "Personal Details saved successfully!"
# updated user profile details
def test_update_personal_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_profile_payload
url = f"/dashboard/personal_details/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Personal details updated successfully!"
# add loan details to the application
def test_add_loan_details_loan_officer(test_client, loan_officer_header):
payload = add_loan_details_payload
url = "/dashboard/loan"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "Loan updated successfully!":
assert response["message"] == "Loan updated successfully!"
elif response["message"] == "Loan Details saved successfully!":
assert response["message"] == "Loan Details saved successfully!"
# update existing loan details
def test_update_loan_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_loan_details_payload
url = f"/dashboard/loan/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Loan details updated successfully!"
# add employment and income details
def test_add_employment_and_income_details_loan_officer(test_client, loan_officer_header):
payload = add_employment_and_income_payload
url = "/dashboard/employment_and_income"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "Employment And Income Details updated successfully!":
assert response["message"] == "Employment And Income Details updated successfully!"
elif response["message"] == "Employment And Income Details saved successfully!":
assert response["message"] == "Employment And Income Details saved successfully!"
# update employment and income details
def test_update_employment_and_income_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_employment_and_income_payload
url = f"/dashboard/employment_and_income/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Employment and Income details updated successfully!"
# add assets details
def test_add_assets_details_loan_officer(test_client, loan_officer_header):
payload = add_assets_payload
url = "/dashboard/assets"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "User Asset Details updated successfully!":
assert response["message"] == "User Asset Details updated successfully!"
elif response["message"] == "Asset Details saved successfully!":
assert response["message"] == "Asset Details saved successfully!"
# update assets details
def test_update_assets_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_assests_payload
url = f"/dashboard/assets/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Asset details updated successfully!"
# add liability details
def test_add_liability_details_loan_officer(test_client, loan_officer_header):
payload = add_liability_payload
url = "/dashboard/liabilities"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "User Libalities Details updated successfully!":
assert response["message"] == "User Libalities Details updated successfully!"
elif response["message"] == "Libality Details saved successfully!":
assert response["message"] == "Libality Details saved successfully!"
# update liability details
def test_update_liability_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_liability_payload
url = f"/dashboard/liabilities/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Libality details updated successfully!"
# add REOs details
def test_add_reos_details_loan_officer(test_client, loan_officer_header):
payload = add_reo_payload
url = "/dashboard/reos"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
if response["message"] == "User REOs updated successfully!":
assert response["message"] == "User REOs updated successfully!"
elif response["message"] == "User REOs Details saved successfully!":
assert response["message"] == "User REOs Details saved successfully!"
# update REOs details
def test_update_reo_details_loan_officer(test_client, loan_officer_header, application_id):
payload = update_reo_payload
url = f"/dashboard/reos/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "User REOs details updated successfully!"
# add declaration details
def test_add_declaration_loan_officer(test_client, loan_officer_header):
payload = add_declaration_payload
url = "/dashboard/declaration"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "User declarations Details saved successfully!"
# update declaration details
def test_update_declaration_loan_officer(test_client, loan_officer_header, application_id):
payload = update_declaration_payload
url = f"/dashboard/declaration/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "User Declaration details updated successfully!"
# add demographics details
def test_add_demographics_loan_officer(test_client, loan_officer_header):
payload = add_demographics_payload
url = "/dashboard/demographics"
response = test_client.post(url, json=payload, headers=loan_officer_header)
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "User demographics Details saved successfully!"
# update demographics details
def test_update_demographics_loan_officer(test_client, loan_officer_header, application_id):
payload = update_demographics_payload
url = f"/dashboard/demographics/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "User Demographic details updated successfully!"
# update application status
def test_update_application_status_loan_officer(test_client, loan_officer_header, application_id):
payload = update_application_status_payload
url = f"/dashboard/status/{application_id}"
response = test_client.put(url, json=payload, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Application not found"
elif response.status_code == 409:
assert response.status_code == 409
response = response.json()
assert response["status"] == 409
assert response["message"] == "Unable to update application status"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Application status updated successfully!"
# fetch borrower's profile
def test_fetch_borrower_profile(test_client, loan_officer_header, application_id):
url = f"/dashboard/borrower_profile/{application_id}"
response = test_client.get(url, headers=loan_officer_header)
if response.status_code == 404:
assert response.status_code == 404
response = response.json()
assert response["status"] == 404
assert response["message"] == "Applications not found"
else:
assert response.status_code == 200
response = response.json()
assert response["status"] == 200
assert response["message"] == "Borrower Profile Info fetched successfully!"