def test_delegate_to(self):
        """Test the view delegate feature."""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['title'] = 'delegate'
        page_data['slug'] = 'delegate'
        response = c.post('/admin/pages/page/add/', page_data)
        self.assertRedirects(response, '/admin/pages/page/')

        page = Page.objects.from_path('delegate', None)

        from pages import urlconf_registry as reg
        reg.register_urlconf('test',
                             'pages.testproj.documents.urls',
                             label='test')
        page.delegate_to = 'test'
        page.save()

        response = c.get(self.get_page_url('delegate'))
        self.assertEqual(response.status_code, 200)

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page)
        doc.save()

        url = self.get_page_url('delegate/doc-%d' % doc.id)
        self.assertTrue(str(doc.id) in url)

        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "doc title 1")
        reg.registry = []
    def test_delegate_to(self):
        """Test the view delegate feature."""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['title'] = 'delegate'
        page_data['slug'] = 'delegate'
        response = c.post('/admin/pages/page/add/', page_data)
        self.assertRedirects(response, '/admin/pages/page/')

        page = Page.objects.from_path('delegate', None)

        from pages import urlconf_registry as reg
        reg.register_urlconf('test', 'pages.testproj.documents.urls',
            label='test')
        page.delegate_to = 'test'
        page.save()

        response = c.get(self.get_page_url('delegate'))
        self.assertEqual(response.status_code, 200)

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page)
        doc.save()

        response = c.get(self.get_page_url('delegate/doc-%d' % doc.id))
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "doc title 1")
        reg.registry = []
Exemple #3
0
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={'slug':'page1'})
        page2 = self.new_page(content={'slug':'page2'})
        from pages import urlconf_registry as reg
        reg.register_urlconf('test', 'pages.testproj.documents.urls',
            label='test')
        page2.delegate_to = 'test'
        page1.delegate_to = 'test'
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", True)
        def _get_context_page(path):
            return details(req, path, 'en-us')
        self.assertEqual(_get_context_page('/').status_code, 200)
        self.assertEqual(_get_context_page('/page1').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/doc-%d' % doc.id
            ).status_code, 200)
        self.assertRaises(Http404, _get_context_page,
            '/page1/page-wrong/doc-%d' % doc.id)

        reg.registry = []
    def test_delegate_to(self):
        """Test the view delegate feature."""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data["title"] = "delegate"
        page_data["slug"] = "delegate"
        response = c.post("/admin/pages/page/add/", page_data)
        self.assertRedirects(response, "/admin/pages/page/")

        page = Page.objects.from_path("delegate", None)

        from pages import urlconf_registry as reg

        reg.register_urlconf("test", "pages.testproj.documents.urls", label="test")
        page.delegate_to = "test"
        page.save()

        response = c.get(self.get_page_url("delegate"))
        self.assertEqual(response.status_code, 200)

        from pages.testproj.documents.models import Document

        doc = Document(title="doc title 1", text="text", page=page)
        doc.save()

        response = c.get(self.get_page_url("delegate/doc-%d" % doc.id))
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "doc title 1")
        reg.registry = []
Exemple #5
0
    def test_delegate_to(self):
        """Test the view delegate feature."""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['title'] = 'delegate'
        page_data['slug'] = 'delegate'
        response = c.post('/admin/pages/page/add/', page_data)
        self.assertRedirects(response, '/admin/pages/page/')

        page = Page.objects.from_path('delegate', None)

        from pages import urlconf_registry as reg
        reg.register_urlconf('test', 'pages.tests.documents.urls',
            label='test')
        page.delegate_to = 'test'
        page.save()
        
        response = c.get('/pages/delegate')
        self.assertEqual(response.status_code, 200)
Exemple #6
0
    def test_urlconf_registry(self):
        """Test urlconf_registry basic functions."""
        reg.register_urlconf('Documents',
                             'example.documents.urls',
                             label='Display documents')

        reg.get_urlconf('Documents')
        try:
            reg.register_urlconf('Documents',
                                 'example.documents.urls',
                                 label='Display documents')
        except reg.UrlconfAlreadyRegistered:
            pass
        reg.registry = []
        try:
            reg.get_urlconf('Documents')
        except reg.UrlconfNotFound:
            pass

        reg.register_urlconf('Documents',
                             'example.documents.urls',
                             label='Display documents')

        self.assertEqual(reg.get_choices(),
                         [('', 'No delegation'),
                          ('Documents', 'Display documents')])
