def test_i18n_view_set_language(self): request = create_request() from lfc.views import set_language self.assertEqual(set_language(request, "de", self.p2en.id)["Location"], "/de/page-2") self.assertEqual(set_language(request, "fr", self.p2en.id)["Location"], "/fr/page-2") self.assertEqual(set_language(request, "fr", self.p2de.id)["Location"], "/fr/page-2") self.assertEqual(set_language(request, "en", self.p2en.id)["Location"], "/page-2")
def test_i18n_has_language(self): request = create_request() self.assertEqual(self.p2de.has_language(request, "de"), True) self.assertEqual(self.p2fr.has_language(request, "fr"), True) self.assertEqual(self.p2en.has_language(request, "en"), True) self.assertEqual(self.p2en.has_language(request, "de"), True) self.assertEqual(self.p2en.has_language(request, "fr"), True) self.assertEqual(self.p2en.has_language(request, "es"), False)
def test_i18n_get_translation2(self): request = create_request() translation = self.p2en.get_translation(request, 'en') if translation: self.assertEqual(translation, self.p2en) translation = self.p2en.get_translation(request, 'fr') if translation: self.assertEqual(translation, self.p2fr) translation = self.p2en.get_translation(request, 'de') if translation: self.assertEqual(translation, self.p2de)
def test_i18n_get_translation3(self): request = create_request() translation = self.p2de.canonical.get_translation(request, 'en') if translation: self.assertEqual(translation, self.p2en) translation = self.p2fr.canonical.get_translation(request, 'en') if translation: self.assertEqual(translation, self.p2en) translation = self.p2fr.canonical.get_translation(request, 'de') if translation: self.assertEqual(translation, self.p2de)
def test_has_language(self): """ """ request = create_request() # Returns True if the object is neutral self.assertEqual(self.p1.has_language(request, "en-us"), True) self.assertEqual(self.p1.has_language(request, "de"), True) self.p1.language = "en-us" self.assertEqual(self.p1.has_language(request, "en-us"), True) self.assertEqual(self.p1.has_language(request, "de"), False)
def test_i18n_get_translation2(self): request = create_request() translation = self.p2en.get_translation(request, "en") if translation: self.assertEqual(translation, self.p2en) translation = self.p2en.get_translation(request, "fr") if translation: self.assertEqual(translation, self.p2fr) translation = self.p2en.get_translation(request, "de") if translation: self.assertEqual(translation, self.p2de)
def setUp(self): """ """ # Initialize LFC from lfc.management.commands.lfc_init import Command Command().handle() self.page = Page.objects.create(title="Page 1", slug="page-1") self.request = create_request() self.client = Client() self.client.login(username="******", password="******")
def test_i18n_get_translation3(self): request = create_request() translation = self.p2de.canonical.get_translation(request, "en") if translation: self.assertEqual(translation, self.p2en) translation = self.p2fr.canonical.get_translation(request, "en") if translation: self.assertEqual(translation, self.p2en) translation = self.p2fr.canonical.get_translation(request, "de") if translation: self.assertEqual(translation, self.p2de)
def test_i18n_view_set_language(self): request = create_request() from lfc.views import set_language self.assertEqual(set_language(request, 'de', self.p2en.id)['Location'], '/de/page-2') self.assertEqual(set_language(request, 'fr', self.p2en.id)['Location'], '/fr/page-2') self.assertEqual(set_language(request, 'fr', self.p2de.id)['Location'], '/fr/page-2') self.assertEqual(set_language(request, 'en', self.p2en.id)['Location'], '/page-2')
def test_i18n_view_set_language(self): request = create_request() from lfc.views import set_language self.assertEqual(set_language(request, 'en', self.p2en.id)['Location'], '/page-2') self.assertEqual(set_language(request, 'de', self.p2en.id)['Location'], '/de/page-2') self.assertEqual(set_language(request, 'fr', self.p2en.id)['Location'], '/fr/page-2') self.assertEqual(set_language(request, 'fr', self.p2de.id)['Location'], '/fr/page-2')
def test_working_cycle(self): request = create_request() self.assertEqual(Page.objects.count(), 2) checkout(request, self.p1.id) self.assertEqual(Page.objects.count(), 3) self.assertTrue(self.p1.has_working_copy()) self.assertFalse(self.p1.is_working_copy()) wc = self.p1.get_working_copy() self.assertFalse(wc.has_working_copy()) self.assertTrue(wc.is_working_copy()) checkin(request, wc.id) self.assertEqual(Page.objects.count(), 2)
def test_get_content_objects(self): """ """ # As superuser ct = lfc.utils.get_content_objects(slug="page-1") self.assertEqual(ct[0].title, "Page 1") request = create_request() request.user.is_superuser = False # Without passed request ct = lfc.utils.get_content_objects(slug="page-1") self.assertEqual(ct[0].title, "Page 1") # With passed request ct = lfc.utils.get_content_objects(request, slug="page-1") self.assertEqual(len(ct), 0)
def test_delete_group(self): """ """ request = create_request() roles = PrincipalRoleRelation.objects.all() self.assertEqual(len(roles), 0) permissions.utils.add_local_role(self.page_1, self.group, self.editor) roles = PrincipalRoleRelation.objects.all() self.assertEqual(len(roles), 1) from lfc.manage.views import delete_group delete_group(request, self.group.id) roles = PrincipalRoleRelation.objects.all() self.assertEqual(len(roles), 0)
def test_get_children(self): """ """ request = create_request() # children = self.p1.get_children(request) # self.assertEqual(len(children), 2) # # # The cildren have to be specific objects # for child in children: # self.failUnless(isinstance(child, Page)) # # children = self.p1.get_children(request, slug="page-1-1") # self.assertEqual(len(children), 1) request.user.is_superuser = False # No page is active children = self.p1.get_children(request) self.assertEqual(len(children), 0) children = self.p1.get_children() self.assertEqual(len(children), 2) # Grant view permission to self.p11 permissions.utils.grant_permission(self.p11, self.anonymous, "view") delattr(request.user, "permissions") result = self.p11.has_permission(request.user, "view") self.assertEqual(result, True) children = self.p1.get_children(request) self.assertEqual(len(children), 1) children = self.p1.get_children() self.assertEqual(len(children), 2) # Page 2 is not active children = self.p1.get_children(slug="page-1-2") self.assertEqual(len(children), 1) children = self.p1.get_children(request, slug="page-1-2") self.assertEqual(len(children), 0)
def test_get_children(self): """ """ request = create_request() children = self.p.get_children(request) self.assertEqual(len(children), 2) # The cildren have to be specific objects for child in children: self.failUnless(isinstance(child, Page)) children = self.p.get_children(request, slug="page-2") self.assertEqual(len(children), 1) request.user.is_superuser = False # No page is active children = self.p.get_children(request) self.assertEqual(len(children), 0) children = self.p.get_children() self.assertEqual(len(children), 2) permissions.utils.grant_permission(self.p1, self.anonymous, "view") delattr(request.user, "permissions") children = self.p.get_children(request) self.assertEqual(len(children), 1) children = self.p.get_children() self.assertEqual(len(children), 2) # Page 2 is not active children = self.p.get_children(slug="page-2") self.assertEqual(len(children), 1) children = self.p.get_children(request, slug="page-2") self.assertEqual(len(children), 0)
def test_i18n_get_canonical(self): request = create_request() self.assertEqual(self.p2de.get_canonical(request), self.p2en) self.assertEqual(self.p2en.get_canonical(request), self.p2en) self.assertEqual(self.p2fr.get_canonical(request), self.p2en)
def test_i18n_get_translation(self): request = create_request() self.assertEqual(self.p2en.is_translation(), False) self.assertEqual(self.p2de.is_translation(), True) self.assertEqual(self.p2fr.is_translation(), True)
def test_get_translation(self): """ """ request = create_request() self.assertEqual(self.p1.get_translation(request, "en-us"), None)
def test_get_canonical(self): """ """ request = create_request() self.assertEqual(self.p1.get_canonical(request), self.p1)