Skip to content

Commit 047728b

Browse files
committed
Add auth tests
1 parent addf674 commit 047728b

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@
55
from tests.common import load_fixture
66

77

8+
@pytest.fixture(name="test_charger_auth")
9+
def test_charger_auth(status_mock, config_mock):
10+
"""Load the charger data."""
11+
return openevsehttp.OpenEVSE(
12+
"openevse.test.tld", user="testuser", pwd="fakepassword"
13+
)
14+
15+
16+
@pytest.fixture(name="test_charger_auth_err")
17+
def test_charger_auth_err(status_mock_err, config_mock_err):
18+
"""Load the charger data."""
19+
with pytest.raises(openevsehttp.AuthenticationError):
20+
return openevsehttp.OpenEVSE(
21+
"openevse.test.tld", user="testuser", pwd="fakepassword"
22+
)
23+
24+
25+
@pytest.fixture(name="status_mock_err")
26+
def mock_status_err(requests_mock):
27+
"""Mock the status reply."""
28+
requests_mock.get(
29+
"http://openevse.test.tld/status",
30+
status_code=401,
31+
)
32+
33+
34+
@pytest.fixture(name="config_mock_err")
35+
def mock_config_err(requests_mock):
36+
"""Mock the config reply."""
37+
requests_mock.get(
38+
"http://openevse.test.tld/config",
39+
status_code=401,
40+
)
41+
42+
843
@pytest.fixture(name="test_charger")
944
def test_charger(status_mock, config_mock):
1045
"""Load the charger data."""

tests/test_init.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import pytest
22

33

4+
def test_get_status_auth(test_charger_auth):
5+
"""Test v4 Status reply"""
6+
status = test_charger_auth.status
7+
assert status == "sleeping"
8+
9+
10+
def test_get_status_auth_err(test_charger_auth_err):
11+
"""Test v4 Status reply"""
12+
assert test_charger_auth_err is None
13+
14+
415
@pytest.mark.parametrize(
516
"fixture, expected",
617
[("test_charger", "sleeping"), ("test_charger_v2", "not connected")],

0 commit comments

Comments
 (0)