Exemple #7
0
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={'slug': 'page1'})
        page2 = self.new_page(content={'slug': 'page2'})
        from pages import urlconf_registry as reg
        reg.register_urlconf('test2',
                             'pages.testproj.documents.urls',
                             label='test')
        page2.delegate_to = 'test2'
        page1.delegate_to = 'test2'
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", False)
        page1.invalidate()
        page2.invalidate()

        def _get_context_page(path):
            return details(req, path, 'en-us')

        self.assertEqual(_get_context_page('/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/').status_code, 200)
        self.assertEqual(
            _get_context_page('/page1/page2/doc-%d' % doc.id).status_code, 200)
        self.assertRaises(Http404, _get_context_page,
                          '/page1/page-wrong/doc-%d' % doc.id)

        reg.registry = []
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={"slug": "page1"})
        page2 = self.new_page(content={"slug": "page2"})
        from pages import urlconf_registry as reg

        reg.register_urlconf("test2", "pages.testproj.documents.urls", label="test")
        page2.delegate_to = "test2"
        page1.delegate_to = "test2"
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document

        doc = Document(title="doc title 1", text="text", page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", False)
        page1.invalidate()
        page2.invalidate()

        def _get_context_page(path):
            return details(req, path, "en-us")

        self.assertEqual(_get_context_page("/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2/doc-%d" % doc.id).status_code, 200)
        self.assertRaises(Http404, _get_context_page, "/page1/page-wrong/doc-%d" % doc.id)

        reg.registry = []
    def test_urlconf_registry(self):
        """Test urlconf_registry basic functions."""
        reg.register_urlconf("Documents", "example.documents.urls", label="Display documents")

        reg.get_urlconf("Documents")
        try:
            reg.register_urlconf("Documents", "example.documents.urls", label="Display documents")
        except reg.UrlconfAlreadyRegistered:
            pass
        reg.registry = []
        try:
            reg.get_urlconf("Documents")
        except reg.UrlconfNotFound:
            pass

        reg.register_urlconf("Documents", "example.documents.urls", label="Display documents")

        self.assertEqual(reg.get_choices(), [("", "No delegation"), ("Documents", "Display documents")])
Exemple #10
0
    def test_urlconf_registry(self):
        """Test urlconf_registry basic functions."""
        reg.register_urlconf('Documents', 'example.documents.urls',
            label='Display documents')

        reg.get_urlconf('Documents')
        try:
            reg.register_urlconf('Documents', 'example.documents.urls',
            label='Display documents')
        except reg.UrlconfAlreadyRegistered:
            pass
        reg.registry = []
        try:
            reg.get_urlconf('Documents')
        except reg.UrlconfNotFound:
            pass

        reg.register_urlconf('Documents', 'example.documents.urls',
            label='Display documents')

        self.assertEqual(reg.get_choices(),
            [('', 'No delegation'), ('Documents', 'Display documents')])
Exemple #11
0
from django.conf import settings
from django.conf.urls import url
from django.urls import include, path, re_path
from django.conf.urls.static import static
from django.contrib import admin
from pages import views

from pages.urlconf_registry import register_urlconf
register_urlconf('blog', 'blog.urls', label='Blog index')

urlpatterns = [
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^admin/', admin.site.urls),
]

try:
	import haystack
	urlpatterns += [url(r'^search/', include('haystack.urls'), name='haystack_search')]
except ImportError:
	pass

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += [
    url(r'^$', views.details, {'path': '', 'name': 'pages-root'}),
    url(r'^', include('pages.urls')),
]

admin.site.site_header = 'Gerbi Admin'
from django.conf import settings
from django.conf.urls import url
from django.urls import include, path, re_path
from django.conf.urls.static import static
from django.contrib import admin
from pages import views

from pages.urlconf_registry import register_urlconf
register_urlconf('blog', 'blog.urls', label='Blog index')

urlpatterns = [
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^admin/', admin.site.urls),
]

try:
    import haystack
    urlpatterns += [
        url(r'^search/', include('haystack.urls'), name='haystack_search')
    ]
except ImportError:
    pass

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += [
    url(r'^$', views.details, {
        'path': '',
        'name': 'pages-root'
    }),
Exemple #13
0
import authority

from django.conf.urls.defaults import url, include, patterns
from django.conf.urls.defaults import handler404, handler500
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from pages.views import details

from pages.urlconf_registry import register_urlconf
register_urlconf('test', 'pages.testsproject.documents.urls')

admin.autodiscover()
authority.autodiscover()

urlpatterns = patterns('',
    (r'^authority/', include('authority.urls')),
    (r'^i18n/', include('django.conf.urls.i18n')),
    (r'^admin/', include(admin.site.urls)),

    # make tests fail if a backend is not present on the system
    (r'^search/', include('haystack.urls')),

)

urlpatterns += staticfiles_urlpatterns()

urlpatterns += patterns('',
    # this gonna match /admin if someone forget the traling slash
    (r'^', include('pages.urls')),
)