Example #1
0
class MysqlTemperatureMessageHandlerTest(unittest.TestCase):
    @asyncio.coroutine
    def setUp(self):
        self.pool = yield from aiomysql.create_pool(host='127.0.0.1', port=3306,
                                                    user='******', password='******', db='test',
                                                    loop=asyncio.get_event_loop())

        with (yield from self.pool) as conn:
            cur = yield from conn.cursor()
            yield from cur.execute("drop table if EXISTS test_temp")
            yield from cur.close()

        redis_toolbox.now = lambda: datetime(2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc)
        self.message_handler = MysqlTemperatureMessageHandler(self.pool, 'test_temp')

    @asyncio.coroutine
    def tearDown(self):
        self.pool.close()
        yield from self.pool.wait_closed()

    @asyncio.coroutine
    def test_save_event_mysql(self):
        with (yield from self.pool) as conn:
            now = datetime(2012, 12, 13, 14, 0, 7, tzinfo=timezone.utc)

            yield from self.message_handler.handle({'date': now, 'temperature': 21.4})

            cursor = yield from conn.cursor()
            yield from cursor.execute("select timestamp, temperature from test_temp")
            rows = yield from cursor.fetchall()
            self.assertEqual((datetime(2012, 12, 13, 14, 0, 7), 21.4), rows[0])
            yield from cursor.close()
Example #2
0
    def setUp(self):
        self.pool = yield from aiomysql.create_pool(
            host='127.0.0.1',
            port=3306,
            user='******',
            password='******',
            db='test',
            loop=asyncio.get_event_loop())

        with (yield from self.pool) as conn:
            cur = yield from conn.cursor()
            yield from cur.execute("drop table if EXISTS test_temp")
            yield from cur.close()

        redis_toolbox.now = lambda: datetime(
            2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc)
        self.message_handler = MysqlTemperatureMessageHandler(
            self.pool, 'test_temp')
Example #3
0
    def setUp(self):
        self.pool = yield from aiomysql.create_pool(host='127.0.0.1', port=3306,
                                                    user='******', password='******', db='test',
                                                    loop=asyncio.get_event_loop())

        with (yield from self.pool) as conn:
            cur = yield from conn.cursor()
            yield from cur.execute("drop table if EXISTS test_temp")
            yield from cur.close()

        redis_toolbox.now = lambda: datetime(2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc)
        self.message_handler = MysqlTemperatureMessageHandler(self.pool, 'test_temp')
Example #4
0
def run_application(mysq_pool, config):
    # backend
    redis_pool_ = yield from create_redis_pool()
    daq_rfxcom = yield from create_rfxtrx433e(config['rfxcom'])
    current_cost = create_current_cost(redis_pool_, config['current_cost'])
    current_cost_recorder = AsyncRedisSubscriber(
        redis_pool_,
        MysqlCurrentCostMessageHandler(mysq_pool, average_period_minutes=10),
        CURRENT_COST_KEY).start()
    pool_temp_recorder = AsyncRedisSubscriber(
        redis_pool_,
        MysqlTemperatureMessageHandler(mysq_pool,
                                       'pool_temperature',
                                       average_period_minutes=10),
        RFXCOM_KEY).start()
Example #5
0
class MysqlTemperatureMessageHandlerTest(unittest.TestCase):
    @asyncio.coroutine
    def setUp(self):
        self.pool = yield from aiomysql.create_pool(
            host='127.0.0.1',
            port=3306,
            user='******',
            password='******',
            db='test',
            loop=asyncio.get_event_loop())

        with (yield from self.pool) as conn:
            cur = yield from conn.cursor()
            yield from cur.execute("drop table if EXISTS test_temp")
            yield from cur.close()

        redis_toolbox.now = lambda: datetime(
            2012, 12, 13, 14, 2, 0, tzinfo=timezone.utc)
        self.message_handler = MysqlTemperatureMessageHandler(
            self.pool, 'test_temp')

    @asyncio.coroutine
    def tearDown(self):
        self.pool.close()
        yield from self.pool.wait_closed()

    @asyncio.coroutine
    def test_save_event_mysql(self):
        with (yield from self.pool) as conn:
            now = datetime(2012, 12, 13, 14, 0, 7, tzinfo=timezone.utc)

            yield from self.message_handler.handle({
                'date': now,
                'temperature': 21.4
            })

            cursor = yield from conn.cursor()
            yield from cursor.execute(
                "select timestamp, temperature from test_temp")
            rows = yield from cursor.fetchall()
            self.assertEqual((datetime(2012, 12, 13, 14, 0, 7), 21.4), rows[0])
            yield from cursor.close()