Exemplo n.º 1
0
 def test_create_packed(self):
     packed = self.target.packed_object()
     result = EventSubscription.create_from_packed(packed)
     self.assertEqual(result.event_filters, {
         'k0': set(['v', '0']),
         'k1': set(['v', '1'])
     })
    def test_EventSubscriptionMap_set_subscription(self):
        self.target = self.target.EventSubscriptionMap()
        self.value = EventSubscription("EventSubscription",
                                       {"key01": ["value01", "value02"]})

        self.target.set_subscription(self.value)

        self.assertEqual(
            self.target._EventSubscriptionMap__subscriptions,
            {"EventSubscription": set(["key01:value01", "key01:value02"])})
        self.assertEqual(
            self.target._EventSubscriptionMap__subscription_map, {
                "key01:value01": set(["EventSubscription"]),
                "key01:value02": set(["EventSubscription"])
            })
Exemplo n.º 3
0
    def __init__(self, arg1, arg2, arg3=None):
        if arg3 is None:
            object_id = arg1
            dispatcher = arg2
        else:
            object_id = arg1
            baseUrl = arg2
            dispatcher = arg3
        self._object_property = ObjectProperty(self.__class__.__name__,
                                               object_id)
        self._object_property.set_state(ObjectProperty.State.INITIALIZING)
        self.__set_description()
        self.__set_connection_types()
        self._object_settings = {}

        self.dispatcher = dispatcher
        if self.dispatcher is None:
            return
        self.dispatcher.add_local_object(self)
        self._event_subscription = EventSubscription(object_id)
        self.__parser = RequestParser()
        self.__add_rules()
    def test_subscribe_event(self):
        # TODO: this requires some work...
        with patch("org.o3project.odenos.remoteobject.transport." +
                   "remote_message_transport.RemoteMessageTransport." +
                   "send_request_message") as mock_send_request_message:
            mock_send_request_message.return_value = "send_request_message"
            subscription_map =\
                self.target._MessageDispatcher__subscription_map
            self.value = EventSubscription("EventSubscription01",
                                           {"key01": ["value01"]})
            subscription_map._EventSubscriptionMap__subscriptions =\
                {"EventSubscription01": set(["key01:value01",
                                             "key01:value02"]),
                 "EventSubscription": set(["key01:value01",
                                           "key01:value02"])}
            self.target._EventSubscriptionMap__subscription_map =\
                {"key01:value01": set(["EventSubscription01",
                                       "EventSubscription02"]),
                 "key01:value02": set(["EventSubscription01",
                                       "EventSubscription02"])}

            self.result = self.target.subscribe_event(self.value)
        self.assertEqual(self.result, "send_request_message")
Exemplo n.º 5
0
 def test_create_packed(self):
     packed = self.target.packed_object()
     result = EventSubscription.create_from_packed(packed)
     self.assertEqual(result.event_filters,
                      {'k0': set(['v', '0']),
                       'k1': set(['v', '1'])})
Exemplo n.º 6
0
 def setUp(self):
     self.target = EventSubscription("subscriber_id",
                                     {'k0': 'v0', 'k1': 'v1'})
