Skip to content

Commit

Permalink
feat: test to download data provider with different params
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Feb 16, 2024
1 parent 9b8a338 commit 6daa4a5
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 additions & 0 deletions tests/commands/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,160 @@ def test_live_passes_live_holdings_to_lean_runner_when_given_as_option(brokerage
return

assert args[0]["live-holdings"] == holding_list

def test_live_non_interactive_deploy_with_live_and_historical_provider() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

api_client = mock.MagicMock()
container.initialize(docker_manager=mock.Mock(), api_client=api_client, lean_runner=mock.Mock())

provider_live_option = ["--data-provider-live", "IEX",
"--iex-cloud-api-key", "123",
"--iex-price-plan", "Launch"]

provider_history_option = ["--data-provider-historical", "Polygon",
"--polygon-api-key", "123"]

result = CliRunner().invoke(lean, ["live", "deploy" , "--brokerage", "Paper Trading",
*provider_live_option,
*provider_history_option,
"Python Project",
])

# validate amount of request to download packages from api
assert len(api_client.method_calls) > 2

product_ids = []
for method_call in list(api_client.method_calls)[:2]:
product_ids.append(method_call.args[0])

assert "333" in product_ids
assert "306" in product_ids
assert result.exit_code == 0

def test_live_non_interactive_deploy_with_live_and_historical_provider_missed_historical_not_optional_config() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock(), api_client = mock.MagicMock())

provider_live_option = ["--data-provider-live", "IEX",
"--iex-cloud-api-key", "123",
"--iex-price-plan", "Launch"]

provider_history_option = ["--data-provider-historical", "Polygon"]
# "--polygon-api-key", "123"]

result = CliRunner().invoke(lean, ["live", "deploy" , "--brokerage", "Paper Trading",
*provider_live_option,
*provider_history_option,
"Python Project",
])
error_msg = str(result.exc_info[1]).split()

assert "--polygon-api-key" in error_msg
assert "--iex-cloud-api-key" not in error_msg

assert result.exit_code == 1

def test_live_non_interactive_deploy_with_live_and_historical_provider_missed_live_not_optional_config() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock(), api_client = mock.MagicMock())

provider_live_option = ["--data-provider-live", "IEX",
"--iex-cloud-api-key", "123"]
#"--iex-price-plan", "Launch"]

provider_history_option = ["--data-provider-historical", "Polygon", "--polygon-api-key", "123"]

result = CliRunner().invoke(lean, ["live", "deploy" , "--brokerage", "Paper Trading",
*provider_live_option,
*provider_history_option,
"Python Project",
])

error_msg = str(result.exc_info[1]).split()

assert "--iex-price-plan" in error_msg
assert "--polygon-api-key" not in error_msg

assert result.exit_code == 1

def test_live_non_interactive_deploy_with_live_and_without_historical_provider() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

api_client = mock.MagicMock()
container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock(), api_client=api_client)

provider_live_option = ["--data-provider-live", "IEX",
"--iex-cloud-api-key", "123",
"--iex-price-plan", "Launch"]

result = CliRunner().invoke(lean, ["live", "deploy" , "--brokerage", "Paper Trading",
*provider_live_option,
"Python Project",
])

# validate amount of request to download packages from api
assert len(api_client.method_calls) == 2

assert "333" in api_client.method_calls[0].args[0]
assert result.exit_code == 0

def test_live_non_interactive_deploy_with_real_brokerage_without_credentials() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock(), api_client = mock.MagicMock())

# create fake environment has IB configs already
brokerage = ["--brokerage", "OANDA"]

provider_live_option = ["--data-provider-live", "IEX",
"--iex-cloud-api-key", "123",
"--iex-price-plan", "Launch"]

result = CliRunner().invoke(lean, ["live", "deploy" ,
*brokerage,
*provider_live_option,
"Python Project",
])

error_msg = str(result.exc_info[1]).split()

assert "--oanda-account-id" in error_msg
assert "--oanda-access-token" in error_msg
assert "--oanda-environment" in error_msg
assert "--iex-price-plan" not in error_msg

assert result.exit_code == 1

def test_live_non_interactive_deploy_with_interactive_brokerage() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)

api_client = mock.MagicMock()
container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock(), api_client=api_client)

# create fake environment has IB configs already
brokerage = ["--brokerage", "Interactive Brokers"]

provider_live_option = ["--data-provider-live", "Interactive Brokers",
"--iex-cloud-api-key", "123",
"--iex-price-plan", "Launch"]

result = CliRunner().invoke(lean, ["live", "deploy" ,
*brokerage,
*provider_live_option,
"Python Project",
])
assert result.exit_code == 0

# validate amount of request to download packages from api
assert len(api_client.method_calls) == 1

assert "181" in api_client.method_calls[0].args[0]

0 comments on commit 6daa4a5

Please sign in to comment.