@@ -0,0 +1,2644 @@
+from django.test import TestCase%0Afrom django.test.client import RequestFactory%0A%0Afrom opps.contrib.mobile import template%0Afrom opps.contrib.mobile.middleware import (%0A    MobileDetectionMiddleware, MobileRedirectMiddleware%0A)%0A%0A%0Aclass TestMobileTemplatesDir(TestCase):%0A%0A    def setUp(self):%0A        self.detection_middleware = MobileDetectionMiddleware()%0A        self.factory = RequestFactory()%0A        self.template_loader = template.Loader()%0A%0A    def test_useragent_based_templatedirs(self):%0A        # Override the TEMPLATE_LOADERS and MIDDLEWARE_CLASSES settings%0A        # to use the middlewares in %60%60opps.contrib.mobile.middleware%60%60%0A        # and the %60%60opps.contrib.mobile.template.Loader%60%60%0A        MIDDLEWARE_CLASSES = (%0A            'django.middleware.common.CommonMiddleware',%0A            'opps.contrib.mobile.middleware.MobileDetectionMiddleware',%0A            'opps.contrib.mobile.middleware.MobileRedirectMiddleware',%0A            'django.contrib.sessions.middleware.SessionMiddleware',%0A            'django.middleware.csrf.CsrfViewMiddleware',%0A            'django.contrib.auth.middleware.AuthenticationMiddleware',%0A            'django.contrib.messages.middleware.MessageMiddleware',%0A            'django.contrib.redirects.middleware.RedirectFallbackMiddleware',%0A        )%0A        TEMPLATE_LOADERS = (%0A            'opps.contrib.mobile.template.Loader',%0A            'django.template.loaders.app_directories.Loader',%0A        )%0A        TEMPLATE_DIRS_MOBILE = ('mobile-templates',) %0A        TEMPLATE_DIRS_WEB = ('web-templates',)%0A%0A        custom_settings = self.settings(%0A            MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES,%0A            TEMPLATE_LOADERS=TEMPLATE_LOADERS,%0A            TEMPLATE_DIRS_MOBILE=TEMPLATE_DIRS_MOBILE,%0A            TEMPLATE_DIRS_WEB=TEMPLATE_DIRS_WEB,%0A            OPPS_CHECK_MOBILE=True,%0A            OPPS_DOMAIN_MOBILE = 'm.testserver'%0A        )%0A        with custom_settings:%0A            mobile_request = self.factory.get('/', HTTP_USER_AGENT='mobi')%0A            desktop_request = self.factory.get('/', HTTP_USER_AGENT='Mozilla/5.0')%0A%0A            self.detection_middleware.process_request(desktop_request)%0A            self.assertEqual(%0A                self.template_loader.get_template_sources('index.html').next(),%0A                self.template_loader.get_template_sources('index.html', TEMPLATE_DIRS_WEB).next()%0A            )%0A%0A            self.detection_middleware.process_request(mobile_request)%0A            self.assertEqual(%0A                self.template_loader.get_template_sources('index.html').next(),%0A                self.template_loader.get_template_sources('index.html', TEMPLATE_DIRS_MOBILE).next()%0A            )%0A

Test if mobile users get the right templates directory