Ejemplo n.º 1
0
def test_create_auction(client: TestClient, superuser_token_headers: dict,
                        db: Session):
    product = create_random_product(db)
    starting_amount = random_float()
    reserve = starting_amount + 2 + random_float()
    bid_cap = reserve + 2 + random_float()
    data = {
        'starting_amount': starting_amount,
        'reserve': reserve,
        'bid_cap': bid_cap,
        'product_id': product.id
    }

    response = client.post(f"{settings.API_PREFIX}/v1/auctions/",
                           headers=superuser_token_headers,
                           json=data)

    assert response.status_code == 201
    content = response.json()

    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == starting_amount
    assert content["reserve"] == reserve
    assert content["bid_cap"] == bid_cap
    assert content["product_id"] == product.id
Ejemplo n.º 2
0
def create_random_daily_ratio(db: Session) -> models.DailyRatio:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    currency = random_currency()
    market_cap = random_integer()
    price_to_earnings_ratio_ttm = random_float()
    price_to_book_ratio = random_float()
    market_to_book_ratio = random_float()
    price_to_tangible_book_value = random_float()
    enterprise_value = random_integer()
    ev_to_revenue = random_float()
    ev_to_net_income = random_float()
    ev_to_ebit = random_float()
    ev_to_ebitda = random_float()
    ev_to_assets = random_float()

    daily_ratio_in = DailyRatioCreate(
        period=period,
        end_date=end_date,
        currency=currency,
        market_cap=market_cap,
        price_to_earnings_ratio_ttm=price_to_earnings_ratio_ttm,
        price_to_book_ratio=price_to_book_ratio,
        market_to_book_ratio=market_to_book_ratio,
        price_to_tangible_book_value=price_to_tangible_book_value,
        enterprise_value=enterprise_value,
        ev_to_revenue=ev_to_revenue,
        ev_to_net_income=ev_to_net_income,
        ev_to_ebit=ev_to_ebit,
        ev_to_ebitda=ev_to_ebitda,
        ev_to_assets=ev_to_assets,
        company_id=company_id)
    return crud.daily_ratio.create(db=db, obj_in=daily_ratio_in)
Ejemplo n.º 3
0
def test_delete_daily_ratio(db: Session) -> None:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    currency = random_currency()
    market_cap = random_integer()
    price_to_earnings_ratio_ttm = random_float()
    price_to_book_ratio = random_float()
    market_to_book_ratio = random_float()
    price_to_tangible_book_value = random_float()
    enterprise_value = random_integer()
    ev_to_revenue = random_float()
    ev_to_net_income = random_float()
    ev_to_ebit = random_float()
    ev_to_ebitda = random_float()
    ev_to_assets = random_float()
    
    daily_ratio_in = DailyRatioCreate(       
        period=period,
        end_date=end_date,
        currency=currency,
        market_cap=market_cap,
        price_to_earnings_ratio_ttm=price_to_earnings_ratio_ttm,
        price_to_book_ratio=price_to_book_ratio,
        market_to_book_ratio=market_to_book_ratio,
        price_to_tangible_book_value=price_to_tangible_book_value,
        enterprise_value=enterprise_value,
        ev_to_revenue=ev_to_revenue,
        ev_to_net_income=ev_to_net_income,
        ev_to_ebit=ev_to_ebit,
        ev_to_ebitda=ev_to_ebitda,
        ev_to_assets=ev_to_assets,
        company_id=company_id
        )
    daily_ratio = crud.daily_ratio.create(db=db, obj_in=daily_ratio_in)
    daily_ratio2 = crud.daily_ratio.remove(db=db, id=daily_ratio.id)
    daily_ratio3 = crud.daily_ratio.get(db=db, id=daily_ratio.id)
    assert daily_ratio3 is None
    assert daily_ratio2.id == daily_ratio.id
    assert daily_ratio2.period == period
    assert daily_ratio2.end_date.strftime("%Y-%m-%d") == end_date.strftime("%Y-%m-%d")
    assert daily_ratio2.currency == currency
    assert daily_ratio2.market_cap == market_cap
    assert daily_ratio2.price_to_earnings_ratio_ttm == price_to_earnings_ratio_ttm
    assert daily_ratio2.price_to_book_ratio == price_to_book_ratio
    assert daily_ratio2.market_to_book_ratio == market_to_book_ratio
    assert daily_ratio2.price_to_tangible_book_value == price_to_tangible_book_value
    assert daily_ratio2.enterprise_value == enterprise_value
    assert daily_ratio2.ev_to_revenue == ev_to_revenue
    assert daily_ratio2.ev_to_net_income == ev_to_net_income
    assert daily_ratio2.ev_to_ebit == ev_to_ebit
    assert daily_ratio2.ev_to_ebitda == ev_to_ebitda
    assert daily_ratio2.ev_to_assets == ev_to_assets
    assert daily_ratio2.company_id == company_id
