Beispiel #1
0
    def start_process(self, data) -> ProcessStatus:

        client = parse_model_and_validate(data, Client)

        if client.status:
            _id = client.data["_id"]
            loan = parse_model_and_validate({"_id": _id}, Loan)

            self._insert_client(client.data)
            self._insert_loan(loan.data)

            return ProcessStatus(Status.success.value, _id, client.data)
        return ProcessStatus(Status.error.value, None, client.data)
Beispiel #2
0
def test_loan_initialize(snapshot):
    data = {"_id": "uuid-1234"}

    loan = parse_model_and_validate(data, Loan)

    loan_status_ok = loan.status
    loan_data = loan.data

    assert loan_status_ok == 1
    snapshot.assert_match(loan_data)
Beispiel #3
0
def test_loan_error_amount_and_terms(snapshot):
    data = {"_id": "uuid-5678", "terms": 15, "amount": 10000}

    loan = parse_model_and_validate(data, Loan)

    loan_status_not_ok = loan.status
    loan_data = loan.data

    assert loan_status_not_ok == 0
    snapshot.assert_match(loan_data)
Beispiel #4
0
def test_loan_no_uuid(snapshot):
    data = {"terms": 6}

    loan = parse_model_and_validate(data, Loan)

    loan_status_not_ok = loan.status
    loan_data = loan.data

    assert loan_status_not_ok == 0
    snapshot.assert_match(loan_data)
Beispiel #5
0
def test_insert_loan(loan_fixture, snapshot):
    test_db = mongomock.MongoClient()["Test"]
    db = Database(test_db)
    loan = parse_model_and_validate(loan_fixture, Loan)
    snapshot.assert_match(loan.status)
    snapshot.assert_match(loan.data)

    db._insert_loan(loan.data)
    loan_inserted = db.find_loan(loan_fixture["_id"])

    snapshot.assert_match(loan_inserted)
Beispiel #6
0
def test_client_data_error(snapshot):
    data = {
        "name": "Everton Tomalok",
        "birthdate": date(1992, 8, 15),
        "terms": 6,
        "income": 12000,
    }

    client_err = parse_model_and_validate(data, Client)
    client_err = _handle_client_err(client_err)

    client_not_ok = client_err.status
    client_data = client_err.data

    assert client_not_ok == 0
    snapshot.assert_match(client_data)
Beispiel #7
0
def test_parse_and_validate(snapshot):
    data = {
        "name": "Everton Tomalok",
        "cpf": "12345678900",
        "birthdate": date(1992, 8, 15),
        "amount": 4000,
        "terms": 6,
        "income": 12000,
    }

    client_validated = parse_model_and_validate(data, Client)
    del client_validated.data["_id"]

    client_ok = client_validated.status
    client_data = client_validated.data

    assert client_ok == 1
    snapshot.assert_match(client_data)
Beispiel #8
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)