Exemplo n.º 1
0
class NoAdminPageTests(POSERTestCase):
    urls = 'poser.test_utils.project.noadmin_urls'

    def setUp(self):
        admin = 'django.contrib.admin'
        noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
        self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
        self._ctx.__enter__()

    def tearDown(self):
        self._ctx.__exit__(None, None, None)

    def test_get_page_from_request_fakeadmin_nopage(self):
        request = self.get_request('/admin/')
        page = get_page_from_request(request)
        self.assertEqual(page, None)
Exemplo n.º 2
0
class SettingsOverrideTestCase(POSERTestCase):
    settings_overrides = {}

    def _pre_setup(self):
        self._enter_settings_override()
        super(SettingsOverrideTestCase, self)._pre_setup()

    def _enter_settings_override(self):
        self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
        self._settings_ctx_manager.__enter__()

    def _post_teardown(self):
        super(SettingsOverrideTestCase, self)._post_teardown()
        self._exit_settings_override()

    def _exit_settings_override(self):
        self._settings_ctx_manager.__exit__(None, None, None)
Exemplo n.º 3
0
    def test_apphook_on_root(self):
        
        with SettingsOverride(ROOT_URLCONF='poser.test_utils.project.urls_for_apphook_tests'):
            apphook_pool.clear()    
            superuser = User.objects.create_superuser('admin', '*****@*****.**', 'admin')
            page = create_page("apphooked-page", "nav_playground.html",
                               created_by=superuser, published=True, apphook="SampleApp")
            blank_page = create_page("not-apphooked-page", "nav_playground.html",
                                     created_by=superuser, published=True, apphook="", slug='blankapp')
            self.assertTrue(page.publish())
            self.assertTrue(blank_page.publish())
    
            response = self.client.get("/apphooked-page/")
            self.assertTemplateUsed(response, 'sampleapp/home.html')

            response = self.client.get('/blankapp/')
            self.assertTemplateUsed(response, 'nav_playground.html')

            apphook_pool.clear()
Exemplo n.º 4
0
    def test_poser_templates_valid(self):
        '''
        These are all formats that should be valid, thus return nothing when DEBUG is True.
        '''
        success_template_tests = (
            # one valid template
            (
                ('col_two.html', 'two columns'), ),

            # two valid templates
            (
                ('col_two.html', 'two columns'),
                ('col_three.html', 'three columns'),
            ),

            # three valid templates
            (
                ('col_two.html', 'two columns'),
                ('col_three.html', 'three columns'),
                ('nav_playground.html', 'navigation examples'),
            ),

            # three valid templates + inheritance
            (
                ('col_two.html', 'two columns'),
                ('col_three.html', 'three columns'),
                ('nav_playground.html', 'navigation examples'),
            ),

            # same valid templates as above, ensuring we don't short circuit when inheritance
            # magic comes first.
            (
                ('col_two.html', 'two columns'),
                ('col_three.html', 'three columns'),
                ('nav_playground.html', 'navigation examples'),
            ),
        )
        for value_to_test in success_template_tests:
            with SettingsOverride(DEBUG=True, POSER_TEMPLATES=value_to_test):
                self.assertEqual(None, post_patch_check())
Exemplo n.º 5
0
    def test_slug_url_overwrite_clash(self):
        """ Tests if a URL-Override clashes with a normal page url
        """
        with SettingsOverride(POSER_PERMISSION=False):
            bar = create_page('bar', 'nav_playground.html', published=False)
            foo = create_page('foo', 'nav_playground.html', published=True)
            # Tests to assure is_valid_url is ok on plain pages
            self.assertTrue(is_valid_url(bar.get_absolute_url(), bar))
            self.assertTrue(is_valid_url(foo.get_absolute_url(), foo))

            # Set url_overwrite for page foo
            foo.has_url_overwrite = True
            foo.path = '/bar/'
            foo.save()
            try:
                url = is_valid_url(bar.get_absolute_url(), bar)
            except ValidationError:
                url = False
            if url:
                bar.published = True
                bar.save()
            self.assertFalse(bar.published)
Exemplo n.º 6
0
    def test_get_page_for_apphook(self):
            
        with SettingsOverride(ROOT_URLCONF='poser.test_utils.project.second_urls_for_apphook_tests'):
    
            apphook_pool.clear()    
            superuser = User.objects.create_superuser('admin', '*****@*****.**', 'admin')
            child_child_page = create_page("child_child_page", "nav_playground.html",
                created_by=superuser, published=True, apphook='SampleApp')
            
            child_child_page.publish()
            # publisher_public is set to draft on publish, issue with onetoone reverse
            child_child_page = self.reload(child_child_page) 
            
            en_title = child_child_page.get_title()

            path = reverse('sample-settings')
            
            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)

            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, en_title)
            
            apphook_pool.clear()
Exemplo n.º 7
0
 def test_apphook_breaking_under_home_with_new_path_caching(self):
     with SettingsOverride(POSER_PERMISSION=False):
         create_page("subchild", "nav_playground.html", published=True, apphook='SampleApp')
         urlpatterns = get_app_patterns()
         resolver = urlpatterns[0]
         url = resolver.reverse('sample-root')
Exemplo n.º 8
0
 def test_unauthed_no_access(self):
     with SettingsOverride(POSER_PUBLIC_FOR='staff'):
         request = self.get_request()
         page = create_page("test-public-for-all", "nav_playground.html")
         self.assertFalse(page.has_view_permission(request))
Exemplo n.º 9
0
 def test_authed_no_access(self):
     with SettingsOverride(POSER_PUBLIC_FOR='staff'):
         user = User.objects.create_user('user', '*****@*****.**', 'user')
         request = self.get_request(user)
         page = create_page("test-public-for-all", "nav_playground.html")
         self.assertFalse(page.has_view_permission(request))
Exemplo n.º 10
0
 def test_anonymous_user_public_for_all(self):
     url = self.page_b.get_absolute_url()
     with SettingsOverride(POSER_PUBLIC_FOR='all'):
         response = self.client.get(url)
         self.assertEqual(response.status_code, 200)
Exemplo n.º 11
0
 def _enter_settings_override(self):
     self._settings_ctx_manager = SettingsOverride(
         **self.settings_overrides)
     self._settings_ctx_manager.__enter__()
Exemplo n.º 12
0
 def _enter_settings_override(self):
     self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
     self._settings_ctx_manager.__enter__()
Exemplo n.º 13
0
 def setUp(self):
     admin = 'django.contrib.admin'
     noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
     self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
     self._ctx.__enter__()