Exemplo n.º 7
0
class EventSubscriptionTest(unittest.TestCase):
    def setUp(self):
        self.target = EventSubscription("subscriber_id",
                                        {'k0': 'v0', 'k1': 'v1'})

    def test_constructor_with_default_arg(self):
        empty = EventSubscription()
        self.assertIsNone(empty.subscriber_id)
        self.assertEqual(len(empty.event_filters), 0)

    def test_constructor_without_eventfilters(self):
        es = EventSubscription("subscriber_id")
        self.assertEqual(es.subscriber_id, "subscriber_id")
        self.assertEqual(len(es.event_filters), 0)

    def test_constructor(self):
        self.assertEqual(self.target.subscriber_id, "subscriber_id")
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1'])})

    def test_clear_filter(self):
        self.target.clear_filter()
        self.assertEqual(len(self.target.event_filters), 0)

    def test_add_filter(self):
        self.target.add_filter("publisher_id", "event_id")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1']),
                          'publisher_id': set(['event_id'])})

    def test_add_filter_with_existing_event_id(self):
        self.target.add_filter("publisher_id", "old_event_id")
        self.target.add_filter("publisher_id", "new_event_id")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1']),
                          'publisher_id': set(['old_event_id',
                                               'new_event_id'])})

    def test_remove_filter(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_filter("publisher_id", "event_id1")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1']),
                          'publisher_id': set(['event_id2'])})

    def test_remove_filter_with_not_existing_publisher_id(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_filter("publisher_id_x", "event_id1")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1']),
                          'publisher_id': set(['event_id1', 'event_id2'])})

    def test_remove_publisher_id(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_publisher_id("publisher_id")
        self.assertEqual(len(self.target.event_filters), 2)
        self.assertEqual(self.target.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1'])})

    def test_create_packed(self):
        packed = self.target.packed_object()
        result = EventSubscription.create_from_packed(packed)
        self.assertEqual(result.event_filters,
                         {'k0': set(['v', '0']),
                          'k1': set(['v', '1'])})

    def test_packed_object(self):
        result = self.target.packed_object()
        self.assertEqual(result, {"subscriber_id": "subscriber_id",
                                  "event_filters": {'k0': ['0', 'v'],
                                                    'k1': ['1', 'v']}})
Exemplo n.º 8
0
 def test_constructor_without_eventfilters(self):
     es = EventSubscription("subscriber_id")
     self.assertEqual(es.subscriber_id, "subscriber_id")
     self.assertEqual(len(es.event_filters), 0)
Exemplo n.º 9
0
 def test_constructor_with_default_arg(self):
     empty = EventSubscription()  # without arguments
     self.assertIsNone(empty.subscriber_id)
     self.assertEqual(len(empty.event_filters), 0)
Exemplo n.º 10
0
 def setUp(self):
     self.target = EventSubscription("subscriber_id", {
         'k0': 'v0',
         'k1': 'v1'
     })
Exemplo n.º 11
0
class EventSubscriptionTest(unittest.TestCase):
    def setUp(self):
        self.target = EventSubscription("subscriber_id", {
            'k0': 'v0',
            'k1': 'v1'
        })

    def test_constructor_with_default_arg(self):
        empty = EventSubscription()  # without arguments
        self.assertIsNone(empty.subscriber_id)
        self.assertEqual(len(empty.event_filters), 0)

    def test_constructor_without_eventfilters(self):
        es = EventSubscription("subscriber_id")
        self.assertEqual(es.subscriber_id, "subscriber_id")
        self.assertEqual(len(es.event_filters), 0)

    def test_constructor(self):
        self.assertEqual(self.target.subscriber_id, "subscriber_id")
        self.assertEqual(self.target.event_filters, {
            'k0': set(['v', '0']),
            'k1': set(['v', '1'])
        })

    def test_clear_filter(self):
        self.target.event_filters.clear()
        self.assertEqual(len(self.target.event_filters), 0)

    def test_add_filter(self):
        self.target.add_filter("publisher_id", "event_id")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(
            self.target.event_filters, {
                'k0': set(['v', '0']),
                'k1': set(['v', '1']),
                'publisher_id': set(['event_id'])
            })

    def test_add_filter_with_existing_event_id(self):
        self.target.add_filter("publisher_id", "old_event_id")
        self.target.add_filter("publisher_id", "new_event_id")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(
            self.target.event_filters, {
                'k0': set(['v', '0']),
                'k1': set(['v', '1']),
                'publisher_id': set(['old_event_id', 'new_event_id'])
            })

    def test_remove_filter(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_filter("publisher_id", "event_id1")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(
            self.target.event_filters, {
                'k0': set(['v', '0']),
                'k1': set(['v', '1']),
                'publisher_id': set(['event_id2'])
            })

    def test_remove_filter_with_not_existing_publisher_id(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_filter("publisher_id_x", "event_id1")
        self.assertEqual(len(self.target.event_filters), 3)
        self.assertEqual(
            self.target.event_filters, {
                'k0': set(['v', '0']),
                'k1': set(['v', '1']),
                'publisher_id': set(['event_id1', 'event_id2'])
            })

    def test_remove_publisher_id(self):
        self.target.add_filter("publisher_id", "event_id1")
        self.target.add_filter("publisher_id", "event_id2")
        self.target.remove_publisher_id("publisher_id")
        self.assertEqual(len(self.target.event_filters), 2)
        self.assertEqual(self.target.event_filters, {
            'k0': set(['v', '0']),
            'k1': set(['v', '1'])
        })

    def test_create_packed(self):
        packed = self.target.packed_object()
        result = EventSubscription.create_from_packed(packed)
        self.assertEqual(result.event_filters, {
            'k0': set(['v', '0']),
            'k1': set(['v', '1'])
        })

    def test_packed_object(self):
        result = self.target.packed_object()
        self.assertEqual(
            result, {
                "subscriber_id": "subscriber_id",
                "event_filters": {
                    'k0': ['0', 'v'],
                    'k1': ['1', 'v']
                }
            })