def test_correct_override_name(self):
        # need to pass this to the asset_url_parser context_processor
        fake_settings = utils.fake_settings(
            MEDIA_URL='not_overridden.url',
            STATIC_URL='not_overriden.url',
            FINIAL_MEDIA_URL_PREFIX='com.finial.media',
            FINIAL_STATIC_URL_PREFIX='com.finial.media',
            FINIAL_URL_OVERRIDES={
                'test_or':'finial.tests.finial_context_test_overrides'
            },
            DEBUG=False
        )

        context_processors.settings = fake_settings

        request = utils.FakeRequest()
        request.active_override_name = 'testing_override'
        request.finial_overrides = [{
            'pk': 1,
            'override_name': 'test_or',
            'override_dir': 'test_or/',
            'priority': 1,
        }]
        expected_output = {
            'STATIC_URL': 'com.finial.media.testing_override/',
            'MEDIA_URL': 'com.finial.media.testing_override/'
        }
        test_output = context_processors.asset_url(request)

        self.assertEqual(expected_output, test_output)
Exemplo n.º 2
0
    def test_unauthenticated_user_is_skipped(self):
        """Make sure we don't do any lookups for unauth'ed users."""
        template_dirs = ('./templates',)
        staticfiles_dirs = ('./static',)
        middleware.settings = utils.fake_settings(
            TEMPLATE_DIRS=template_dirs,
            STATICFILES_DIRS=staticfiles_dirs,
            PROJECT_PATH='.',
        )

        fake_request = utils.FakeRequest()
        fake_request.user = utils.fake_user(is_authenticated=lambda self: False)

        self.assertFalse(fake_request.user.is_authenticated())

        mid_inst = middleware.TemplateOverrideMiddleware()

        mid_inst.process_request(fake_request)

        # Assert that nothing has changed, our unauthenticated user is a
        # noop.
        self.assertEqual(
            middleware.settings.TEMPLATE_DIRS, template_dirs
        )

        self.assertEqual(
            middleware.settings.STATICFILES_DIRS, staticfiles_dirs
        )
Exemplo n.º 3
0
    def test_override_urlconf(self):
        """Test success case for overriding a request's urlconf."""
        paths = ['path.number1', 'path.number2']
        middleware.settings = utils.fake_settings(
            TEMPLATE_DIRS=self.override_template_dirs,
            PROJECT_PATH='.',
            FINIAL_URL_OVERRIDES={
                'override': paths[0],
                'override2': paths[1]
            },
            ROOT_URLCONF='test_settings'
        )
        fake_request = utils.FakeRequest()
        overrides = [{
            'pk': 1,
            'override_name': 'override',
            'override_dir': '/override',
            'priority': 1,
        },
        {
            'pk': 2,
            'override_name': 'override2',
            'override_dir': '/override2',
            'priority': 2,
        }]

        self.mimic.stub_out_with_mock(importlib, 'import_module')

        for path in paths:
            importlib.import_module(path).and_return(
                self._import_fake_urlconf(path)
            )

        self.mimic.replay_all()

        mid_inst = middleware.TemplateOverrideMiddleware()
        test_urlconf = mid_inst.override_urlconf(fake_request, overrides)

        expected = patterns(
            '',
            url('', paths[0], name='{0}_name'.format(paths[0])),
            url('', paths[1], name='{0}_name'.format(paths[1])),
            url('', include('test_settings'))
        )


        self.assertEqual(len(test_urlconf.urlpatterns), len(expected))
        for i in range(len(test_urlconf.urlpatterns) -1):
            self.assertEqual(
                test_urlconf.urlpatterns[i].name, expected[i].name
            )
            self.assertEqual(
                test_urlconf.urlpatterns[i].regex.pattern,
                expected[i].regex.pattern
            )

        self.assertEqual(
            test_urlconf.urlpatterns[-1].urlconf_name,
            expected[-1].urlconf_name
        )
Exemplo n.º 4
0
    def test_correct_override_name(self):
        # need to pass this to the asset_url_parser context_processor
        fake_settings = utils.fake_settings(
            MEDIA_URL='not_overridden.url',
            STATIC_URL='not_overriden.url',
            FINIAL_MEDIA_URL_PREFIX='com.finial.media',
            FINIAL_STATIC_URL_PREFIX='com.finial.media',
            FINIAL_URL_OVERRIDES={
                'test_or': 'finial.tests.finial_context_test_overrides'
            },
            DEBUG=False)

        context_processors.settings = fake_settings

        request = utils.FakeRequest()
        request.active_override_name = 'testing_override'
        request.finial_overrides = [{
            'pk': 1,
            'override_name': 'test_or',
            'override_dir': 'test_or/',
            'priority': 1,
        }]
        expected_output = {
            'STATIC_URL': 'com.finial.media.testing_override/',
            'MEDIA_URL': 'com.finial.media.testing_override/'
        }
        test_output = context_processors.asset_url(request)

        self.assertEqual(expected_output, test_output)
Exemplo n.º 5
0
 def setUp(self):
     super(MiddlewareTest, self).setUp()
     self.override_template_dirs = ('./templates',)
     self.override_static_dirs= ('./static',)
     self.settings = utils.fake_settings(
         TEMPLATE_DIRS=self.override_template_dirs,
         STATICFILES_DIRS=self.override_static_dirs,
         PROJECT_PATH='.',
     )
     middleware.settings = self.settings
     middleware.model_to_dict = utils.mock_model_to_dict
     self.mw = middleware.TemplateOverrideMiddleware()
     self.view_url = '/view1'
     cache.clear()