core/tests/components/google_pubsub/test_pubsub.py

22 lines
679 B
Python
Raw Normal View History

"""The tests for the Google Pub/Sub component."""
from datetime import datetime
2019-07-31 19:25:30 +00:00
from homeassistant.components.google_pubsub import DateTimeJSONEncoder as victim
class TestDateTimeJSONEncoder(object):
"""Bundle for DateTimeJSONEncoder tests."""
def test_datetime(self):
"""Test datetime encoding."""
time = datetime(2019, 1, 13, 12, 30, 5)
assert victim().encode(time) == '"2019-01-13T12:30:05"'
def test_no_datetime(self):
"""Test integer encoding."""
2019-07-31 19:25:30 +00:00
assert victim().encode(42) == "42"
def test_nested(self):
"""Test dictionary encoding."""
2019-07-31 19:25:30 +00:00
assert victim().encode({"foo": "bar"}) == '{"foo": "bar"}'