def test_page_image_view(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') PageImageContent.objects.create(page=self.page_foo, image='img/test.jpg', title='test') img1 = PageImageContent.objects.create(page=self.page_foo, image='img/test.jpg', title='test') img1.tags.add('test', 'image-1') img2 = PageImageContent.objects.create(page=self.page_foo, image='img/test.jpg', title='test') img2.tags.add('test', 'image-2') self.page_foo.template = 'pages/page_image.html' self.page_foo.save() page_url = reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('en') response = view(request=request, context=context, slug='test') translation.deactivate() self.assertEqual(response.status_code, 200) self.page_foo.delete() cache.clear()
def test_page_video_view(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test' ) video1 = PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test' ) video1.tags.add('test', 'video-1') video2 = PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test' ) video2.tags.add('test', 'video-2') self.page_foo.template = 'pages/page_video.html' self.page_foo.save() page_url = reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('en') response = view(request=request, context=context, slug='test') translation.deactivate() self.assertEqual(response.status_code, 200) self.page_foo.delete() cache.clear()
def test_page_text_view_cache(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') self.page_foo.template = 'pages/page_text.html' self.page_foo.save() page_url = reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('en') response = view(request=request, context=context, slug='test') translation.deactivate() self.assertEqual(response.status_code, 200) page_cache_key = settings.PAGES_PAGE_CACHE_KEY + 'en' + ':' + 'test' + ':' + 'False' page_cache_version_key = settings.PAGES_PAGE_VERSION_KEY + 'en' + ':' + 'test' cache_version = cache.get(page_cache_version_key) page = cache.get(page_cache_key, version=cache_version) self.assertNotEqual(page, None) self.page_foo.save() cache_version = cache.get(page_cache_version_key) self.assertEqual(cache_version, 2) self.page_foo.delete() cache.clear()
def test_page_file_view(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') PageFileContent.objects.create(page=self.page_foo, file='files/test.txt', title='test') file1 = PageFileContent.objects.create(page=self.page_foo, file='files/test.txt', title='test') file1.tags.add('test', 'file-1') file2 = PageFileContent.objects.create(page=self.page_foo, file='files/test.txt', title='test') file2.tags.add('test', 'file-2') self.page_foo.template = 'pages/page_file.html' self.page_foo.save() page_url = reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('en') response = view(request=request, context=context, slug='test') translation.deactivate() self.assertEqual(response.status_code, 200) self.page_foo.delete() cache.clear()
def setUp(self): # useful to make sure the tests will be properly # executed in an exotic project. self.set_setting("PAGE_TEMPLATES", test_settings.PAGE_TEMPLATES) self.set_setting("PAGE_DEFAULT_TEMPLATE", test_settings.PAGE_DEFAULT_TEMPLATE) self.old_url_conf = getattr(settings, "ROOT_URLCONF") setattr(settings, "ROOT_URLCONF", "pages.testproj.urls") clear_url_caches() cache.clear()
def test_page_absolute_url(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') self.page_foo.template = 'pages/page_text.html' self.page_foo.save() page_url = self.page_foo.get_absolute_url() self.assertEqual(page_url, '/en/page/test/') self.page_foo.delete() cache.clear()
def setUp(self): # useful to make sure the tests will be properly # executed in an exotic project. self.set_setting('PAGE_TEMPLATES', test_settings.PAGE_TEMPLATES) self.set_setting('PAGE_DEFAULT_TEMPLATE', test_settings.PAGE_DEFAULT_TEMPLATE) self.old_url_conf = getattr(settings, 'ROOT_URLCONF') setattr(settings, 'ROOT_URLCONF', 'pages.testproj.urls') clear_url_caches() cache.clear()
def test_page_fallback_language(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') self.page_foo.template = 'pages/page_text.html' self.page_foo.save() page_url = '/de' + reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('de') response = view(request=request, context=context, slug='test') self.assertEqual(response.status_code, 302) page_url = response.get('location') response = self.client.get(page_url) translation.deactivate() self.assertEqual(response.status_code, 200) self.page_foo.delete() cache.clear()
def test_page_video_view(self): PageSlugContent.objects.create(page=self.page_foo, slug='test') PageMetaContent.objects.create(page=self.page_foo, title='test', description='test', keywords='test') PageTextContent.objects.create(page=self.page_foo, text='test') PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test') video1 = PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test') video1.tags.add('test', 'video-1') video2 = PageVideoContent.objects.create( page=self.page_foo, video='https://www.youtube.com/watch?v=C0DPdy98e4c', title='test') video2.tags.add('test', 'video-2') self.page_foo.template = 'pages/page_video.html' self.page_foo.save() page_url = reverse('pages:show', kwargs={'slug': 'test'}) request = self.factory.get(page_url) request.user = AnonymousUser() context = RequestContext(request) view = PageDetailsView.as_view() translation.activate('en') response = view(request=request, context=context, slug='test') translation.deactivate() self.assertEqual(response.status_code, 200) self.page_foo.delete() cache.clear()