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
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_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
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_read_company_by_ticker(client: TestClient, db: Session) -> None: company = create_random_company(db) response = client.get(f"{settings.API_V1_STR}/companies/{company.ticker}") assert response.status_code == 200 content = response.json() assert content["id"] == company.id assert content["name"] == company.name assert content["isin"] == company.isin assert content["number_of_shares"] == company.number_of_shares assert content["url"] == company.url assert content["ipo_date"] == company.ipo_date.strftime("%Y-%m-%d") assert content["stock_exchange"] == company.stock_exchange assert content["ticker"] == company.ticker
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)
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