Use standardised datetime format

This commit is contained in:
Paulus Schoutsen committed 2016-04-16 01:46:50 -07:00
1 parent e7520ef401
commit 68d92c3196
29 files changed
+154 -162

No files matched your search

+11 -11
View File
@@ -34,7 +34,7 @@ class TestAutomationSun(unittest.TestCase):
def test_sunset_trigger(self):
"""Test the sunset trigger."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_SETTING: '2015-09-16T02:00:00Z',
})
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
@@ -61,7 +61,7 @@ class TestAutomationSun(unittest.TestCase):
def test_sunrise_trigger(self):
"""Test the sunrise trigger."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
@@ -88,7 +88,7 @@ class TestAutomationSun(unittest.TestCase):
def test_sunset_trigger_with_offset(self):
"""Test the sunset trigger with offset."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_SETTING: '02:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_SETTING: '2015-09-16T02:00:00Z',
})
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
@@ -116,7 +116,7 @@ class TestAutomationSun(unittest.TestCase):
def test_sunrise_trigger_with_offset(self):
"""Test the runrise trigger with offset."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
@@ -144,7 +144,7 @@ class TestAutomationSun(unittest.TestCase):
def test_if_action_before(self):
"""Test if action was before."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
@@ -180,7 +180,7 @@ class TestAutomationSun(unittest.TestCase):
def test_if_action_after(self):
"""Test if action was after."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
@@ -216,7 +216,7 @@ class TestAutomationSun(unittest.TestCase):
def test_if_action_before_with_offset(self):
"""Test if action was before offset."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
@@ -253,7 +253,7 @@ class TestAutomationSun(unittest.TestCase):
def test_if_action_after_with_offset(self):
"""Test if action was after offset."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '14:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
@@ -290,8 +290,8 @@ class TestAutomationSun(unittest.TestCase):
def test_if_action_before_and_after_during(self):
"""Test if action was before and after during."""
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_RISING: '10:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_SETTING: '15:00:00 16-09-2015',
sun.STATE_ATTR_NEXT_RISING: '2015-09-16T10:00:00Z',
sun.STATE_ATTR_NEXT_SETTING: '2015-09-16T15:00:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
@@ -337,7 +337,7 @@ class TestAutomationSun(unittest.TestCase):
import pytz
self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
sun.STATE_ATTR_NEXT_SETTING: '17:30:00 16-09-2015',
sun.STATE_ATTR_NEXT_SETTING: '2015-09-16T17:30:00Z',
})
_setup_component(self.hass, automation.DOMAIN, {
+6 -2
View File
@@ -2,6 +2,7 @@
import os
import unittest
import tempfile
from unittest.mock import patch
import homeassistant.components.notify as notify
from homeassistant.components.notify import (
@@ -31,8 +32,11 @@ class TestNotifyFile(unittest.TestCase):
}
}))
def test_notify_file(self):
@patch('homeassistant.util.dt.utcnow')
def test_notify_file(self, mock_utcnow):
"""Test the notify file output."""
mock_utcnow.return_value = dt_util.as_utc(dt_util.now())
with tempfile.TemporaryDirectory() as tempdirname:
filename = os.path.join(tempdirname, 'notify.txt')
message = 'one, two, testing, testing'
@@ -46,7 +50,7 @@ class TestNotifyFile(unittest.TestCase):
}))
title = '{} notifications (Log started: {})\n{}\n'.format(
ATTR_TITLE_DEFAULT,
dt_util.strip_microseconds(dt_util.utcnow()),
dt_util.utcnow().isoformat(),
'-' * 80)
self.hass.services.call('notify', 'test', {'message': message},
+1 -1
View File
@@ -68,7 +68,7 @@ class TestComponentHistory(unittest.TestCase):
"""Test humanify filter too frequent sensor values."""
entity_id = 'sensor.bla'
pointA = dt_util.strip_microseconds(dt_util.utcnow().replace(minute=2))
pointA = dt_util.utcnow().replace(minute=2)
pointB = pointA.replace(minute=5)
pointC = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
+6 -6
View File
@@ -66,13 +66,13 @@ class TestMqttEventStream(unittest.TestCase):
mock_sub.assert_called_with(self.hass, sub_topic, ANY)
@patch('homeassistant.components.mqtt.publish')
@patch('homeassistant.core.dt_util.datetime_to_str')
def test_state_changed_event_sends_message(self, mock_datetime, mock_pub):
@patch('homeassistant.core.dt_util.utcnow')
def test_state_changed_event_sends_message(self, mock_utcnow, mock_pub):
""""Test the sending of a new message if event changed."""
now = '00:19:19 11-01-2016'
now = dt_util.as_utc(dt_util.now())
e_id = 'fake.entity'
pub_topic = 'bar'
mock_datetime.return_value = now
mock_utcnow.return_value = now
# Add the eventstream component for publishing events
self.assertTrue(self.add_eventstream(pub_topic=pub_topic))
@@ -97,11 +97,11 @@ class TestMqttEventStream(unittest.TestCase):
event = {}
event['event_type'] = EVENT_STATE_CHANGED
new_state = {
"last_updated": now,
"last_updated": now.isoformat(),
"state": "on",
"entity_id": e_id,
"attributes": {},
"last_changed": now
"last_changed": now.isoformat()
}
event['event_data'] = {"new_state": new_state, "entity_id": e_id}
+13 -1
View File
@@ -63,4 +63,16 @@ class TestRecorder(unittest.TestCase):
db_events = recorder.query_events(
'SELECT * FROM events WHERE event_type = ?', (event_type, ))
self.assertEqual(events, db_events)
assert len(events) == 1
assert len(db_events) == 1
event = events[0]
db_event = db_events[0]
assert event.event_type == db_event.event_type
assert event.data == db_event.data
assert event.origin == db_event.origin
# Recorder uses SQLite and stores datetimes as integer unix timestamps
assert event.time_fired.replace(microsecond=0) == \
db_event.time_fired.replace(microsecond=0)