Пример #1
0
    def test_post_detail_view(self):
        page1, page2 = self.get_pages()
        post1, post2 = self.get_posts()

        request = self.get_page_request(page1, AnonymousUser(), r'/en/blog/', edit=False)
        activate('en')
        view_obj = PostDetailView()
        view_obj.request = request

        with self.assertRaises(Http404):
            view_obj.kwargs = {'slug': 'not-existing'}
            post_obj = view_obj.get_object()

        view_obj.kwargs = {'slug': post1.slug}
        post_obj = view_obj.get_object()
        self.assertEqual(post_obj, post1)
        self.assertEqual(post_obj.language_code, 'en')

        request = self.get_page_request(page1, AnonymousUser(), r'/it/blog/', lang_code='it', edit=False)
        activate('it')
        post1.set_current_language('it')
        view_obj.request = request
        view_obj.kwargs = {'slug': post1.slug}
        post_obj = view_obj.get_object()
        self.assertEqual(post_obj, post1)
        self.assertEqual(post_obj.language_code, 'it')

        view_obj.object = post_obj
        context = view_obj.get_context_data()
        self.assertEqual(context['post'], post1)
        self.assertEqual(context['post'].language_code, 'it')
        self.assertTrue(context['meta'])
Пример #2
0
    def test_post_detail_view(self):
        pages = self.get_pages()
        posts = self.get_posts()

        with smart_override('en'):
            with switch_language(posts[0], 'en'):
                request = self.get_page_request(pages[1],
                                                AnonymousUser(),
                                                lang='en',
                                                edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                with self.assertRaises(Http404):
                    view_obj.kwargs = {'slug': 'not-existing'}
                    post_obj = view_obj.get_object()

                view_obj.kwargs = {'slug': posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, 'en')

        with smart_override('it'):
            with switch_language(posts[0], 'it'):
                request = self.get_page_request(pages[1],
                                                AnonymousUser(),
                                                lang='it',
                                                edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                view_obj.kwargs = {'slug': posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, 'it')

                view_obj.object = post_obj
                context = view_obj.get_context_data()
                self.assertEqual(context['post'], posts[0])
                self.assertEqual(context['post'].language_code, 'it')
                self.assertTrue(context['meta'])
Пример #3
0
    def test_post_detail_view(self):
        pages = self.get_pages()
        posts = self.get_posts()

        with smart_override("en"):
            with switch_language(posts[0], "en"):
                request = self.get_page_request(pages[1],
                                                AnonymousUser(),
                                                lang="en",
                                                edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                with self.assertRaises(Http404):
                    view_obj.kwargs = {"slug": "not-existing"}
                    post_obj = view_obj.get_object()

                view_obj.kwargs = {"slug": posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, "en")

        with smart_override("it"):
            with switch_language(posts[0], "it"):
                request = self.get_page_request(pages[1],
                                                AnonymousUser(),
                                                lang="it",
                                                edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                view_obj.kwargs = {"slug": posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, "it")

                view_obj.object = post_obj
                context = view_obj.get_context_data()
                self.assertEqual(context["post"], posts[0])
                self.assertEqual(context["post"].language_code, "it")
                self.assertTrue(context["meta"])
Пример #4
0
    def test_post_detail_view(self):
        posts = self.get_posts()
        pages = self.get_pages()

        with smart_override('en'):
            with switch_language(posts[0], 'en'):
                request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                with self.assertRaises(Http404):
                    view_obj.kwargs = {'slug': 'not-existing'}
                    post_obj = view_obj.get_object()

                view_obj.kwargs = {'slug': posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, 'en')

        with smart_override('it'):
            with switch_language(posts[0], 'it'):
                request = self.get_page_request(pages[1], AnonymousUser(), lang='it', edit=False)
                view_obj = PostDetailView()
                view_obj.request = request
                view_obj.namespace, view_obj.config = get_app_instance(request)

                view_obj.kwargs = {'slug': posts[0].slug}
                post_obj = view_obj.get_object()
                self.assertEqual(post_obj, posts[0])
                self.assertEqual(post_obj.language_code, 'it')

                view_obj.object = post_obj
                context = view_obj.get_context_data()
                self.assertEqual(context['post'], posts[0])
                self.assertEqual(context['post'].language_code, 'it')
                self.assertTrue(context['meta'])