Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few unittests for MyT #82

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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