2019-02-10 20:45:46 +00:00
|
|
|
"""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
|
2019-02-10 20:45:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"
|
2019-02-10 20:45:46 +00:00
|
|
|
|
|
|
|
def test_nested(self):
|
|
|
|
"""Test dictionary encoding."""
|
2019-07-31 19:25:30 +00:00
|
|
|
assert victim().encode({"foo": "bar"}) == '{"foo": "bar"}'
|