def test_convert_url_to_regex(self):
     """
     Tests the ``DjangoDispatcher_convert_url_to_regex`` static method
     """
     urls = [('/api/resource', '^api/resource$'),
             ('', '^$'),
             ('/api/resource/<id>', '^api/resource/(?P<id>[^/]+)$'),
             ('/api/resource/<id>/<pk>', '^api/resource/(?P<id>[^/]+)/(?P<pk>[^/]+)$'),
             ('/api/resource/<id>/<id>', '^api/resource/(?P<id>[^/]+)/(?P<id>[^/]+)$'),
             ('/api/resource/<id>/another', '^api/resource/(?P<id>[^/]+)/another$')]
     for input_url, output in urls:
         self.assertEqual(DjangoDispatcher._convert_url_to_regex(input_url), output)
    def test_url_patterns(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)