Browse Source

Routes: CELERY_ROUTES can be dict, which also has __iter__

Need to test for instances of (list, tuple) instead of iterables.
Ask Solem 15 years ago
parent
commit
d9d3c70c6e
2 changed files with 8 additions and 2 deletions
  1. 1 1
      celery/routes.py
  2. 7 1
      celery/tests/test_routes.py

+ 1 - 1
celery/routes.py

@@ -80,6 +80,6 @@ def prepare(routes):
             return mpromise(instantiate, route)
         return route
 
-    if not hasattr(routes, "__iter__"):
+    if not isinstance(routes, (list, tuple)):
         routes = (routes, )
     return map(expand_route, routes)

+ 7 - 1
celery/tests/test_routes.py

@@ -3,6 +3,7 @@ import unittest2 as unittest
 
 from celery import conf
 from celery import routes
+from celery.utils import maybe_promise
 from celery.utils.functional import wraps
 from celery.exceptions import QueueNotFound
 
@@ -96,7 +97,12 @@ class test_prepare(unittest.TestCase):
                   o]
         p = routes.prepare(R)
         self.assertIsInstance(p[0], routes.MapRoute)
-        self.assertIsInstance(p[1], LocalCache)
+        self.assertIsInstance(maybe_promise(p[1]), LocalCache)
         self.assertIs(p[2], o)
 
         self.assertEqual(routes.prepare(o), [o])
+
+    def test_prepare_item_is_dict(self):
+        R = {"foo": "bar"}
+        p = routes.prepare(R)
+        self.assertIsInstance(p[0], routes.MapRoute)