Skip to content

Commit

Permalink
Add a few unittests for MyT (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
joro75 authored Oct 12, 2021
1 parent 9ee0002 commit 437267a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mytoyota/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
) -> None:
"""Toyota API"""

if "@" not in username:
if username is None or "@" not in username:
raise ToyotaInvalidUsername

if region not in SUPPORTED_REGIONS:
Expand Down
83 changes: 83 additions & 0 deletions tests/test_myt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""pytest tests for mytoyota.client.MyT"""

import pytest

from mytoyota.client import MyT
from mytoyota.exceptions import (
ToyotaInvalidUsername,
ToyotaLocaleNotValid,
ToyotaRegionNotSupported,
)

# pylint: disable=no-self-use


class TestMyT:
"""pytest functions to test MyT"""

def test_myt(self):
"""Test an error free initialisation of MyT"""
myt = MyT(
username="[email protected]",
password="xxxxx",
locale="en-gb",
region="europe",
)
assert myt is not None
assert myt.api is not None

@pytest.mark.parametrize(
"username",
[None, "", "_invalid_"],
)
def test_myt_invalid_username(self, username):
"""Test an invalid username in MyT"""
with pytest.raises(ToyotaInvalidUsername):
_ = MyT(
username=username, password="xxxxx", locale="en-gb", region="europe"
)

@pytest.mark.parametrize(
"locale",
[
None,
"",
"invalid-locale",
"da-en-dk-us",
],
)
def test_myt_invalid_locale(self, locale):
"""Test an invalid locale in MyT"""
with pytest.raises(ToyotaLocaleNotValid):
_ = MyT(
username="[email protected]",
password="xxxxx",
locale=locale,
region="europe",
)

@pytest.mark.parametrize(
"region",
[
None,
"",
"antartica",
"mars",
],
)
def test_myt_unsupported_region(self, region):
"""Test an invalid region in MyT"""
with pytest.raises(ToyotaRegionNotSupported):
_ = MyT(
username="[email protected]",
password="xxxxx",
locale="en-gb",
region=region,
)

def test_get_supported_regions(self):
"""Test the supported regions"""
regions = MyT.get_supported_regions()
assert regions is not None
assert len(regions) > 0
assert "europe" in regions

0 comments on commit 437267a

Please sign in to comment.