def test_get_track(db: Session) -> None: title = random_lower_string() artist = random_lower_string() provider = create_random_provider(db) license = create_random_license(db) url = random_url() media_url = random_url() track_in = TrackCreate( title=title, artist=artist, provider_name=provider.name, license_name=license.name, url=url, media_url=media_url, ) track_in.s3_preview_key = canonical_preview_uri(track_in) db_track = crud.track.create(db, obj_in=track_in) stored_track = crud.track.get(db=db, id=db_track.id) assert stored_track assert db_track.id == stored_track.id assert db_track.title == stored_track.title assert db_track.artist == stored_track.artist assert db_track.provider_id == stored_track.provider_id assert db_track.license_id == stored_track.license_id assert db_track.url == stored_track.url assert db_track.media_url == stored_track.media_url assert db_track.s3_preview_key == stored_track.s3_preview_key
def test_update_track(db: Session) -> None: title = random_lower_string() artist = random_lower_string() provider = create_random_provider(db) license = create_random_license(db) url = random_url() media_url = random_url() track_in = TrackCreate( title=title, artist=artist, provider_name=provider.name, license_name=license.name, url=url, media_url=media_url, ) db_track = crud.track.create(db, obj_in=track_in) url2 = random_url() provider2 = create_random_provider(db) track_update = TrackUpdate(id=db_track.id, url=url2, provider=provider2) track2 = crud.track.update(db=db, db_obj=db_track, obj_in=track_update) assert db_track.id == track2.id assert db_track.title == track2.title assert track2.url == url2 assert track2.provider == provider2 assert db_track.license == track2.license
def test_import_track(db: Session): with open("app/tests/support/example.mp3", "rb") as f: responses.add( responses.GET, "http://example.com/sample.mp3", content_type="audio/mpeg", body=f, # type: ignore ) title = random_lower_string() artist = random_lower_string() provider = create_random_provider(db) license = create_random_license(db) url = random_url() media_url = "http://example.com/sample.mp3" track_in = TrackCreate( title=title, artist=artist, provider_name=provider.name, license_name=license.name, url=url, media_url=media_url, ) db_track = import_track(db, track_in) on_s3 = object_store.object_on_s3(db_track.s3_preview_key) assert on_s3 in [None, True] if on_s3: object_store.remove_from_s3(db_track.s3_preview_key) assert db_track.title == title assert db_track.url == url assert db_track.s3_preview_key == canonical_preview_uri(track_in) assert db_track.embeddings assert db_track.embeddings[0].track_id == db_track.id as_ary = np.array(db_track.embeddings[0].values) assert np.isclose(np.linalg.norm(as_ary), 1.)
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
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
def create_random_track(db: Session, *, provider_name: Optional[str] = None, license_name: Optional[str] = None) -> models.Track: if provider_name is None: provider= create_random_provider(db) provider_name = provider.name if license_name is None: license = create_random_license(db) license_name = license.name track_in = TrackCreate( title = random_lower_string(), artist = random_lower_string(), url = random_url(), provider_name = provider_name, license_name = license_name, media_url = random_url() ) track_in.s3_preview_key = canonical_preview_uri(track_in) return crud.track.create(db, obj_in=track_in)
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
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)
def create_random_provider(db: Session) -> models.Provider: name = random_lower_string() url = random_url() provider_in = ProviderCreate(name=name, url=url) return crud.provider.create(db=db, obj_in=provider_in)
def create_random_license(db: Session) -> models.License: name = random_lower_string() url = random_url() license_in = LicenseCreate(name=name, url=url) return crud.license.create(db=db, obj_in=license_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_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