def test_eq(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 4.4) orig.notification_type = OhNotificationType.ITEM_COMMAND comp = copy.deepcopy(orig) self.assertTrue(orig == comp) self.assertTrue(orig is not None) self.assertTrue(orig != 1) comp = copy.deepcopy(orig) orig.channel = Channel.create(ChannelType.ITEM, 'channel2') self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.state_old = State.create(StateType.DECIMAL, 2.23) self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.state_new = State.create(StateType.DECIMAL, 2.23) self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.notification_type = OhNotificationType.ITEM_CHANGE self.assertTrue(orig != comp)
def test_dispatch_action(self): dispatcher = Dispatcher() checker = DispatchCheckerRule(dispatcher) channel = Channel.create(ChannelType.ITEM, 'dummyNumber') checker.subscribe_channel_actions(channel) action_in = Action() action_in.channel = channel action_in.state_new = State.create(StateType.DECIMAL, 3) action_in.notification_type = OhNotificationType.ITEM_COMMAND self.assertTrue(len(checker.notifications) == 0) something_processed = dispatcher.dispatch() self.assertFalse(something_processed) self.assertTrue(len(checker.notifications) == 0) dispatcher.push_action(action_in) something_processed = dispatcher.dispatch() self.assertTrue(something_processed) self.assertTrue(len(checker.notifications) == 1) action_out = checker.notifications[0] action_out.listener = None # compare! compare = (action_in == action_out) self.assertTrue(compare)
def test_should_be_published(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 2.2) orig.notification_type = OhNotificationType.ITEM_CHANGE comp = copy.deepcopy(orig) out = comp.should_be_published() self.assertFalse(out) comp = copy.deepcopy(orig) comp.notification_type = OhNotificationType.ITEM_COMMAND out = comp.should_be_published() self.assertTrue(out) comp = copy.deepcopy(orig) comp.state_new = State.create(StateType.DECIMAL, 2.3) out = comp.should_be_published() self.assertTrue(out) comp = copy.deepcopy(orig) comp.channel = Channel.create(ChannelType.CRON, 'channel') out = comp.should_be_published() self.assertTrue(out)
def test_is_valid(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 2.2) orig.notification_type = OhNotificationType.ITEM_CHANGE cron = Action() cron.channel = Channel.create(ChannelType.CRON, 'channel') cron.state_old = None cron.state_new = None cron.notification_type = None startup = Action.create_startup_action() comp = copy.deepcopy(orig) out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(orig) comp.state_old = None out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(cron) out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(orig) comp.channel.name = None out = comp.is_valid() self.assertFalse(out) comp = copy.deepcopy(orig) comp.state_new = None out = comp.is_valid() self.assertFalse(out) comp = copy.deepcopy(orig) comp.notification_type = None out = comp.is_valid() self.assertFalse(out) out = startup.is_valid() self.assertTrue(out)