Esempio n. 1
0
def test_should_pass_policy_with_other_terms():
    fake_adapter = FakeExternalApiAdapter(900, Decimal(0.66))
    loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), Decimal(2500), 6,
                Decimal(1000))
    loan.person_score = 900
    CommitmentPolicy(fake_adapter).apply(loan)
    assert loan.terms == 9
Esempio n. 2
0
def test_should_approve_loan():
    loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), 1000, 6, 1000)
    policies_to_apply = [FakePolicy(True)]
    port = LoanPort(FakeLoanAdapter())
    ComputeLoanUseCase(port, policies_to_apply).execute(loan)
    assert loan.status == 'completed'
    assert loan.result == 'approved'
Esempio n. 3
0
def test_should_throw_policy_exception():
    with pytest.raises(PolicyException, match='Política negada: commitment'):
        fake_adapter = FakeExternalApiAdapter(900, Decimal(0.9))
        loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), Decimal(2500),
                    6, Decimal(1000))
        loan.person_score = 900
        CommitmentPolicy(fake_adapter).apply(loan)
Esempio n. 4
0
def test_shouldnt_approve_loan():
    loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), 1000, 6, 1000)
    policies_to_apply = [FakePolicy(False)]
    port = LoanPort(FakeLoanAdapter())
    ComputeLoanUseCase(port, policies_to_apply).execute(loan)
    assert loan.refused_policy == 'fake_policy'
    assert loan.result == 'refused'
    assert loan.status == 'completed'
    assert loan.terms is None
    assert loan.amount is None
Esempio n. 5
0
def test_should_not_construct_loan():
    with pytest.raises(ValidationException,
                       match='Erros: Nome inválido, CPF inválido, ' +
                       'Data de nascimento inválida, Valor ' +
                       'inválido, Quantidade de parcelas inválidas'):
        name = ''
        cpf = ''
        birthdate = ''
        amount = 999
        terms = 5
        income = 1000
        Loan(name, cpf, birthdate, amount, terms, income)
Esempio n. 6
0
def compute(event, context):
    for record in event.get('Records'):
        if record.get('eventName') == 'INSERT':
            print(record)
            id = uuid.UUID(record['dynamodb']['Keys']['id']['S'])
            name = record['dynamodb']['NewImage']['name']['S']
            cpf = record['dynamodb']['NewImage']['cpf']['S']
            birthdate = dateutil.parser.isoparse(
                record['dynamodb']['NewImage']['birthdate']['S'])
            amount = Decimal(record['dynamodb']['NewImage']['amount']['N'])
            terms = int(record['dynamodb']['NewImage']['terms']['N'])
            income = Decimal(record['dynamodb']['NewImage']['income']['N'])
            loan = Loan(name, cpf, birthdate, amount, terms, income, id=id)
            compute_loan_use_case_instace.execute(loan)
Esempio n. 7
0
def create_loan(event, context):
    try:
        data = json.loads(event['body'])
        birthdate = datetime.datetime.strptime(
            data.get('birthdate'), '%Y-%m-%d') if 'birthdate' in data else None
        loan = Loan(data.get('name', ''), data.get('cpf', ''), birthdate,
                    data.get('amount', 0), data.get('terms', 0),
                    data.get('income', ''))
        create_loan_use_case_instace.execute(loan)
        body = {'id': loan.id}
        return {'statusCode': 200, 'body': json.dumps(body)}
    except ValidationException as ex:
        body = {'errors': ex.errors}
        return {'statusCode': 400, 'body': json.dumps(body)}
    except Exception as e:
        body = {'errorMessage': getattr(e, 'message', str(e))}
        return {'statusCode': 500, 'body': json.dumps(body)}
Esempio n. 8
0
def test_should_construct_loan():
    name = 'teste'
    cpf = '123123'
    birthdate = date.today()
    amount = 1000
    terms = 6
    income = 1000
    loan = Loan(name, cpf, birthdate, amount, terms, income)
    assert name == loan.name
    assert cpf == loan.cpf
    assert birthdate == loan.birthdate
    assert amount == loan.amount
    assert terms == loan.terms
    assert income == loan.income
    assert 'processing' == loan.status
    assert None is loan.refused_policy
    assert None is loan.result
    UUID(hex=loan.id, version=4)
Esempio n. 9
0
 def get_by_id(self, id) -> Loan:
     item = self.dynamo_table.get_item(Key={'id': id})['Item']
     print(item)
     loan = Loan(item['name'], item['cpf'], dateutil.parser.isoparse(item['birthdate']), item['amount'], item['terms'], item['income'], status=item['status'], result=item['result'], refused_policy=item['refused_policy'], id=item['id'])
     print(loan)
     return loan
Esempio n. 10
0
 def get_by_id(self, id) -> Loan:
     return Loan('test', 'cpf', datetime.date.today(), 1000, 6, 1000)
Esempio n. 11
0
def test_shouldnt_throw_policy_exception():
    fake_adapter = FakeExternalApiAdapter(600, 0)
    loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), 1000, 6, 1000)
    ScorePolicy(fake_adapter).apply(loan)
Esempio n. 12
0
def test_should_throw_policy_exception():
    with pytest.raises(PolicyException, match='Política negada: score'):
        fake_adapter = FakeExternalApiAdapter(599, 0)
        loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), 1000, 6, 1000)
        ScorePolicy(fake_adapter).apply(loan)
Esempio n. 13
0
def test_shouldnt_throw_policy_exception():
    loan = Loan('name', 'cpf', datetime.date(2000, 7, 12), 1000, 6, 1000)
    AgePolicy().apply(loan)
Esempio n. 14
0
def test_should_throw_policy_exception():
    with pytest.raises(PolicyException, match='Política negada: age'):
        loan = Loan('name', 'cpf', datetime.date.today(), 1000, 6, 1000)
        AgePolicy().apply(loan)