Ejemplo n.º 1
0
def test_delete_dividend(db: Session) -> None:
    company = create_random_company(db)
    company_id = company.id
    currency = random_currency()
    ex_dividend_date = random_date()
    pay_date = random_date()
    dividend_payout = random_dividend_payout()

    dividend_in = DividendCreate(
        currency=currency,
        ex_dividend_date=ex_dividend_date,
        pay_date=pay_date,
        dividend_payout=dividend_payout,
        company_id=company_id
    )
    dividend = crud.dividend.create(db=db, obj_in=dividend_in)
    dividend2 = crud.dividend.remove(db=db, id=dividend.id)
    dividend3 = crud.dividend.get(db=db, id=dividend.id)
    assert dividend3 is None
    assert dividend2.id == dividend.id
    assert dividend2.currency == currency
    assert dividend2.ex_dividend_date.strftime("%Y-%m-%d") == ex_dividend_date.strftime("%Y-%m-%d")
    assert dividend2.pay_date.strftime("%Y-%m-%d") == pay_date.strftime("%Y-%m-%d")
    assert dividend2.dividend_payout == dividend_payout
    assert dividend2.company_id == company_id
Ejemplo n.º 2
0
def test_update_dividend(db: Session) -> None:
    company = create_random_company(db)
    company_id = company.id
    currency = random_currency()
    ex_dividend_date = random_date()
    pay_date = random_date()
    dividend_payout = random_dividend_payout()

    dividend_in = DividendCreate(
        currency=currency,
        ex_dividend_date=ex_dividend_date,
        pay_date=pay_date,
        dividend_payout=dividend_payout,
        company_id=company_id
    )

    dividend = crud.dividend.create(db=db, obj_in = dividend_in)

    ex_dividend_date2 = random_date()
    pay_date2 = random_date()
    dividend_payout2 = random_dividend_payout()
    
    dividend_update = DividendUpdate(
        ex_dividend_date=ex_dividend_date2,
        pay_date=pay_date2,
        dividend_payout=dividend_payout2
    )
    
    dividend2 = crud.dividend.update(db=db, db_obj=dividend, obj_in=dividend_update)
    assert dividend.currency == dividend2.currency
    assert dividend2.ex_dividend_date.strftime("%Y-%m-%d") == ex_dividend_date2.strftime("%Y-%m-%d")
    assert dividend2.pay_date.strftime("%Y-%m-%d") == pay_date2.strftime("%Y-%m-%d")
    assert dividend2.dividend_payout == dividend_payout2
    assert dividend.company_id == dividend2.company_id
Ejemplo n.º 3
0
def create_random_dividend(db: Session) -> models.Dividend:
    company = create_random_company(db)
    company_id = company.id
    currency = random_currency()
    ex_dividend_date = random_date()
    pay_date = random_date()
    dividend_payout = random_dividend_payout()
    
    dividend_in = DividendCreate(
        currency=currency,
        ex_dividend_date=ex_dividend_date,
        pay_date=pay_date,
        dividend_payout=dividend_payout,
        company_id=company_id
    )
    return crud.dividend.create(db=db, obj_in=dividend_in)
Ejemplo n.º 4
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.º 5
0
def test_get_company(db: Session) -> None:
    name = random_lower_string()
    isin = random_isin()
    number_of_shares = random_number_of_shares()
    url = random_url()
    ticker = random_lower_string()
    ipo_date = random_date()
    stock_exchange = random_lower_string()

    company_in = CompanyCreate(name=name,
                               isin=isin,
                               number_of_shares=number_of_shares,
                               url=url,
                               ticker=ticker,
                               ipo_date=ipo_date,
                               stock_exchange=stock_exchange)
    company = crud.company.create(db=db, obj_in=company_in)
    stored_company = crud.company.get(db=db, id=company.id)
    assert company.id == stored_company.id
    assert company.name == stored_company.name
    assert company.isin == stored_company.isin
    assert company.number_of_shares == stored_company.number_of_shares
    assert company.url == stored_company.url
    assert company.ticker == stored_company.ticker
    assert company.ipo_date.strftime(
        "%Y-%m-%d") == stored_company.ipo_date.strftime("%Y-%m-%d")
    assert company.stock_exchange == stored_company.stock_exchange
