Improve ecobee service schemas (#26955)

* Validate date and time in create vaction

Improve validation with utility functions.

* Improve validate ATTR_VACATION_NAME

* Add tests for ecobee.util functions

* Revise tests as standalone functions
This commit is contained in:
Mark Coombes authored and Martin Hjelmare committed 2019-09-28 11:32:22 +02:00
1 parent 1c72a246a0
commit 2dfdc5f6f8
3 files changed
+67 -6

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
"""Tests for the ecobee.util module."""
import pytest
import voluptuous as vol
from homeassistant.components.ecobee.util import ecobee_date, ecobee_time
def test_ecobee_date_with_valid_input():
"""Test that the date function returns the expected result."""
test_input = "2019-09-27"
assert ecobee_date(test_input) == test_input
def test_ecobee_date_with_invalid_input():
"""Test that the date function raises the expected exception."""
test_input = "20190927"
with pytest.raises(vol.Invalid):
ecobee_date(test_input)
def test_ecobee_time_with_valid_input():
"""Test that the time function returns the expected result."""
test_input = "20:55:15"
assert ecobee_time(test_input) == test_input
def test_ecobee_time_with_invalid_input():
"""Test that the time function raises the expected exception."""
test_input = "20:55"
with pytest.raises(vol.Invalid):
ecobee_time(test_input)