def test_url_patterns_property(self):
        """
        Test to ensure that the url_patterns propery
        appropriately gets the django patterns object
        """
        d = DjangoDispatcher()
        self.assertIsInstance(d.url_patterns, list)
        self.assertEqual(len(d.url_patterns), 1)

        def fake():
            pass
        d.register_route('fake', endpoint_func=fake, route='route', methods=['GET'])
        route = DjangoDispatcher._convert_url_to_regex('route')
        self.assertIsInstance(d.url_patterns, list)
        regexes = [p._regex for p in d.url_patterns]
        self.assertEqual(len(regexes), 2)
        self.assertIn(route, regexes)
        self.assertIn('^$', regexes)
 def test_register_route(self):
     """
     Tests the register_route method on the DjangoDispatcher instance
     """
     d = DjangoDispatcher()
     def fake():
         pass
     d.register_route('fake', endpoint_func=fake, route='route', methods=['GET'])
     route = DjangoDispatcher._convert_url_to_regex('route')
     self.assertIn(route, d.url_map)
     old_router = d.url_map[route]
     self.assertIsInstance(d.url_map[route], MethodRouter)
     def fake2():
         pass
     d.register_route('fake2', endpoint_func=fake2, route='route', methods=['POST'])
     self.assertEqual(old_router, d.url_map[route])
     self.assertEqual(len(old_router.method_map), 2)
Exemple #3
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from django_ripozo.dispatcher import DjangoDispatcher

from ripozo.adapters import SirenAdapter, HalAdapter

from testapp.resources import HelloResource, HelloWorldIdResource


dispatcher = DjangoDispatcher(base_url='/api')
dispatcher.register_resources(HelloResource, HelloWorldIdResource)
dispatcher.register_adapters(SirenAdapter, HalAdapter)

urlpatterns = dispatcher.url_patterns