Ejemplo n.º 6
0
def test_create_company(client: TestClient, superuser_token_headers: dict,
                        db: Session) -> None:
    data = {
        "name": random_lower_string(),
        "isin": random_isin(),
        "number_of_shares": random_number_of_shares(),
        "url": random_url(),
        "ticker": random_lower_string(),
        "ipo_date": random_date().strftime("%Y-%m-%d"),
        "stock_exchange": random_lower_string()
    }

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

    assert response.status_code == 200
    content = response.json()
    assert content["name"] == data["name"]
    assert content["isin"] == data["isin"]
    assert content["number_of_shares"] == data["number_of_shares"]
    assert content["url"] == data["url"]
    assert content["ticker"] == data["ticker"]
    assert content["ipo_date"] == data["ipo_date"]
    assert content["stock_exchange"] == data["stock_exchange"]
    assert "id" in content
Ejemplo n.º 7
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.º 8
0
def test_create_dividend(client: TestClient, superuser_token_headers: dict,
                         db: Session) -> None:
    data = {
        "currency": random_currency(),
        "ex_dividend_date": random_date().strftime("%Y-%m-%d"),
        "pay_date": random_date().strftime("%Y-%m-%d"),
        "dividend_payout": random_dividend_payout()
    }
    response = client.post(f"{settings.API_V1_STR}/dividends/",
                           headers=superuser_token_headers,
                           json=data)

    assert response.status_code == 200
    content = response.json()
    assert content["currency"] == data["currency"]
    assert content["ex_dividend_date"] == data["ex_dividend_date"]
    assert content["pay_date"] == data["pay_date"]
    assert content["dividend_payout"] == data["dividend_payout"]
    assert "id" in content
Ejemplo n.º 9
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.º 10
0
def test_update_company(db: Session) -> None:
    name = random_lower_string()
    isin = random_isin()
    number_of_shares = random_number_of_shares()
    url = random_url()
    ticker = random_lower_string()
    ipo_date = random_date()
    stock_exchange = random_lower_string()

    company_in = CompanyCreate(name=name,
                               isin=isin,
                               number_of_shares=number_of_shares,
                               url=url,
                               ticker=ticker,
                               ipo_date=ipo_date,
                               stock_exchange=stock_exchange)
    company = crud.company.create(db=db, obj_in=company_in)
    name2 = random_lower_string()
    isin2 = random_isin()
    number_of_shares2 = random_number_of_shares()
    url2 = random_url()
    ipo_date2 = random_date()

    company_update = CompanyUpdate(
        name=name2,
        isin=isin2,
        number_of_shares=number_of_shares2,
        url=url2,
        ipo_date=ipo_date2,
    )
    company2 = crud.company.update(db=db,
                                   db_obj=company,
                                   obj_in=company_update)
    assert company.id == company2.id
    assert company2.name == name2
    assert company2.isin == isin2
    assert company2.number_of_shares == number_of_shares2
    assert company2.url == url2
    assert company.ticker == company2.ticker
    assert company2.ipo_date.strftime("%Y-%m-%d") == ipo_date2.strftime(
        "%Y-%m-%d")
    assert company.stock_exchange == company2.stock_exchange
Ejemplo n.º 11
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.º 12
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)
Ejemplo n.º 13
0
def create_random_company(db: Session) -> models.Company:
    name = random_lower_string()
    isin = random_isin()
    number_of_shares = random_number_of_shares()
    url = random_url()
    ticker = random_lower_string()
    ipo_date = random_date()
    stock_exchange = random_lower_string()

    company_in = CompanyCreate(name=name,
                               isin=isin,
                               number_of_shares=number_of_shares,
                               url=url,
                               ticker=ticker,
                               ipo_date=ipo_date,
                               stock_exchange=stock_exchange,
                               id=id)

    return crud.company.create(db=db, obj_in=company_in)
Ejemplo n.º 14
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.º 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
Ejemplo n.º 18
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)