Beispiel #1
0
def seed_db():
    from models.Budget import Budget
    from models.User import User
    from main import bcrypt
    from faker import Faker
    import random

    faker = Faker()
    users = []

    for i in range(5):
        user = User()
        user.username = f"tester{i}"
        user.email = f"test{i}@test.com"
        user.password = bcrypt.generate_password_hash("123456").decode("utf-8")
        db.session.add(user)
        users.append(user)

    db.session.commit()

    for i in range(10):
        budget = Budget()
        budget.name = faker.catch_phrase()
        budget.user_id = random.choice(users).id
        db.session.add(budget)

    db.session.commit()
    print("Tables seeded")
Beispiel #2
0
def filter_by_receipt_date(budget: Budget) -> None:
    transaction_table = PrettyTable()
    transaction_table.field_names = [
        "Name", "Payee Name", "Inflow", "Outflow", "Category", "Receipt Date"
    ]
    transaction_table.align = "l"
    transaction_table.float_format = "1.2"

    date_input = input(
        "Write date for which you would like to check transactions (YYYY-MM-DD): "
    )
    transaction_time = datetime.strptime(date_input, '%Y-%m-%d').date()
    all_transactions = budget.all_transactions()

    for transaction in all_transactions:
        if transaction.receipt_date == transaction_time:
            name = transaction.name
            payee_name = transaction.payee_name
            inflow = transaction.amount_inflow
            outflow = transaction.amount_outflow
            category = transaction.category_id
            receipt_date = transaction.receipt_date
            transaction_table.add_row(
                [name, payee_name, inflow, outflow, category, receipt_date])

    print(transaction_table)
    _ = input("Press ENTER to go back.")
Beispiel #3
0
def add_budget(user: User) -> Budget:
    budget_name = input("Name of the new budget: ")
    budget = Budget(name=budget_name, user_id=user.id)
    session.add(budget)
    session.commit()
    new_budget = session.query(Budget).order_by(Budget.id.desc()).first()
    return new_budget
def budget_create():
    budget_fields = budget_schema.load(request.json)
    user_id = get_jwt_identity()

    user = User.query.get(user_id)

    if not user:
        return abort(401, description="Invalid user")

    new_budget = Budget()
    new_budget.name = budget_fields["name"]

    user.budgets.append(new_budget)
    db.session.commit()

    return jsonify(budget_schema.dump(new_budget))
Beispiel #5
0
def print_budget(budget: Budget, month, year) -> None:
    # Initiate and set up a PrettyTable table

    table_budget = PrettyTable()
    table_budget.field_names = [" id, CATEGORY", "BUDGETED", "OUTFLOW", "AVAILABLE"]
    table_budget.align = "r"  # align in all columns to the right side
    table_budget.align[" id, CATEGORY"] = "l"  # align in column "CATEGORY" to the left side
    table_budget.float_format = "1.2"  # the way floating point data is printed
    table_budget.vertical_char = "║"
    table_budget.horizontal_char = "═"
    table_budget.junction_char = "╬"

    for parent in budget.parent_categories:
        table_budget.add_row([40 * "─", 10 * "─", 10 * "─", 10 * "─"])
        table_budget.add_row(parent.get_prettytable_repr(month, year))
        table_budget.add_row([40 * "─", 10 * "─", 10 * "─", 10 * "─"])

        for category in parent.categories:
            table_budget.add_row(category.get_prettytable_repr(month, year))

        table_budget.add_row([" ", " ", " ", " "])

    budgeted = round(budget.get_budgeted_this_month(month, year), 2)

    outflow = round(budget.total_outflow(month, year), 2)
    inflow = round(budget.total_inflow(month, year), 2)
    available = inflow - outflow
    to_be_budgeted = inflow - budgeted

    print(f"\n{style.bYELLOW}{style.fBOLD}{style.fUNDERLINE}{style.tBLACK}", end="")
    print(f"{budget.name.upper()}{style.RESET}")
    print(f"{style.bYELLOW}{style.fBOLD}{style.tBLACK}", end="")
    print(f"MONTH: {month_name[month].upper()} {year}{style.RESET}")
    # print("-----------------------------")
    print(f"{style.tYELLOW}", end="")
    print(f"BUDGETED:   {budgeted}                 TO BE BUDGETED:   {to_be_budgeted}")
    print(f"TOTAL INFLOW: {inflow}                 TOTAL OUTFLOW:   {outflow}")
    print(f"AVAILABLE:  {available}")
    print(f"{style.RESET}")
    print(table_budget)
from models.Budget import Budget

banana_budget = Budget()
status_code_bad_request = 400
status_code_ok = 200
status_msg = "Invalid startDate"


def test_day_month_year_time_format():
    number_of_days = 1
    response = banana_budget.get_price(number_of_days, "31-08-2018")
    assert response.status_code == status_code_bad_request
    assert response.json()["error"] == status_msg


def test_unexpected_separator_dot():
    # This works even though out of spec
    number_of_days = 1
    response = banana_budget.get_price(number_of_days, "08.01.2018")
    assert response.status_code == status_code_ok


def test_unexpected_separator_slash():
    # This works even though out of spec
    number_of_days = 1
    response = banana_budget.get_price(number_of_days, "08.01.2018")
    assert response.status_code == status_code_ok


def test_out_of_bounds_month():
    number_of_days = 1
Beispiel #7
0
    key = hashlib.pbkdf2_hmac('sha256', "test".encode('utf-8'), salt, 100000)
    # append user instance
    user_list.append(User(name=user_names[i], salt=salt, key=key))

# Zapisz do bazy
session.add_all(user_list)
session.commit()

# ADD BUDGETS
# ------------------------------

budget_list = []

for user_instance in session.query(User).order_by(User.id):
    budget_list.append(
        Budget(name="Budżet użytkownika {}".format(user_instance.name),
               user_id=user_instance.id))

session.add_all(budget_list)
session.commit()

# ADD PARENT CATEGORIES
# ------------------------------

parent_category_list = []
parent_category_names = [
    "Rachunki", "Kredyty", "Wydatki na życie", "Odkładanie", "Rozrywki"
]

for budget_instance in session.query(Budget).order_by(Budget.id):
    for i in range(len(parent_category_names)):
        parent_category_list.append(