Exemplo n.º 1
0
def prepare_data(data) -> dict:
    """
    All the date already been validate, so now we are preparing the data
    to be inserted on the database
    :param data: dict
    :return: dict
    """
    data["birthdate"] = parse_str_to_date(data["birthdate"])
    data["_id"] = generate_uuid()

    return data
Exemplo n.º 2
0
def test_start_process_error():
    test_db = mongomock.MongoClient()["Test"]
    db = Database(test_db)
    _id = "uuid_1234"
    data = {
        "_id": _id,
        "birthdate": parse_str_to_date("15/08/1992"),
        "amount": 3000,
        "terms": 6,
        "income": 12000,
    }

    insert_status = db.start_process(data)
    assert not insert_status.status
Exemplo n.º 3
0
def test_insert_client(snapshot):
    test_db = mongomock.MongoClient()["Test"]
    db = Database(test_db)
    _id = "uuid-1234"
    data = {
        "_id": _id,
        "name": "Everton Tomalok",
        "cpf": "12345678900",
        "birthdate": parse_str_to_date("15/08/1992"),
        "amount": 3000,
        "terms": 6,
        "income": 12000,
    }

    client = parse_model_and_validate(data, Client)
    db._insert_client(client.data)
    client_inserted = db.find_client(_id)

    snapshot.assert_match(client_inserted)
Exemplo n.º 4
0
def test_start_process(snapshot):
    test_db = mongomock.MongoClient()["Test"]
    db = Database(test_db)
    _id = "uuid_1234"
    data = {
        "_id": _id,
        "name": "Everton Tomalok",
        "cpf": "12345678900",
        "birthdate": parse_str_to_date("15/08/1992"),
        "amount": 3000,
        "terms": 6,
        "income": 12000,
    }

    insert_status = db.start_process(data)
    assert insert_status.status

    client_inserted = db.find_client(_id)
    loan_inserted = db.find_loan(_id)

    snapshot.assert_match(client_inserted)
    snapshot.assert_match(loan_inserted)
Exemplo n.º 5
0
def test_parse_str_to_date(date_str, snapshot):
    snapshot.assert_match(parse_str_to_date(date_str))
Exemplo n.º 6
0
def test_parse_str_to_date_raise_value_error():
    assert not parse_str_to_date("19920815")
Exemplo n.º 7
0
def test_parse_str_to_date_date_obj(snapshot):
    snapshot.assert_match(parse_str_to_date(date(1992, 8, 15)))
Exemplo n.º 8
0
from os import getenv

from api.utils import (
    check_and_return_amount_float,
    check_and_return_term_int,
    is_cpf_valid,
    name_is_valid_field,
    normalize_cpf,
)
from api.utils.dates import parse_str_to_date

# These lambdas bellow will handle/check the fields received from api.
functions = {
    "name": lambda n: n if name_is_valid_field(n) else None,
    "cpf": lambda x: normalize_cpf(x) if is_cpf_valid(x) else None,
    "birthdate": lambda d: parse_str_to_date(d) if parse_str_to_date(d) else None,
    "amount": lambda a: check_and_return_amount_float(a)
    if check_and_return_amount_float(a)
    else None,
    "income": lambda i: check_and_return_amount_float(i)
    if check_and_return_amount_float(i)
    else None,
    "terms": lambda t: check_and_return_term_int(t)
    if check_and_return_term_int(t)
    else None,
}


def parse_loan_form(form):
    """
    Extract from the form the fields that will be send in the processing.