def get_events_by_task(task_id): data_source = DataSource.get_instance() return data_source.query_for_list(Event, Event.__EVENTS_BY_TASK, task_id)
import unittest from batch.domain import Pin, Event, Task from batch.dateutils import cast_time_to_datetime, get_difference_in_seconds from datetime import datetime from batch.workers import TaskManager from batch.dao import DataSource DataSource.set_sql_type("sqLite") class PinTest(unittest.TestCase): def get_pin_test(self): pin = Pin.get_pin(1) self.assertIsNotNone(pin) self.assertEqual(1, pin.id) def turn_off_pin_test(self): pin = Pin.get_pin(1) pin.turn_off() pin1 = Pin.get_pin(1) self.assertFalse(pin1.output) def turn_on_pin_test(self): pin = Pin.get_pin(1) pin.turn_on() pin1 = Pin.get_pin(1) self.assertTrue(pin1.output) def load_pins_test(self): pins = Pin.load() self.assertTrue(len(pins) > 0)
def load(): data_source = DataSource.get_instance() return data_source.query_for_list(Event, Event.__ALL)
def get_event(event_id): data_source = DataSource.get_instance() return data_source.query_for_object(Event, Event.__DETAIL, event_id)
def get_pin(pin_id): data_source = DataSource.get_instance() pin = data_source.query_for_object(Pin, Pin.__DETAIL, pin_id) return pin
def load(): data_source = DataSource.get_instance() return data_source.query_for_list(domain_type=Pin, query=Pin.__ALL)
def __update(self): data_source = DataSource.get_instance() data_source.execute(Pin.__UPDATE, [1 if self.output else 0, self.id])
def get_task(task_id): data_source = DataSource.get_instance() task = data_source.query_for_object(Task, Task.__DETAIL, task_id) return task
def load(): data_source = DataSource.get_instance() return data_source.query_for_list(Task, Task.__ALL)