File: test_session.py

package info (click to toggle)
python-renault-api 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,696 kB
  • sloc: python: 7,804; makefile: 2
file content (119 lines) | stat: -rw-r--r-- 3,748 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
116
117
118
119
"""Test cases for the __main__ module."""

import os

from click.testing import CliRunner
from syrupy.assertion import SnapshotAssertion

from tests.const import TEST_ACCOUNT_ID
from tests.const import TEST_LOCALE
from tests.const import TEST_VIN

from renault_api.cli import __main__
from renault_api.cli.renault_settings import CONF_ACCOUNT_ID
from renault_api.cli.renault_settings import CONF_VIN
from renault_api.cli.renault_settings import CREDENTIAL_PATH
from renault_api.const import CONF_GIGYA_APIKEY
from renault_api.const import CONF_GIGYA_URL
from renault_api.const import CONF_KAMEREON_APIKEY
from renault_api.const import CONF_KAMEREON_URL
from renault_api.const import CONF_LOCALE
from renault_api.credential_store import FileCredentialStore


def test_set_locale(cli_runner: CliRunner) -> None:
    """Test set locale."""
    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_LOCALE,
        CONF_GIGYA_APIKEY,
        CONF_GIGYA_URL,
        CONF_KAMEREON_APIKEY,
        CONF_KAMEREON_URL,
    ]:
        assert key not in credential_store

    result = cli_runner.invoke(__main__.main, f"set --locale {TEST_LOCALE}")
    assert result.exit_code == 0

    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_LOCALE,
        CONF_GIGYA_APIKEY,
        CONF_GIGYA_URL,
        CONF_KAMEREON_APIKEY,
        CONF_KAMEREON_URL,
    ]:
        assert key in credential_store

    assert "" == result.output


def test_set_account(cli_runner: CliRunner) -> None:
    """Test set locale."""
    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_ACCOUNT_ID,
    ]:
        assert key not in credential_store

    result = cli_runner.invoke(__main__.main, f"set --account {TEST_ACCOUNT_ID}")
    assert result.exit_code == 0

    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_ACCOUNT_ID,
    ]:
        assert key in credential_store

    assert "" == result.output


def test_set_vin(cli_runner: CliRunner) -> None:
    """Test set vin."""
    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_VIN,
    ]:
        assert key not in credential_store

    result = cli_runner.invoke(__main__.main, f"set --vin {TEST_VIN}")
    assert result.exit_code == 0

    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    for key in [
        CONF_VIN,
    ]:
        assert key in credential_store

    assert "" == result.output


def test_get_keys_succeeds(cli_runner: CliRunner, snapshot: SnapshotAssertion) -> None:
    """It exits with a status code of zero."""
    result = cli_runner.invoke(__main__.main, f"set --locale {TEST_LOCALE}")
    assert result.exit_code == 0

    result = cli_runner.invoke(__main__.main, "settings")
    assert result.exit_code == 0

    assert result.output == snapshot


def test_reset(cli_runner: CliRunner) -> None:
    """Test set vin."""
    assert not os.path.exists(os.path.expanduser(CREDENTIAL_PATH))

    result = cli_runner.invoke(__main__.main, f"set --locale {TEST_LOCALE}")
    assert result.exit_code == 0
    assert os.path.exists(os.path.expanduser(CREDENTIAL_PATH))

    # Reset a first time - file should get deleted
    result = cli_runner.invoke(__main__.main, "reset")
    assert result.exit_code == 0
    assert not os.path.exists(os.path.expanduser(CREDENTIAL_PATH))

    # Reset a second time - make sure it doesn't error
    result = cli_runner.invoke(__main__.main, "reset")
    assert result.exit_code == 0
    assert not os.path.exists(os.path.expanduser(CREDENTIAL_PATH))