class TestBankOperationsSuite(unittest.TestCase): '''Test suite for bank operations''' application1 = ApplicationInfo('Username', 'nile', 'barn', '34', 'Gender', '456789345', 'Title', 'Employer', '123333', '1233', '1 Dravus', 'Seattle', 'WA', '98109', '1 Dravus', 'Seattle', 'WA', '98109') loan = Loan('Personal') def test_cal_risk_score(self): '''Test the calc_risk_score function''' _log.info('Testing cal_risk_score') self.assertEqual( 1.95, ops.cal_risk_score(TestBankOperationsSuite.application1)) application = ApplicationInfo('zz', 'First Name', 'Last Name', '34', 'Gender', '456789345', 'Title', 'Employer', '123333', '1233', '1 Dravus', 'Seattle', 'WA', '98109', '1 Dravus', 'Seattle', 'WA', '98109') self.assertEqual(1.45, ops.cal_risk_score(application)) def test_credit_score(self): '''Test the calc_credit_score function''' _log.info('Testing credit_score') self.assertEqual( 320, ops.credit_score(TestBankOperationsSuite.application1)) application = ApplicationInfo('aa', 'First Name', 'Last Name', '34', 'Gender', '456789345', 'Title', 'Employer', '123333', '1233', '1 Dravus', 'Seattle', 'WA', '98109', '1 Dravus', 'Seattle', 'WA', '98109') self.assertEqual(600, ops.credit_score(application))
def test_to_dict(self): '''Test to_dict in loan''' _log.info('Testing to_dict') self.loan = Loan('Mortgage') self.assertIs(type(LoanTestSuite.loan.to_dict()), dict)
def test_from_dict(self): '''Test from_dict in loan''' _log.info('Testing from_dict') test_dict = {'loan_type': 'Personal'} self.loan = Loan().from_dict(test_dict) self.assertIs(type(LoanTestSuite.loan), Loan)
def test_str(self): '''Test __str__ in loan''' _log.info('Testing __st__ in loan') self.loan = Loan('Car') self.assertIs(type(str(LoanTestSuite.loan)), str)
def setUpClass(cls): cls.loan = Loan()
def setUp(self): self.loan = Loan('Mortgage') self.loan = Loan('Car') self.loan = Loan('Student') self.loan = Loan('Personal')
def approval(loan: Loan, applicationInfo: ApplicationInfo): _log.debug(loan) _log.info("In approval function") if loan.loan_type == 'Student': if loan.cosigner_needed != 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Approved' elif loan.cosigner_needed == 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Co-signer Needed' else: loan.status = 'Co-signer Needed' elif loan.loan_type == 'Mortgage': if loan.collateral_needed != 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Approved' elif loan.collateral_needed == 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Collateral Needed' else: loan.status = 'Loan Manager Approval Needed' elif loan.loan_type == 'Car': if loan.collateral_needed != 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Approved' elif loan.collateral_needed == 'Required' and loan.risk_score <= RISK_THRESHOLD: loan.status = 'Collateral Needed' else: loan.status = 'Denied' else: if loan.risk_score >= RISK_THRESHOLD and loan.collateral_needed == 'Risk Score': loan.collateral_needed = 'Required' loan.status = 'Collateral Needed' else: loan.status = 'Loan Manager Approval Needed'
def post_operations(self, path: list, r_body): '''POST operation for loan''' _log.debug('POST request received') _log.debug("len(path) = %s", len(path)) if len(path) == 1: r_body_temp = json.loads(r_body.decode('utf-8')) _log.info("In loan handler. %s", r_body_temp) application = ApplicationInfo.from_dict(r_body_temp) loan = Loan(r_body_temp['loan_type']) value = r_body_temp['loan_type'] if value == 'Car': loan.set_collateral_needed('Automobile') elif value == 'Personal': loan.set_collateral_needed('Real estate') elif value == 'Mortgage': loan.set_collateral_needed('House') risk = cal_risk_score(application) loan.set_risk_score(risk) credit = credit_score(application) loan.set_credit_score(credit) approval(loan, application) db.add_loan_application_to_user(r_body_temp['username'], application, loan) return (201, bytes(json.dumps(application, cls=ItemEncoder), 'utf-8')) if len(path) == 2: _log.info("in len equal 2 post") _log.debug(path) r_body_temp = json.loads(r_body.decode('utf-8')) loan = { 'loan_type': r_body_temp['loan_type'], 'risk_score': r_body_temp['risk_score'], 'credit_score': r_body_temp['credit_score'] } if r_body_temp['status'] == 'Approved': db.approve_loan(loan) elif r_body_temp['status'] == 'Denied': db.deny_loan(loan) return (200, bytes(json.dumps(loan, cls=ItemEncoder), 'utf-8')) return (401, b'Unauthorized')