Ejemplo n.º 4
0
def create_random_auction(db: Session) -> Auction:

    product = create_random_product(db)
    starting_amount = random_float()
    reserve = starting_amount + random_float() + 2
    bid_cap = reserve + random_float() + 2
    owner = product.owner

    return auction_repo.create_with_owner(db,
                                          obj_in=AuctionCreate(
                                              product_id=product.id,
                                              owner_id=owner.id,
                                              starting_amount=starting_amount,
                                              reserve=reserve,
                                              bid_cap=bid_cap),
                                          owner_id=owner.id)
Ejemplo n.º 5
0
def test_end_auction(client: TestClient, superuser_token_headers: dict,
                     db: Session):
    auction = create_random_auction(db)
    amount = auction.reserve + random_float()
    bidder = create_random_user(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    english.bid(db, db_obj=auction, amount=amount, bidder_id=bidder.id)

    response = client.put(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/end",
        headers=superuser_token_headers)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.state == AuctionState.ENDED
    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == auction.starting_amount
    assert content["reserve"] == auction.reserve
    assert content["bid_cap"] == auction.bid_cap
    assert content["product_id"] == auction.product_id
    assert content["state"] == AuctionState.ENDED
Ejemplo n.º 6
0
def test_create_auction(db: Session):
    product = create_random_product(db)
    starting_amount = random_float()
    reserve = starting_amount + random_float()
    bid_cap = reserve + random_float()
    owner = product.owner

    auction = auction_repo.create(db,
                                  obj_in=AuctionCreate(
                                      product_id=product.id,
                                      starting_amount=starting_amount,
                                      reserve=reserve,
                                      bid_cap=bid_cap))

    db_obj = auction_repo.get(db, id=auction.id)

    assert db_obj
    assert db_obj.product_id == product.id
    assert db_obj.starting_amount == starting_amount
    assert db_obj.reserve == reserve
    assert db_obj.bid_cap == bid_cap
    assert db_obj.state == AuctionState.CREATED
Ejemplo n.º 7
0
def test_create_daily_ratio(client: TestClient, superuser_token_headers: dict,
                            db: Session) -> None:
    data = {
        "period": random_period(),
        "end_date": random_date().strftime("%Y-%m-%d"),
        "currency": random_currency(),
        "market_cap": random_integer(),
        "price_to_earnings_ratio_ttm": random_float(),
        "price_to_book_ratio": random_float(),
        "market_to_book_ratio": random_float(),
        "price_to_tangible_book_value": random_float(),
        "enterprise_value": random_integer(),
        "ev_to_revenue": random_float(),
        "ev_to_net_income": random_float(),
        "ev_to_ebit": random_float(),
        "ev_to_ebitda": random_float(),
        "ev_to_assets": random_float()
    }

    response = client.post(f"{settings.API_V1_STR}/dailyratios/",
                           headers=superuser_token_headers,
                           json=data)

    assert response.status_code == 200
    content = response.json()
    assert content["period"] == data["period"]
    assert content["end_date"] == data["end_date"]
    assert content["currency"] == data["currency"]
    assert content["market_cap"] == data["market_cap"]
    assert content["price_to_earnings_ratio_ttm"] == data[
        "price_to_earnings_ratio_ttm"]
    assert content["price_to_book_ratio"] == data["price_to_book_ratio"]
    assert content["market_to_book_ratio"] == data["market_to_book_ratio"]
    assert content["price_to_tangible_book_value"] == data[
        "price_to_tangible_book_value"]
    assert content["enterprise_value"] == data["enterprise_value"]
    assert content["ev_to_revenue"] == data["ev_to_revenue"]
    assert content["ev_to_net_income"] == data["ev_to_net_income"]
    assert content["ev_to_ebit"] == data["ev_to_ebit"]
    assert content["ev_to_ebitda"] == data["ev_to_ebitda"]
    assert content["ev_to_assets"] == data["ev_to_assets"]
    assert "id" in content
Ejemplo n.º 8
0
def create_random_item(db: Session, itemtype_id: int, category_id: int,
                       payment_id: int) -> models.Item:
    user = create_random_user(db)
    owner_id = user.id
    description = random_string()
    amount = random_float()
    date = random_date()
    item_in = ItemCreate(description=description,
                         amount=amount,
                         date=date,
                         itemtype_id=itemtype_id,
                         category_id=category_id,
                         payment_id=payment_id)
    return crud.item.create_with_owner(db=db,
                                       obj_in=item_in,
                                       owner_id=owner_id)
def test_end(db: Session):
    auction = create_random_auction(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    assert auction.state == AuctionState.ONGOING

    amount = auction.reserve + random_float()
    bidder = create_random_user(db)
    english.bid(db, db_obj=auction, amount=amount, bidder_id=bidder.id)
    db_obj = auction_repo.get(db, id=auction.id)

    assert db_obj.winning_bid

    english.end(db, db_obj=db_obj)
    assert db_obj.state == AuctionState.ENDED
    assert db_obj.final_winner_id == bidder.id
Ejemplo n.º 10
0
def test_bid_auction(client: TestClient, superuser_token_headers: dict,
                     db: Session):
    auction = create_random_auction(db)
    amount = auction.reserve + random_float()
    english = EnglishAuction()
    english.start(db, db_obj=auction)
    data = amount

    response = client.post(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/bid",
        headers=superuser_token_headers,
        json=data)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.winning_bid
    assert auction.last_bid_at
Ejemplo n.º 11
0
from sqlalchemy.orm import Session
import datetime
import pytest
import mock
from pydantic import ValidationError
from alchemy_mock.mocking import AlchemyMagicMock

from app import crud
from app.db.exc import DBException
from app.schemas.item import ItemCreate, ItemUpdate
from app.tests.utils.user import create_random_user
from app.tests.utils.utils import random_string, random_float

DESCRIPTION = random_string()
AMOUNT = random_float()
DATE = "01.12.2020"


def _compare_items(a, b):
    assert a.description == b.description
    assert a.amount == b.amount
    assert a.date == b.date
    assert a.payment_id == b.payment_id
    assert a.category_id == b.category_id
    assert a.id == b.id
    assert a.owner_id == b.owner_id


def _create_schema_for_item(itemtype_id: int, category_id: int,
                            payment_id: int) -> ItemCreate:
    return ItemCreate(description=DESCRIPTION,
Ejemplo n.º 12
0
def test_create_value_metric(client: TestClient, superuser_token_headers: dict,
                             db: Session) -> None:
    data = {
        "period": random_period(),
        "end_date": random_date().strftime("%Y-%m-%d"),
        "currency": random_currency(),
        "book_value": random_integer(),
        "tangible_book_value": random_integer(),
        "tangible_book_value_per_share": random_float(),
        "debt_to_equity": random_float(),
        "equity_ratio": random_float(),
        "debt_ratio": random_float(),
        "cash_ratio": random_float(),
        "gross_profit_margin": random_float(),
        "net_profit_margin": random_float(),
        "ebit_margin": random_float(),
        "operating_margin": random_float(),
        "ebitda_margin": random_float(),
        "cash_return_on_capital_invested": random_float(),
        "debt_to_ebitda": random_float(),
        "return_on_equity": random_float(),
        "return_on_assets": random_float(),
        "current_ratio": random_float(),
        "working_capital": random_integer()
    }

    response = client.post(f"{settings.API_V1_STR}/valuemetrics/",
                           headers=superuser_token_headers,
                           json=data)

    assert response.status_code == 200
    content = response.json()
    assert content["period"] == data["period"]
    assert content["end_date"] == data["end_date"]
    assert content["currency"] == data["currency"]
    assert content["book_value"] == data["book_value"]
    assert content["tangible_book_value"] == data["tangible_book_value"]
    assert content["tangible_book_value_per_share"] == data[
        "tangible_book_value_per_share"]
    assert content["debt_to_equity"] == data["debt_to_equity"]
    assert content["equity_ratio"] == data["equity_ratio"]
    assert content["debt_ratio"] == data["debt_ratio"]
    assert content["cash_ratio"] == data["cash_ratio"]
    assert content["gross_profit_margin"] == data["gross_profit_margin"]
    assert content["net_profit_margin"] == data["net_profit_margin"]
    assert content["ebit_margin"] == data["ebit_margin"]
    assert content["operating_margin"] == data["operating_margin"]
    assert content["ebitda_margin"] == data["ebitda_margin"]
    assert content["cash_return_on_capital_invested"] == data[
        "cash_return_on_capital_invested"]
    assert content["debt_to_ebitda"] == data["debt_to_ebitda"]
    assert content["return_on_equity"] == data["return_on_equity"]
    assert content["return_on_assets"] == data["return_on_assets"]
    assert content["current_ratio"] == data["current_ratio"]
    assert content["working_capital"] == data["working_capital"]
    assert "id" in content
Ejemplo n.º 13
0
def create_random_financial_statement(
        db: Session) -> models.FinancialStatement:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    publish_date = random_date()
    url = random_url()
    audited = random_bool()
    currency = random_currency()
    non_current_assets = random_integer()
    cash_and_equivalents = random_integer()
    current_assets = random_integer()
    total_assets = random_integer()
    short_term_debt = random_integer()
    current_liabilities = random_integer()
    long_term_debt = random_integer()
    long_term_liabilities = random_integer()
    total_debt = random_integer()
    total_liabilities = random_integer()
    total_equity = random_integer()
    total_equities_and_liabilities = random_integer()
    total_revenues = random_integer()
    cost_of_revenue = random_integer()
    costs_of_goods_sold = random_integer()
    gross_profit = random_integer()
    ebitda = random_integer()
    ebit = random_integer()
    operating_income = random_integer()
    interest_expense = random_integer()
    profit_before_tax = random_integer()
    tax_expense = random_integer()
    depreciation = random_integer()
    amortization = random_integer()
    net_income = random_integer()
    earnings_per_share = random_float()

    financial_statement_in = FinancialStatementCreate(
        period=period,
        end_date=end_date,
        publish_date=publish_date,
        url=url,
        audited=audited,
        currency=currency,
        non_current_assets=non_current_assets,
        cash_and_equivalents=cash_and_equivalents,
        current_assets=current_assets,
        total_assets=total_assets,
        short_term_debt=short_term_debt,
        current_liabilities=current_liabilities,
        long_term_debt=long_term_debt,
        long_term_liabilities=long_term_liabilities,
        total_debt=total_debt,
        total_liabilities=total_liabilities,
        total_equity=total_equity,
        total_equities_and_liabilities=total_equities_and_liabilities,
        total_revenues=total_revenues,
        cost_of_revenue=cost_of_revenue,
        costs_of_goods_sold=costs_of_goods_sold,
        gross_profit=gross_profit,
        ebitda=ebitda,
        ebit=ebit,
        operating_income=operating_income,
        interest_expense=interest_expense,
        profit_before_tax=profit_before_tax,
        tax_expense=tax_expense,
        depreciation=depreciation,
        amortization=amortization,
        net_income=net_income,
        earnings_per_share=earnings_per_share,
        company_id=company_id)
    return crud.financial_statement.create(db=db,
                                           obj_in=financial_statement_in)
Ejemplo n.º 14
0
def create_random_value_metric(db: Session) -> models.ValueMetric:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    currency = random_currency()
    book_value = random_integer()
    tangible_book_value = random_integer()
    tangible_book_value_per_share = random_float()
    debt_to_equity = random_float()
    equity_ratio = random_float()
    debt_ratio = random_float()
    cash_ratio = random_float()
    gross_profit_margin = random_float()
    net_profit_margin = random_float()
    ebit_margin = random_float()
    operating_margin = random_float()
    ebitda_margin = random_float()
    cash_return_on_capital_invested = random_float()
    debt_to_ebitda = random_float()
    return_on_equity = random_float()
    return_on_assets = random_float()
    current_ratio = random_float()
    working_capital = random_integer()

    value_metric_in = ValueMetricCreate(
        period=period,
        end_date=end_date,
        currency=currency,
        book_value=book_value,
        tangible_book_value=tangible_book_value,
        tangible_book_value_per_share=tangible_book_value_per_share,
        debt_to_equity=debt_to_equity,
        equity_ratio=equity_ratio,
        debt_ratio=debt_ratio,
        cash_ratio=cash_ratio,
        gross_profit_margin=gross_profit_margin,
        net_profit_margin=net_profit_margin,
        ebit_margin=ebit_margin,
        operating_margin=operating_margin,
        ebitda_margin=ebitda_margin,
        cash_return_on_capital_invested=cash_return_on_capital_invested,
        debt_to_ebitda=debt_to_ebitda,
        return_on_equity=return_on_equity,
        return_on_assets=return_on_assets,
        current_ratio=current_ratio,
        working_capital=working_capital,
        company_id=company_id)
    return crud.value_metric.create(db=db, obj_in=value_metric_in)
Ejemplo n.º 15
0
def test_get_value_metric(db: Session) -> None:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    currency = random_currency()
    book_value = random_integer()
    tangible_book_value = random_integer()
    tangible_book_value_per_share = random_float()
    debt_to_equity = random_float()
    equity_ratio = random_float()
    debt_ratio = random_float()
    cash_ratio = random_float()
    gross_profit_margin = random_float()
    net_profit_margin = random_float()
    ebit_margin = random_float()
    operating_margin = random_float()
    ebitda_margin = random_float()
    cash_return_on_capital_invested = random_float()
    debt_to_ebitda = random_float()
    return_on_equity = random_float()
    return_on_assets = random_float()
    current_ratio = random_float()
    working_capital = random_integer()

    value_metric_in = ValueMetricCreate(
        period=period,
        end_date=end_date,
        currency=currency,
        book_value=book_value,
        tangible_book_value=tangible_book_value,
        tangible_book_value_per_share=tangible_book_value_per_share,
        debt_to_equity=debt_to_equity,
        equity_ratio=equity_ratio,
        debt_ratio=debt_ratio,
        cash_ratio=cash_ratio,
        gross_profit_margin=gross_profit_margin,
        net_profit_margin=net_profit_margin,
        ebit_margin=ebit_margin,
        operating_margin=operating_margin,
        ebitda_margin=ebitda_margin,
        cash_return_on_capital_invested=cash_return_on_capital_invested,
        debt_to_ebitda=debt_to_ebitda,
        return_on_equity=return_on_equity,
        return_on_assets=return_on_assets,
        current_ratio=current_ratio,
        working_capital=working_capital,
        company_id=company_id)
    value_metric = crud.value_metric.create(db=db, obj_in=value_metric_in)
    stored_value_metric = crud.value_metric.get(db=db, id=value_metric.id)

    assert value_metric.id == stored_value_metric.id
    assert value_metric.period == stored_value_metric.period
    assert value_metric.end_date.strftime(
        "%Y-%m-%d") == stored_value_metric.end_date.strftime("%Y-%m-%d")
    assert value_metric.currency == stored_value_metric.currency
    assert value_metric.book_value == stored_value_metric.book_value
    assert value_metric.tangible_book_value == stored_value_metric.tangible_book_value
    assert value_metric.tangible_book_value_per_share == stored_value_metric.tangible_book_value_per_share
    assert value_metric.debt_to_equity == stored_value_metric.debt_to_equity
    assert value_metric.equity_ratio == stored_value_metric.equity_ratio
    assert value_metric.debt_ratio == stored_value_metric.debt_ratio
    assert value_metric.cash_ratio == stored_value_metric.cash_ratio
    assert value_metric.gross_profit_margin == stored_value_metric.gross_profit_margin
    assert value_metric.net_profit_margin == stored_value_metric.net_profit_margin
    assert value_metric.ebit_margin == stored_value_metric.ebit_margin
    assert value_metric.operating_margin == stored_value_metric.operating_margin
    assert value_metric.ebitda_margin == stored_value_metric.ebitda_margin
    assert value_metric.cash_return_on_capital_invested == stored_value_metric.cash_return_on_capital_invested
    assert value_metric.debt_to_ebitda == stored_value_metric.debt_to_ebitda
    assert value_metric.return_on_equity == stored_value_metric.return_on_equity
    assert value_metric.return_on_assets == stored_value_metric.return_on_assets
    assert value_metric.current_ratio == stored_value_metric.current_ratio
    assert value_metric.working_capital == stored_value_metric.working_capital
    assert value_metric.company_id == stored_value_metric.company_id
Ejemplo n.º 16
0
def test_delete_financial_statement(db: Session) -> None:
    company = create_random_company(db)
    company_id = company.id
    period = random_period()
    end_date = random_date()
    publish_date = random_date()
    url = random_url()
    audited = random_bool()
    currency = random_currency()
    non_current_assets = random_integer()
    cash_and_equivalents = random_integer()
    current_assets = random_integer()
    total_assets = random_integer()
    short_term_debt = random_integer()
    current_liabilities = random_integer()
    long_term_debt = random_integer()
    long_term_liabilities = random_integer()
    total_debt = random_integer()
    total_liabilities = random_integer()
    total_equity = random_integer()
    total_equities_and_liabilities = random_integer()
    total_revenues = random_integer()
    cost_of_revenue = random_integer()
    costs_of_goods_sold = random_integer()
    gross_profit = random_integer()
    ebitda = random_integer()
    ebit = random_integer()
    operating_income = random_integer()
    interest_expense = random_integer()
    profit_before_tax = random_integer()
    tax_expense = random_integer()
    depreciation = random_integer()
    amortization = random_integer()
    net_income = random_integer()
    earnings_per_share = random_float()

    financial_statement_in = FinancialStatementCreate(
        period=period,
        end_date=end_date,
        publish_date=publish_date,
        url=url,
        audited=audited,
        currency=currency,
        non_current_assets=non_current_assets,
        cash_and_equivalents=cash_and_equivalents,
        current_assets=current_assets,
        total_assets=total_assets,
        short_term_debt=short_term_debt,
        current_liabilities=current_liabilities,
        long_term_debt=long_term_debt,
        long_term_liabilities=long_term_liabilities,
        total_debt=total_debt,
        total_liabilities=total_liabilities,
        total_equity=total_equity,
        total_equities_and_liabilities=total_equities_and_liabilities,
        total_revenues=total_revenues,
        cost_of_revenue=cost_of_revenue,
        costs_of_goods_sold=costs_of_goods_sold,
        gross_profit=gross_profit,
        ebitda=ebitda,
        ebit=ebit,
        operating_income=operating_income,
        interest_expense=interest_expense,
        profit_before_tax=profit_before_tax,
        tax_expense=tax_expense,
        depreciation=depreciation,
        amortization=amortization,
        net_income=net_income,
        earnings_per_share=earnings_per_share,
        company_id=company_id)
    financial_statement = crud.financial_statement.create(
        db=db, obj_in=financial_statement_in)
    financial_statement2 = crud.financial_statement.remove(
        db=db, id=financial_statement.id)
    financial_statement3 = crud.financial_statement.get(
        db=db, id=financial_statement.id)
    assert financial_statement3 is None
    assert financial_statement2.id == financial_statement.id
    assert financial_statement2.period == period
    assert financial_statement2.end_date.strftime(
        "%Y-%m-%d") == end_date.strftime("%Y-%m-%d")
    assert financial_statement2.publish_date.strftime(
        "%Y-%m-%d") == publish_date.strftime("%Y-%m-%d")
    assert financial_statement2.url == url
    assert financial_statement2.audited == audited
    assert financial_statement2.currency == currency
    assert financial_statement2.non_current_assets == non_current_assets
    assert financial_statement2.cash_and_equivalents == cash_and_equivalents
    assert financial_statement2.current_assets == current_assets
    assert financial_statement2.total_assets == total_assets
    assert financial_statement2.short_term_debt == short_term_debt
    assert financial_statement2.current_liabilities == current_liabilities
    assert financial_statement2.long_term_debt == long_term_debt
    assert financial_statement2.long_term_liabilities == long_term_liabilities
    assert financial_statement2.total_debt == total_debt
    assert financial_statement2.total_liabilities == total_liabilities
    assert financial_statement2.total_equity == total_equity
    assert financial_statement2.total_equities_and_liabilities == total_equities_and_liabilities
    assert financial_statement2.total_revenues == total_revenues
    assert financial_statement2.cost_of_revenue == cost_of_revenue
    assert financial_statement2.costs_of_goods_sold == costs_of_goods_sold
    assert financial_statement2.gross_profit == gross_profit
    assert financial_statement2.ebitda == ebitda
    assert financial_statement2.ebit == ebit
    assert financial_statement2.operating_income == operating_income
    assert financial_statement2.interest_expense == interest_expense
    assert financial_statement2.profit_before_tax == profit_before_tax
    assert financial_statement2.tax_expense == tax_expense
    assert financial_statement2.depreciation == depreciation
    assert financial_statement2.amortization == amortization
    assert financial_statement2.net_income == net_income
    assert financial_statement2.earnings_per_share == earnings_per_share
    assert financial_statement2.company_id == company_id
Ejemplo n.º 17
0
def test_create_financial_statement(client: TestClient,
                                    superuser_token_headers: dict,
                                    db: Session) -> None:
    data = {
        "period": random_period(),
        "end_date": random_date().strftime("%Y-%m-%d"),
        "publish_date": random_date().strftime("%Y-%m-%d"),
        "url": random_url(),
        "audited": True,
        "currency": random_currency(),
        "non_current_assets": random_integer(),
        "cash_and_equivalents": random_integer(),
        "current_assets": random_integer(),
        "total_assets": random_integer(),
        "short_term_debt": random_integer(),
        "current_liabilities": random_integer(),
        "long_term_debt": random_integer(),
        "long_term_liabilities": random_integer(),
        "total_debt": random_integer(),
        "total_liabilities": random_integer(),
        "total_equity": random_integer(),
        "total_equities_and_liabilities": random_integer(),
        "total_revenues": random_integer(),
        "cost_of_revenue": random_integer(),
        "costs_of_goods_sold": random_integer(),
        "gross_profit": random_integer(),
        "ebitda": random_integer(),
        "ebit": random_integer(),
        "operating_income": random_integer(),
        "interest_expense": random_integer(),
        "profit_before_tax": random_integer(),
        "tax_expense": random_integer(),
        "depreciation": random_integer(),
        "amortization": random_integer(),
        "net_income": random_integer(),
        "earnings_per_share": random_float()
    }

    response = client.post(f"{settings.API_V1_STR}/financialstatements/",
                           headers=superuser_token_headers,
                           json=data)

    assert response.status_code == 200
    content = response.json()
    assert content["period"] == data["period"]
    assert content["end_date"] == data["end_date"]
    assert content["publish_date"] == data["publish_date"]
    assert content["url"] == data["url"]
    assert content["audited"] == data["audited"]
    assert content["currency"] == data["currency"]
    assert content["non_current_assets"] == data["non_current_assets"]
    assert content["cash_and_equivalents"] == data["cash_and_equivalents"]
    assert content["current_assets"] == data["current_assets"]
    assert content["total_assets"] == data["total_assets"]
    assert content["short_term_debt"] == data["short_term_debt"]
    assert content["current_liabilities"] == data["current_liabilities"]
    assert content["long_term_debt"] == data["long_term_debt"]
    assert content["long_term_liabilities"] == data["long_term_liabilities"]
    assert content["total_debt"] == data["total_debt"]
    assert content["total_liabilities"] == data["total_liabilities"]
    assert content["total_equity"] == data["total_equity"]
    assert content["total_equities_and_liabilities"] == data[
        "total_equities_and_liabilities"]
    assert content["total_revenues"] == data["total_revenues"]
    assert content["cost_of_revenue"] == data["cost_of_revenue"]
    assert content["costs_of_goods_sold"] == data["costs_of_goods_sold"]
    assert content["gross_profit"] == data["gross_profit"]
    assert content["ebitda"] == data["ebitda"]
    assert content["ebit"] == data["ebit"]
    assert content["operating_income"] == data["operating_income"]
    assert content["interest_expense"] == data["interest_expense"]
    assert content["profit_before_tax"] == data["profit_before_tax"]
    assert content["tax_expense"] == data["tax_expense"]
    assert content["depreciation"] == data["depreciation"]
    assert content["amortization"] == data["amortization"]
    assert content["net_income"] == data["net_income"]
    assert content["earnings_per_share"] == data["earnings_per_share"]
    assert "id" in content