Initial commit
This commit is contained in:
+173
@@ -0,0 +1,173 @@
|
||||
import requests
|
||||
import base64
|
||||
import json
|
||||
|
||||
# Configuration
|
||||
BASE_URL = "http://127.0.0.1:8080/v1/api/salary"
|
||||
USERNAME = "admin"
|
||||
PASSWORD = "password"
|
||||
APP_ID = "your_app_id" # Replace with your actual app ID
|
||||
API_KEY = "your_api_key" # Replace with your actual API key
|
||||
|
||||
# Authentication headers
|
||||
basic_auth = base64.b64encode(f"{USERNAME}:{PASSWORD}".encode()).decode()
|
||||
basic_auth_headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Basic {basic_auth}"
|
||||
}
|
||||
|
||||
api_key_headers = {
|
||||
"Content-Type": "application/json",
|
||||
"appID": APP_ID,
|
||||
"apiKey": API_KEY
|
||||
}
|
||||
|
||||
|
||||
def test_eligibility_check():
|
||||
"""Test the EligibilityCheck endpoint."""
|
||||
url = f"{BASE_URL}/EligibilityCheck"
|
||||
payload = {
|
||||
"$type": "EligibilityCheckRequest",
|
||||
"transactionId": "Tr202503RK9232P115",
|
||||
"countryCode": "NGR",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "ACN8263457",
|
||||
"msisdn": "2348012345678",
|
||||
"lienAmount": 4.0,
|
||||
"channel": "USSD"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=basic_auth_headers, json=payload)
|
||||
print(f"EligibilityCheck Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_select_offer():
|
||||
"""Test the SelectOffer endpoint."""
|
||||
url = f"{BASE_URL}/SelectOffer"
|
||||
payload = {
|
||||
"requestId": "202503170001371256908",
|
||||
"transactionId": "1231231321232",
|
||||
"customerId": "1256907",
|
||||
"accountId": "5948306019",
|
||||
"msisdn": "2348012345678",
|
||||
"requestedAmount": 10000.0,
|
||||
"productid": "101",
|
||||
"channel": "USSD"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=basic_auth_headers, json=payload)
|
||||
print(f"SelectOffer Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_provide_loan():
|
||||
"""Test the ProvideLoan endpoint."""
|
||||
url = f"{BASE_URL}/ProvideLoan"
|
||||
payload = {
|
||||
"$type": "ProvideLoanRequest",
|
||||
"requestId": "202503170001371256908",
|
||||
"transactionId": "Tr202503RK9232P115",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "ACN8263457",
|
||||
"msisdn": "2348012345678",
|
||||
"productId": "101",
|
||||
"lienAmount": 400.0,
|
||||
"requestedAmount": 10000.0,
|
||||
"collectionType": 1,
|
||||
"loanType": 0,
|
||||
"channel": "USSD"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=basic_auth_headers, json=payload)
|
||||
print(f"ProvideLoan Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_loan_information():
|
||||
"""Test the LoanInformation endpoint."""
|
||||
url = f"{BASE_URL}/LoanInformation"
|
||||
payload = {
|
||||
"$type": "LoanInformationRequest",
|
||||
"transactionId": "Tr202503RK9232P115",
|
||||
"customerId": "CN621868",
|
||||
"msisdn": "2348012345678",
|
||||
"channel": "USSD"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=basic_auth_headers, json=payload)
|
||||
print(f"LoanInformation Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_rac_check():
|
||||
"""Test the RACCheck endpoint."""
|
||||
url = f"{BASE_URL}/RACCheck"
|
||||
payload = {
|
||||
"transactionId": "T001",
|
||||
"fbnTransactionId": "Tr202503RK9232P115",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "2017821799",
|
||||
"RAC_Array": ["SalaryAccount", "BVN", "CRMS", "CRC", "AccountStatus", "Lien", "NoBounchedCheck", "Whitelist"]
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=api_key_headers, json=payload)
|
||||
print(f"RACCheck Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_disbursement():
|
||||
"""Test the Disbursement endpoint."""
|
||||
url = f"{BASE_URL}/Disbursement"
|
||||
payload = {
|
||||
"requestId": "202503170001371256908",
|
||||
"debtId": "273194670",
|
||||
"transactionId": "T001",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "2017821799",
|
||||
"productId": "101",
|
||||
"provideAmount": 100000.0,
|
||||
"collectAmountInterest": 5000.0,
|
||||
"collectAmountMgtFee": 1000.0,
|
||||
"collectAmountInsurance": 1000.0,
|
||||
"collectAmountVAT": 75.0,
|
||||
"countryId": "01",
|
||||
"comment": "Testing LoanRequest"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=api_key_headers, json=payload)
|
||||
print(f"Disbursement Status: {response.status_code}")
|
||||
print(json.dumps(response.json(), indent=2))
|
||||
print("-" * 50)
|
||||
return response.json()
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
"""Run all test functions."""
|
||||
print("Starting API tests...\n")
|
||||
|
||||
# Test endpoints with basic auth
|
||||
test_eligibility_check()
|
||||
test_select_offer()
|
||||
test_provide_loan()
|
||||
test_loan_information()
|
||||
|
||||
# Test endpoints with API key auth
|
||||
test_rac_check()
|
||||
test_disbursement()
|
||||
|
||||
print("All tests completed!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_all_tests()
|
||||
Reference in New Issue
Block a user