예제 #1
0
 def test_remove(self):
     a = object()
     router = RoutingBase()
     router.get_or_create_routes(a, ('a', ))
     router.remove_routes(('a', ))
     item = router.get_route_item('a')
     self.assertIsNone(item)
예제 #2
0
 def test_cache_clear(self):
     a = object()
     b = object()
     router = RoutingBase()
     router.get_or_create_routes(a, ('a', ))
     router.remove_routes(('a', ))
     # get_or_create_routes against the same key should return the new object, not a stale one
     item = router.get_or_create_routes(b, ('a', ))
     self.assertEqual(b, item)
예제 #3
0
    def test_route_item(self):
        a = object()
        router = RoutingBase()
        router.get_or_create_routes(a, ('a', ))
        self.assertEqual([a], router.list_all())

        # index a single item
        item = router.get_route_item('a')
        self.assertIn(a, item.values())
예제 #4
0
    def test_cache(self):
        a = object()
        router = RoutingBase()
        router.get_or_create_routes(a, ('a', ))
        self.assertEqual(router.list_all(), [a])

        # idempotent / cache
        b = object()
        item = router.get_or_create_routes(b, ('a', ))
        self.assertEqual(a, item)
    def test_same_items(self):
        a = 12345
        b = a
        router = RoutingBase()
        router.create_route(a, ('a', ))
        router.create_route(b, ('b', ))
        self.assertEqual([a], sorted(router.list_all()))

        # index a single item
        items = router.get_route_items('a')
        self.assertIn(a, items)

        # index a single item
        items = router.get_route_items('b')
        self.assertIn(b, items)
예제 #6
0
    def test_route_two_items(self):
        a = 12345
        b = 54321
        router = RoutingBase()
        router.get_or_create_routes(a, ('a', ))
        router.get_or_create_routes(b, ('b', ))
        self.assertEqual(sorted(router.list_all()), sorted([a, b]))

        # index a single item
        item = router.get_route_item('a')
        self.assertIn(a, item.values())

        # index a single item
        item = router.get_route_item('b')
        self.assertIn(b, item.values())
    def test_same_routes(self):
        a = 12345
        b = 54321
        router = RoutingBase()
        router.create_route(a, ('a', ))
        router.create_route(b, ('a', ))
        self.assertEqual(sorted([a, b]), sorted(router.list_all()))

        # index a single item
        items = router.get_route_items('a')
        self.assertIn(a, items)
        # explicit sort needed for Python2
        self.assertEqual(sorted([a, b]), sorted(items))
예제 #8
0
    def test_routing_conflict(self):
        a = object()
        b = object()
        router = RoutingBase()
        router.get_or_create_routes(a, ('a', ), sub_routes=('b', 'c'))

        # You can't route across partial existing routes
        # I think this is important, but finding it hard to justify why.
        # If you could, you'd be partially overwriting sub routes
        # If you can't, I suspect some legitimate use cases might fail e.g.
        #    - subscribe(channel=notifications, device_id=1, resource_path=4)            # ok
        #    - subscribe(channel=notifications, device_id=1, resource_path=4, time_gt=5) # ok
        #    - subscribe(channel=notifications, device_id=1, resource_path=4, time_gt=3) # fail
        # Maybe this is indicative that the right hand side needs to be a list (again?!?)
        with self.assertRaises(RoutingConflict):
            router.get_or_create_routes(b, ('a', ), sub_routes=('c', 'd'))
 def test_add_and_list_one_item(self):
     a = object()
     router = RoutingBase()
     router.create_route(a, ('a', ))
     self.assertEqual([a], router.list_all())
예제 #10
0
 def test_remove_item(self):
     a = object()
     router = RoutingBase()
     router.create_route(a, ('a', ))
     router.remove_routes(a, ('a', ))
     self.assertEqual([], router.get_route_items('a'))
예제 #11
0
 def test_missing_item(self):
     router = RoutingBase()
     self.assertEqual([], router.get_route_items('a'))
예제 #12
0
 def test_add_and_get_one_item(self):
     a = object()
     router = RoutingBase()
     router.create_route(a, ('a', ))
     self.assertIn(a, router.get_route_items('a'))
예제 #13
0
    def test_routing_extras(self):
        a = object()
        router = RoutingBase()
        router.get_or_create_routes(a, ('a', ), sub_routes=('b', 'c'))
        self.assertEqual(router.list_all(), [a])

        item = router.get_route_item('a')
        self.assertEqual({'b': a, 'c': a}, item)

        # additional top level route for 'a' with no sub_routes
        b = object()
        item = router.get_or_create_routes(b, ('a', ))
        self.assertEqual(b, item)

        # re-setting existing sub route for 'a' ... returns 'a'
        c = object()
        item = router.get_or_create_routes(c, ('a', ), ('b', ))
        self.assertEqual(a, item)

        # additional route for 'a' with no sub_routes ... should return 'b' from top-level cache
        d = object()
        item = router.get_or_create_routes(d, ('a', ))
        self.assertEqual(b, item)

        # our router now has only two unique items
        self.assertEqual(2, len(router.list_all()))
        self.assertEqual({a, b}, set(router.list_all()))

        # now if we look up an entry we see the items we need to iterate
        # to resolve the sub_routes (the router does not resolve them for us)
        item = router.get_route_item('a')
        self.assertEqual({a, b}, set(list(item.values())))