Beispiel #1
0
    def test_get_costs_without_empty_and_full_hours(self):
        current_cost_service_without_discount_hours = CurrentCostDatabaseReader(
            self.pool)
        yield from self.message_handler.save({
            'date':
            datetime(2015, 5, 28, 12, 0, 0),
            'watt':
            1000,
            'minutes':
            60,
            'nb_data':
            120,
            'temperature':
            20.2
        })
        yield from self.message_handler.save({
            'date':
            datetime(2015, 5, 28, 7, 0, 0),
            'watt':
            1000,
            'minutes':
            60,
            'nb_data':
            120,
            'temperature':
            20.2
        })

        data = yield from current_cost_service_without_discount_hours.get_costs(
            since=datetime(2015, 5, 28, tzinfo=get_localzone()))

        self.assertEqual(1, len(data))
        self.assertEqual((datetime(2015, 5, 28), (Decimal(2.0), Decimal(0.0))),
                         data[0])
Beispiel #2
0
    def setUp(self):
        self.pool = yield from aiomysql.create_pool(host='127.0.0.1',
                                                    port=3306,
                                                    user='******',
                                                    password='******',
                                                    db='test',
                                                    loop=self.loop)

        self.message_handler = MysqlCurrentCostMessageHandler(self.pool)
        self.current_cost_service = CurrentCostDatabaseReader(
            self.pool, time(8, 0), time(22, 0))
        current_cost_mysql_service.now = lambda: datetime(
            2015, 6, 1, 12, 0, 0, tzinfo=get_localzone())
        with (yield from self.pool) as conn:
            cur = yield from conn.cursor()
            yield from cur.execute("truncate current_cost")