def setUp(self):
     self.application = ApplicationInfo('Uname', 'First Name', ' Last Name',
                                        '34', 'Gender', '456789345',
                                        'Title', 'Employer', '123333',
                                        '1233', '1 Dravus', 'Seattle', 'WA',
                                        '98109', '1 Dravus', 'Seattle',
                                        'WA', '98109')
Beispiel #2
0
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):
     '''Testing to_dict for application info'''
     self.application = ApplicationInfo('Uname', 'First Name', 'Last Name',
                                        '34', 'Gender', '456789345',
                                        'Title', 'Employer', '123333', 1233,
                                        '1 Dravus', 'Seattle', 'WA',
                                        '98109', '1 Dravus', 'Seattle',
                                        'WA', '98109')
     self.assertIs(type(ApplicationInfoTestSuite.application.to_dict()),
                   dict)
Beispiel #4
0
 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))
Beispiel #5
0
    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')
    def test_from_dict(self):
        '''Test from_dict for application info'''
        test_dict = {
            'username': '******',
            'age': '34',
            'gender': 'fluid',
            'ssn': '456789345',
            'title': 'awesome',
            'employer': 'the man',
            'salary': '123333',
            'expenses': 1233,
            'b_street': '1 Dravus',
            'b_city': 'Seattle',
            'b_state': 'WA',
            'b_zip': '98109',
            'm_street': '1 Dravus',
            'm_city': 'Seattle',
            'm_state': 'WA',
            'm_zip': '98109'
        }

        self.application = ApplicationInfo().from_dict(test_dict)
        self.assertIs(type(ApplicationInfoTestSuite.application),
                      ApplicationInfo)
 def test_str(self):
     '''Tests __str__ in applicationinfo'''
     _log.info('Testing test_str')
     self.application = ApplicationInfo('username')
     self.assertIs(type(str(ApplicationInfoTestSuite.application)), str)
 def setUpClass(cls):
     cls.application = ApplicationInfo()