Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.curr_auth = settings.AUTHENTICATION_BACKENDS
settings.AUTHENTICATION_BACKENDS = tuple(self.curr_auth) + (self.backend,)
self.user1 = User.objects.create_user('test', 'test@example.com', 'test')
self.user2 = User.objects.create_user('test2', 'test2@example.com', 'test')
self.page_1 = Page.objects.create(title='1', slug='1', parent=None)
self.page_1_1 = Page.objects.create(title='1.1', slug='1.1', parent=self.page_1)
self.page_1 = Page.objects.get(pk=self.page_1.id)
self.page_1_1_1 = Page.objects.create(title='1.1.1', slug='1.1.1', parent=self.page_1_1)
self.page_1 = Page.objects.get(pk=self.page_1.id)
self.page_1_1 = Page.objects.get(pk=self.page_1_1.id)
self.page_1_2 = Page.objects.create(title='1.2', slug='1.2', parent=self.page_1)
self.page_1 = Page.objects.get(pk=self.page_1.id)
self.page_1_3 = Page.objects.create(title='1.3', slug='1.3', parent=self.page_1)
from feincms.module.page.models import Page
from feincms.module.page import processors
from mptt.models import MPTTModel
from .content import CustomContentType
Page.register_templates(
{
"key": "base",
"title": "Base Template",
"path": "base.html",
"regions": (("main", "Main region"), ("sidebar", "Sidebar", "inherited")),
}
)
Page.create_content_type(RawContent)
Page.create_content_type(
MediaFileContent, TYPE_CHOICES=(("default", "Default position"),)
)
Page.create_content_type(
TemplateContent, TEMPLATES=[("templatecontent_1.html", "template 1")]
)
Page.register_request_processor(processors.etag_request_processor)
Page.register_response_processor(processors.etag_response_processor)
Page.register_response_processor(processors.debug_sql_queries_response_processor())
def get_admin_fields(form, *args, **kwargs):
return {
"exclusive_subpages": forms.BooleanField(
label=capfirst(_("exclusive subpages")),
required=False,
def test_14_richtext(self):
# only create the content type to test the item editor
# customization hooks
tmp = Page._feincms_content_types[:]
type = Page.create_content_type(RichTextContent, regions=('notexists',))
Page._feincms_content_types = tmp
from django.utils.safestring import SafeData
obj = type()
obj.text = 'Something'
assert isinstance(obj.render(), SafeData)
def test_10_mediafile_and_imagecontent(self):
self.create_default_page_set()
page = Page.objects.get(pk=1)
self.create_pagecontent(page)
path = os.path.join(settings.MEDIA_ROOT, 'somefile.jpg')
f = open(path, 'wb')
f.write('blabla')
f.close()
category = Category.objects.create(title='Category', parent=None)
category2 = Category.objects.create(title='Something', parent=category)
self.assertEqual(unicode(category2), 'Category - Something')
self.assertEqual(unicode(category), 'Category')
mediafile = MediaFile.objects.create(file='somefile.jpg')
mediafile.categories = [category]
page.mediafilecontent_set.create(
def test_09_pagecontent(self):
self.create_default_page_set()
page = Page.objects.get(pk=1)
response = self.create_pagecontent(page)
self.assertRedirects(response, '/admin/page/page/')
self.assertEqual(page.content.main[0].__class__.__name__, 'RawContent')
page2 = Page.objects.get(pk=2)
page2.symlinked_page = page
self.assertEqual(page2.content.main[0].__class__.__name__, 'RawContent')
self.assertEqual(unicode(page2.content.main[0]),
'main on Test page (/test-page/), ordering 0')
self.assertEqual(len(page2.content.main), 1)
self.assertEqual(len(page2.content.sidebar), 0)
self.assertEqual(len(page2.content.nonexistant_region), 0)
self.assertRaises(Page.DoesNotExist, lambda: Page.objects.get(pk=2))
def test_20_redirects(self):
self.create_default_page_set()
page1 = Page.objects.get(pk=1)
page2 = Page.objects.get(pk=2)
page2.active = True
page2.publication_date = datetime.now() - timedelta(days=1)
page2.override_url = '/blablabla/'
page2.redirect_to = page1.get_absolute_url()
page2.save()
# regenerate cached URLs in the whole tree
page1.active = True
page1.save()
page2 = Page.objects.get(pk=2)
# page2 has been modified too, but its URL should not have changed
try:
self.assertRedirects(self.client.get('/blablabla/'), page1.get_absolute_url())
except TemplateDoesNotExist, e:
# catch the error from rendering page1
if e.args != ('feincms_base.html',):
raise
def test_24_admin_redirects(self):
self.create_default_page_set()
page = Page.objects.get(pk=1)
response = self.create_pagecontent(page, _continue=1)
self.assertRedirects(response, '/admin/page/page/1/')
response = self.create_pagecontent(page, _addanother=1)
self.assertRedirects(response, '/admin/page/page/add/')
response = self.create_pagecontent(page)
self.assertRedirects(response, '/admin/page/page/')
def test_08_publishing(self):
self.create_default_page_set()
page = Page.objects.get(pk=1)
page2 = Page.objects.get(pk=2)
self.is_published(page.get_absolute_url(), should_be=False)
self.is_published(page2.get_absolute_url(), should_be=False)
page.active = True
page.save()
page2.active = True
page2.save()
self.is_published(page.get_absolute_url(), should_be=True)
self.is_published(page2.get_absolute_url(), should_be=True)
old_publication = page.publication_date
page.publication_date = datetime.now() + timedelta(days=1)
page.save()
self.is_published(page.get_absolute_url(), should_be=False)
# Should be not accessible because of its parent's inactivity
def test_23_navigation_extension(self):
self.create_default_page_set()
page = Page.objects.get(pk=1)
self.assertEqual(page.extended_navigation(), [])
page.navigation_extension = 'feincms.tests.PassthroughExtension'
page2 = Page.objects.get(pk=2)
page2.active = True
page2.in_navigation = True
page2.save()
self.assertEqual(list(page.extended_navigation()), [page2])
page.navigation_extension = 'feincms.tests.ThisExtensionDoesNotExist'
self.assertEqual(page.extended_navigation(), [])