Exemplo n.º 1
0
    def test_is_user_already_exist(self):

        datas = [
            {
                "username": "******",
                "password": "******",
                "phonenumber": "094653438",
                "address": "Malang"
            },
            {
                "username": "******",
                "password": "******",
                "phonenumber": "097563782",
                "address": "Jakarta"
            }
        ]

        # insert data
        for data in datas:
            user = UserModel(data['username'], data['password'], data['phonenumber'], data['address'])
            db.session.add(user)
            db.session.commit()

        username = "******"

        assert UserModel.is_exists(username) == True
Exemplo n.º 2
0
def charlie(session):
    charlie = UserModel(
        name="charlie",
        email="*****@*****.**",
        password_hash="klakdw",
    )
    session.add(charlie)
    session.commit()
    return charlie
Exemplo n.º 3
0
def bob(session):
    bob = UserModel(
        name="bob",
        email="*****@*****.**",
        password_hash="klakdw",
    )
    session.add(bob)
    session.commit()
    return bob
Exemplo n.º 4
0
def alice(session):
    alice = UserModel(
        name="Alice",
        email="*****@*****.**",
        password_hash="ajdief",
    )
    session.add(alice)
    session.commit()
    return alice
def reset_database():

    db.drop_all()
    db.create_all()

    admin = UserModel("admin-tria", bcrypt.generate_password_hash("triapass"),
                      "0986463", "Balikpapan", "admin")

    # create test non-admin user

    # save users to database
    db.session.add(admin)
    db.session.commit()
Exemplo n.º 6
0
def signup():
    session = current_app.db.session

    name = request.json.get("name")
    email = request.json.get("email")
    password = request.json.get("password")

    new_user = UserModel(name=name, email=email)
    new_user.password = password

    session.add(new_user)
    session.commit()

    access_token = create_access_token(
        identity=new_user.id, expires_delta=timedelta(days=7)
    )

    return {
        "user": {
            "id": new_user.id,
            "email": new_user.email,
        }
    }, HTTPStatus.CREATED
Exemplo n.º 7
0
def test_create_expense(
    group: GroupModel,
    alice: UserModel,
    bob: UserModel,
    group_alice_account: AccountModel,
    group_bob_account: AccountModel,
    session,
    category_moradia,
):

    charlie = UserModel(
        name="Charlie",
        email="*****@*****.**",
        password_hash="kklafeasflmrwegko",
    )

    session.add(charlie)
    session.commit()

    group_charlie_account = AccountModel(user_id=charlie.id, group_id=group.id)

    session.add(group_charlie_account)
    session.commit()

    given_splitted = {
        "payers": [{"payer_id": alice.id, "paid_amount": 100}],
        "benefited": [
            {"benefited_id": alice.id, "benefited_amount": 40},
            {"benefited_id": bob.id, "benefited_amount": 30},
            {"benefited_id": charlie.id, "benefited_amount": 30},
        ],
    }

    expected_entry_name = "Conta Luz"
    expected_entry_amount = 100
    expected_entry_group_id = 1
    expected_entry_created_by = alice.id
    expected_entry_created_at = datetime.combine(date.today(), datetime.min.time())

    expected_transactions_debit_target_account_id = [group_alice_account.id]
    expected_transactions_credit_target_account_id = [
        group_alice_account.id,
        group_bob_account.id,
        group_charlie_account.id,
    ]
    expected_transactions_entries_id = [2, 2, 2, 2]

    expected_expense_id = 1
    expected_expense_category_id = category_moradia.id
    expected_expense_description = "Veio mais alta por causa da secadora"
    expected_expense_journal_id = 2

    expense_entry: JournalModel = group.create_expense(
        name="Conta Luz",
        amount=100,
        created_by=alice.id,
        splitted=given_splitted,
        category_id=category_moradia.id,
        description=expected_expense_description,
    )

    actual_entry: JournalModel = JournalModel.query.get(expense_entry.id)

    actual_transactions_credit: list[
        TransactionModel
    ] = TransactionModel.query.filter_by(
        type=TransactionType.credit, entry_id=actual_entry.id
    ).all()

    actual_transactions_credit_target_account_id = [
        transaction.target_account for transaction in actual_transactions_credit
    ]

    actual_transactions_debit: list[
        TransactionModel
    ] = TransactionModel.query.filter_by(
        type=TransactionType.debit, entry_id=actual_entry.id
    ).all()

    actual_transactions_debit_target_account_id = [
        transaction.target_account for transaction in actual_transactions_debit
    ]

    actual_all_transactions = actual_transactions_credit + actual_transactions_debit

    actual_transactions_entries_id = [
        transaction.entry_id for transaction in actual_all_transactions
    ]

    actual_expense = ExpenseModel.query.filter_by(journal_id=actual_entry.id).first()

    assert actual_entry.name == expected_entry_name
    assert actual_entry.amount == expected_entry_amount
    assert actual_entry.group_id == expected_entry_group_id
    assert actual_entry.created_by == expected_entry_created_by
    assert actual_entry.created_at == expected_entry_created_at
    assert actual_transactions_entries_id == expected_transactions_entries_id

    assert actual_expense.id == expected_expense_id
    assert actual_expense.category_id == expected_expense_category_id
    assert actual_expense.description == expected_expense_description
    assert actual_expense.journal_id == expected_expense_journal_id

    assert (
        actual_transactions_credit_target_account_id
        == expected_transactions_credit_target_account_id
    )
    assert (
        actual_transactions_debit_target_account_id
        == expected_transactions_debit_target_account_id
    )