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)
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
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
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)
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
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
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)
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
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