Skip to content
Closed
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
34 changes: 15 additions & 19 deletions tests/components/tankerkoenig/test_tankerkoenig_validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""The tests for the custom tankerkoenig validators."""
import unittest
import uuid

import pytest
Expand All @@ -8,25 +7,22 @@
from homeassistant.components.tankerkoenig import uuid4_string


class TestUUID4StringValidator(unittest.TestCase):
"""Test the UUID4 string custom validator."""

def test_uuid4_string(caplog):
"""Test string uuid validation."""
schema = vol.Schema(uuid4_string)

for value in ["Not a hex string", "0", 0]:
with pytest.raises(vol.Invalid):
schema(value)
def test_uuid4_string(caplog):
"""Test string uuid validation."""
schema = vol.Schema(uuid4_string)

for value in ["Not a hex string", "0", 0]:
with pytest.raises(vol.Invalid):
# the third block should start with 4
schema("a03d31b2-2eee-2acc-bb90-eec40be6ed23")
schema(value)

with pytest.raises(vol.Invalid):
# the fourth block should start with 8-a
schema("a03d31b2-2eee-4acc-1b90-eec40be6ed23")
with pytest.raises(vol.Invalid):
# the third block should start with 4
schema("a03d31b2-2eee-2acc-bb90-eec40be6ed23")

with pytest.raises(vol.Invalid):
# the fourth block should start with 8-a
schema("a03d31b2-2eee-4acc-1b90-eec40be6ed23")

_str = str(uuid.uuid4())
assert schema(_str) == _str
assert schema(_str.upper()) == _str
_str = str(uuid.uuid4())
assert schema(_str) == _str
assert schema(_str.upper()) == _str