class RedisAverageMessageHandlerTest(WithRedis): @asyncio.coroutine def setUp(self): yield from super().setUp() redis_toolbox.now = lambda: datetime(2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc) self.message_handler = RedisAverageMessageHandler(self.connection, ['watt', 'temperature']) @asyncio.coroutine def test_save_event_redis_function(self): now = datetime(2012, 12, 13, 14, 0, 7, tzinfo=timezone.utc) yield from self.message_handler.handle({'date': now, 'watt': 305.0, 'temperature': 21.4}) ttl = yield from self.connection.ttl('current_cost_2012-12-13') self.assertTrue(int(ttl) > 0) self.assertTrue(int(ttl) <= 5 * 24 * 3600) event = yield from self.connection.lpop('current_cost_2012-12-13') self.assertDictEqual( {'date': now, 'watt': 305, 'temperature': 21.4, 'nb_data': 1, 'minutes': 0}, loads(event, object_hook=with_iso8601_date)) @asyncio.coroutine def test_save_event_redis_function_no_ttl_if_not_first_element(self): yield from self.connection.lpush('current_cost_2012-12-13', ['not used']) self.message_handler.handle(dumps({'date': (redis_toolbox.now().isoformat()), 'watt': 305, 'temperature': 21.4})) ttl = yield from self.connection.ttl('current_cost_2012-12-13') self.assertEqual(-1, int(ttl))
class RedisAverageMessageHandlerTest(WithRedis): @asyncio.coroutine def setUp(self): yield from super().setUp() redis_toolbox.now = lambda: datetime( 2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc) self.message_handler = RedisAverageMessageHandler( self.connection, ['watt', 'temperature']) @asyncio.coroutine def test_save_event_redis_function(self): now = datetime(2012, 12, 13, 14, 0, 7, tzinfo=timezone.utc) yield from self.message_handler.handle({ 'date': now, 'watt': 305.0, 'temperature': 21.4 }) ttl = yield from self.connection.ttl('current_cost_2012-12-13') self.assertTrue(int(ttl) > 0) self.assertTrue(int(ttl) <= 5 * 24 * 3600) event = yield from self.connection.lpop('current_cost_2012-12-13') self.assertDictEqual( { 'date': now, 'watt': 305, 'temperature': 21.4, 'nb_data': 1, 'minutes': 0 }, loads(event, object_hook=with_iso8601_date)) @asyncio.coroutine def test_save_event_redis_function_no_ttl_if_not_first_element(self): yield from self.connection.lpush('current_cost_2012-12-13', ['not used']) self.message_handler.handle( dumps({ 'date': (redis_toolbox.now().isoformat()), 'watt': 305, 'temperature': 21.4 })) ttl = yield from self.connection.ttl('current_cost_2012-12-13') self.assertEqual(-1, int(ttl))
def setUp(self): yield from super().setUp() redis_toolbox.now = lambda: datetime( 2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc) self.message_handler = RedisAverageMessageHandler( self.connection, ['watt', 'temperature'])
def setUp(self): yield from super().setUp() redis_toolbox.now = lambda: datetime(2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc) self.message_handler = RedisAverageMessageHandler(self.connection, ['watt', 'temperature'])