mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	For a long time, rest_dispatch has had this hack where we have to create a copy of it in each views file using it, in order to directly access the globals list in that file. This removes that hack, instead making rest_dispatch just use Django's import_string to access the target method to use. [tweaked and reorganized from acrefoot's original branch in various ways by tabbott]
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding: utf-8 -*-
 | 
						|
from __future__ import absolute_import
 | 
						|
from __future__ import print_function
 | 
						|
 | 
						|
import django.core.urlresolvers
 | 
						|
from django.test import TestCase
 | 
						|
import importlib
 | 
						|
from zproject import urls
 | 
						|
 | 
						|
class URLResolutionTest(TestCase):
 | 
						|
    def check_function_exists(self, module_name, view):
 | 
						|
        # type: (str, str) -> None
 | 
						|
        module = importlib.import_module(module_name)
 | 
						|
        self.assertTrue(hasattr(module, view), "View %s.%s does not exist" % (module_name, view))
 | 
						|
 | 
						|
    # Tests that all views in urls.v1_api_and_json_patterns exist
 | 
						|
    def test_rest_api_url_resolution(self):
 | 
						|
        # type: () -> None
 | 
						|
        for pattern in urls.v1_api_and_json_patterns:
 | 
						|
            if not (hasattr(pattern, "_callback_str") and hasattr(pattern, "default_args")):
 | 
						|
                continue
 | 
						|
 | 
						|
            for func_string in pattern.default_args.values():
 | 
						|
                module_name, view = func_string.rsplit('.', 1)
 | 
						|
                self.check_function_exists(module_name, view)
 | 
						|
 | 
						|
    # Tests function-based views declared in urls.urlpatterns for
 | 
						|
    # whether the function exists.  We at present do not test the
 | 
						|
    # class-based views.
 | 
						|
    def test_non_api_url_resolution(self):
 | 
						|
        # type: () -> None
 | 
						|
        for pattern in urls.urlpatterns:
 | 
						|
            if not hasattr(pattern, "_callback_str"):
 | 
						|
                continue
 | 
						|
            (module_name, base_view) = pattern._callback_str.rsplit(".", 1)
 | 
						|
            self.check_function_exists(module_name, base_view)
 |