1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
"""Test cases for the __main__ module."""
from aioresponses import aioresponses
from aioresponses.core import RequestCall
from click.testing import CliRunner
from syrupy.assertion import SnapshotAssertion
from yarl import URL
from tests import fixtures
from . import initialise_credential_store
from renault_api.cli import __main__
def test_hvac_history_day(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
fixtures.inject_get_hvac_history(
mocked_responses, start="20201101", end="20201130", period="day"
)
result = cli_runner.invoke(
__main__.main, "hvac history --from 2020-11-01 --to 2020-11-30 --period day"
)
assert result.exit_code == 0, result.exception
assert result.output == snapshot
def test_hvac_history_month(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
fixtures.inject_get_hvac_history(
mocked_responses, start="202011", end="202011", period="month"
)
result = cli_runner.invoke(
__main__.main, "hvac history --from 2020-11-01 --to 2020-11-30"
)
assert result.exit_code == 0, result.exception
assert result.output == snapshot
def test_hvac_cancel(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
url = fixtures.inject_set_hvac_start(mocked_responses, result="cancel")
fixtures.inject_get_vehicle_details(mocked_responses, "zoe_40.1.json")
result = cli_runner.invoke(__main__.main, "hvac cancel")
assert result.exit_code == 0, result.exception
request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
assert request.kwargs["json"] == snapshot
assert result.output == snapshot
def test_sessions(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
fixtures.inject_get_hvac_sessions(
mocked_responses, start="20201101", end="20201130"
)
result = cli_runner.invoke(
__main__.main, "hvac sessions --from 2020-11-01 --to 2020-11-30"
)
assert result.exit_code == 0, result.exception
assert result.output == snapshot
def test_hvac_start_now(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
fixtures.inject_get_vehicle_details(mocked_responses, "zoe_40.1.json")
url = fixtures.inject_set_hvac_start(mocked_responses, "start")
result = cli_runner.invoke(__main__.main, "hvac start --temperature 25")
assert result.exit_code == 0, result.exception
request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
assert request.kwargs["json"] == snapshot
assert result.output == snapshot
def test_hvac_start_later(
mocked_responses: aioresponses, cli_runner: CliRunner, snapshot: SnapshotAssertion
) -> None:
"""It exits with a status code of zero."""
initialise_credential_store(include_account_id=True, include_vin=True)
fixtures.inject_get_vehicle_details(mocked_responses, "zoe_40.1.json")
url = fixtures.inject_set_hvac_start(mocked_responses, "start")
result = cli_runner.invoke(
__main__.main, "hvac start --temperature 24 --at '2020-12-25T11:50:00+02:00'"
)
assert result.exit_code == 0, result.exception
request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
assert request.kwargs["json"] == snapshot
assert result.output == snapshot
|