def setUp(self): self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.author = ProfileFactory() self.user = ProfileFactory() self.staff = StaffProfileFactory() self.tuto = PublishableContentFactory(type='TUTORIAL') self.tuto.authors.add(self.author.user) self.tuto.licence = self.licence self.tuto.subcategory.add(self.subcategory) self.tuto.save() self.validation = Validation( content=self.tuto, version=self.tuto.sha_draft, comment_authors='bla', date_proposition=datetime.now(), ) self.validation.save() self.topic = send_mp(author=self.author.user, users=[], title='Title', text='Testing', subtitle='', leave=False) self.topic.participants.add(self.user.user) send_message_mp(self.user.user, self.topic, 'Testing') # humane_delta test periods = ((1, 0), (2, 1), (3, 7), (4, 30), (5, 360)) cont = dict() cont['date_today'] = periods[0][0] cont['date_yesterday'] = periods[1][0] cont['date_last_week'] = periods[2][0] cont['date_last_month'] = periods[3][0] cont['date_last_year'] = periods[4][0] self.context = Context(cont)
def setUp(self): self.overridden_zds_app = overridden_zds_app # don't build PDF to speed up the tests overridden_zds_app["content"]["build_pdf_when_published"] = False self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" self.mas = ProfileFactory().user overridden_zds_app["member"]["bot_account"] = self.mas.username self.licence = LicenceFactory() self.subcategory = SubCategoryFactory(category=CategoryFactory()) self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user self.content = PublishableContentFactory( author_list=[self.user_author], light=False) self.part_published = ContainerFactory( db_object=self.content, light=False, parent=self.content.load_version()) self.ignored_part = ContainerFactory( db_object=self.content, light=False, parent=self.content.load_version()) ExtractFactory(db_object=self.content, container=self.part_published, light=False) ExtractFactory(db_object=self.content, container=self.ignored_part, light=False)
def setUp(self): self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' self.mas = ProfileFactory().user self.overridden_zds_app['member']['bot_account'] = self.mas.username self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user self.tuto = PublishableContentFactory(type='TUTORIAL') self.tuto.authors.add(self.user_author) UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W') self.tuto.licence = self.licence self.tuto.subcategory.add(self.subcategory) self.tuto.save() self.beta_forum = ForumFactory( pk=self.overridden_zds_app['forum']['beta_forum_id'], category=CategoryFactory(position=1), position_in_category=1) # ensure that the forum, for the beta versions, is created self.tuto_draft = self.tuto.load_version() self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto) self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto) self.extract1 = ExtractFactory(container=self.chapter1, db_object=self.tuto) bot = Group(name=self.overridden_zds_app['member']['bot_group']) bot.save()
def setUp(self): # don't build PDF to speed up the tests self.user1 = ProfileFactory().user self.user2 = ProfileFactory().user # create a tutorial self.tuto = PublishableContentFactory(type='TUTORIAL') self.tuto.authors.add(self.user1) UserGalleryFactory(gallery=self.tuto.gallery, user=self.user1, mode='W') self.tuto.licence = LicenceFactory() self.tuto.subcategory.add(SubCategoryFactory()) self.tuto.save() tuto_draft = self.tuto.load_version() # then, publish it ! version = tuto_draft.current_version self.published = publish_content(self.tuto, tuto_draft, is_major_update=True) self.tuto.sha_public = version self.tuto.sha_draft = version self.tuto.public_version = self.published self.tuto.save() self.assertTrue(self.client.login(username=self.user1.username, password='******'))
def setUp(self): self.overridden_zds_app = overridden_zds_app # don't build PDF to speed up the tests overridden_zds_app["content"]["build_pdf_when_published"] = False self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" self.mas = ProfileFactory().user overridden_zds_app["member"]["bot_account"] = self.mas.username bot = Group(name=overridden_zds_app["member"]["bot_group"]) bot.save() self.external = UserFactory( username=overridden_zds_app["member"]["external_account"], password="******") self.beta_forum = ForumFactory( pk=overridden_zds_app["forum"]["beta_forum_id"], category=ForumCategoryFactory(position=1), position_in_category=1, ) # ensure that the forum, for the beta versions, is created self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.tag = TagFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user # create an article self.article = PublishableContentFactory(type="ARTICLE") self.article.authors.add(self.user_author) UserGalleryFactory(gallery=self.article.gallery, user=self.user_author, mode="W") self.article.licence = self.licence self.article.subcategory.add(self.subcategory) self.article.tags.add(self.tag) self.article.save() # fill it with one extract self.article_draft = self.article.load_version() self.extract1 = ExtractFactory(container=self.article_draft, db_object=self.article) # then, publish it ! version = self.article_draft.current_version self.published = publish_content(self.article, self.article_draft, is_major_update=True) self.article.sha_public = version self.article.sha_draft = version self.article.public_version = self.published self.article.save() self.articlefeed = LastArticlesFeedRSS()
def setUp(self): # don't build PDF to speed up the tests settings.ZDS_APP['content']['build_pdf_when_published'] = False self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' self.mas = ProfileFactory().user settings.ZDS_APP['member']['bot_account'] = self.mas.username bot = Group(name=settings.ZDS_APP['member']['bot_group']) bot.save() self.external = UserFactory( username=settings.ZDS_APP['member']['external_account'], password='******') self.beta_forum = ForumFactory( pk=settings.ZDS_APP['forum']['beta_forum_id'], category=CategoryFactory(position=1), position_in_category=1 ) # ensure that the forum, for the beta versions, is created self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user # create an article self.article = PublishableContentFactory(type='ARTICLE') self.article.authors.add(self.user_author) UserGalleryFactory(gallery=self.article.gallery, user=self.user_author, mode='W') self.article.licence = self.licence self.article.subcategory.add(self.subcategory) self.article.save() # fill it with one extract self.article_draft = self.article.load_version() self.extract1 = ExtractFactory(container=self.article_draft, db_object=self.article) # then, publish it ! version = self.article_draft.current_version self.published = publish_content(self.article, self.article_draft, is_major_update=True) self.article.sha_public = version self.article.sha_draft = version self.article.public_version = self.published self.article.save() self.articlefeed = LastArticlesFeedRSS()
def test_list_categories(self): category_1 = ContentCategoryFactory() subcategory_1 = SubCategoryFactory(category=category_1) subcategory_2 = SubCategoryFactory(category=category_1) # Not in context if nothing published inside this subcategory SubCategoryFactory(category=category_1) for _ in range(5): self._create_and_publish_type_in_subcategory('TUTORIAL', subcategory_1) self._create_and_publish_type_in_subcategory('ARTICLE', subcategory_2) self.client.logout() resp = self.client.get(reverse('publication:list')) context_categories = list(resp.context_data['categories']) self.assertEqual(context_categories[0].contents_count, 10) self.assertEqual(context_categories[0].subcategories, [subcategory_1, subcategory_2]) self.assertEqual(context_categories, [category_1])
def test_accessible_ui_for_author(self): opinion = PublishedContentFactory(author_list=[self.user_author], type='OPINION') subcategory = SubCategoryFactory() opinion.subcategory.add(subcategory) opinion.save() self.assertEqual( self.client.login(username=self.user_author.username, password='******'), True) resp = self.client.get(reverse('opinion:view', kwargs={'pk': opinion.pk, 'slug': opinion.slug})) self.assertContains(resp, 'Version brouillon', msg_prefix='Author must access their draft directly') self.assertNotContains(resp, '{}?subcategory='.format(reverse('publication:list'))) self.assertContains(resp, '{}?category='.format(reverse('opinion:list')))
def setUp(self): # don't build PDF to speed up the tests settings.ZDS_APP['content']['build_pdf_when_published'] = False self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' self.mas = ProfileFactory().user settings.ZDS_APP['member']['bot_account'] = self.mas.username self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user self.tuto = PublishableContentFactory(type='TUTORIAL') self.tuto.authors.add(self.user_author) UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W') self.tuto.licence = self.licence self.tuto.subcategory.add(self.subcategory) self.tuto.save() self.beta_forum = ForumFactory( pk=settings.ZDS_APP['forum']['beta_forum_id'], category=CategoryFactory(position=1), position_in_category=1 ) # ensure that the forum, for the beta versions, is created self.tuto_draft = self.tuto.load_version() self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto) self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto) self.extract1 = ExtractFactory(container=self.chapter1, db_object=self.tuto) bot = Group(name=settings.ZDS_APP["member"]["bot_group"]) bot.save() self.external = UserFactory( username=settings.ZDS_APP["member"]["external_account"], password="******")
def test_content_ordering(self): category_1 = ContentCategoryFactory() category_2 = ContentCategoryFactory() subcategory_1 = SubCategoryFactory(category=category_1) subcategory_1.position = 5 subcategory_1.save() subcategory_2 = SubCategoryFactory(category=category_1) subcategory_2.position = 1 subcategory_2.save() subcategory_3 = SubCategoryFactory(category=category_2) tuto_1 = PublishableContentFactory(type='TUTORIAL') tuto_1.subcategory.add(subcategory_1) tuto_1_draft = tuto_1.load_version() publish_content(tuto_1, tuto_1_draft, is_major_update=True) top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories') expected = [(subcategory_1.title, subcategory_1.slug, category_1.slug)] self.assertEqual(top_categories_tuto[category_1.title], expected) tuto_2 = PublishableContentFactory(type='TUTORIAL') tuto_2.subcategory.add(subcategory_2) tuto_2_draft = tuto_2.load_version() publish_content(tuto_2, tuto_2_draft, is_major_update=True) top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories') # New subcategory is now first is the list expected.insert(0, (subcategory_2.title, subcategory_2.slug, category_1.slug)) self.assertEqual(top_categories_tuto[category_1.title], expected) article_1 = PublishableContentFactory(type='TUTORIAL') article_1.subcategory.add(subcategory_3) article_1_draft = tuto_2.load_version() publish_content(article_1, article_1_draft, is_major_update=True) # New article has no impact top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories') self.assertEqual(top_categories_tuto[category_1.title], expected) top_categories_contents = topbar_publication_categories(['TUTORIAL', 'ARTICLE']).get('categories') expected_2 = [(subcategory_3.title, subcategory_3.slug, category_2.slug)] self.assertEqual(top_categories_contents[category_1.title], expected) self.assertEqual(top_categories_contents[category_2.title], expected_2)
def test_publication_and_attributes_consistency(self): pubdate = datetime.now() - timedelta(days=1) article = PublishedContentFactory(type="ARTICLE", author_list=[self.user_author]) public_version = article.public_version public_version.publication_date = pubdate public_version.save() # everything must come from database to have good datetime comparison article = PublishableContent.objects.get(pk=article.pk) article.public_version.load_public_version() old_date = article.public_version.publication_date old_title = article.public_version.title() old_description = article.public_version.description() article.licence = LicenceFactory() article.save() self.assertEqual( self.client.login(username=self.user_author.username, password="******"), True) self.client.post( reverse("content:edit", args=[article.pk, article.slug]), { "title": old_title + "bla", "description": old_description + "bla", "type": "ARTICLE", "licence": article.licence.pk, "subcategory": SubCategoryFactory().pk, "last_hash": article.sha_draft, }, ) article = PublishableContent.objects.prefetch_related( "public_version").get(pk=article.pk) article.public_version.load_public_version() self.assertEqual(old_title, article.public_version.title()) self.assertEqual(old_description, article.public_version.description()) self.assertEqual(old_date, article.public_version.publication_date) publish_content(article, article.load_version(), False) article = PublishableContent.objects.get(pk=article.pk) article.public_version.load_public_version() self.assertEqual(old_date, article.public_version.publication_date) self.assertNotEqual(old_date, article.public_version.update_date)
def test_publication_and_attributes_consistency(self): pubdate = datetime.now() - timedelta(days=1) article = PublishedContentFactory(type='ARTICLE', author_list=[self.user_author]) public_version = article.public_version public_version.publication_date = pubdate public_version.save() # everything must come from database to have good datetime comparison article = PublishableContent.objects.get(pk=article.pk) article.public_version.load_public_version() old_date = article.public_version.publication_date old_title = article.public_version.title() old_description = article.public_version.description() article.licence = LicenceFactory() article.save() self.assertEqual( self.client.login(username=self.user_author.username, password='******'), True) self.client.post( reverse('content:edit', args=[article.pk, article.slug]), { 'title': old_title + 'bla', 'description': old_description + 'bla', 'type': 'ARTICLE', 'licence': article.licence.pk, 'subcategory': SubCategoryFactory().pk, 'last_hash': article.sha_draft }) article = PublishableContent.objects.prefetch_related( 'public_version').get(pk=article.pk) article.public_version.load_public_version() self.assertEqual(old_title, article.public_version.title()) self.assertEqual(old_description, article.public_version.description()) self.assertEqual(old_date, article.public_version.publication_date) publish_content(article, article.load_version(), False) article = PublishableContent.objects.get(pk=article.pk) article.public_version.load_public_version() self.assertEqual(old_date, article.public_version.publication_date) self.assertNotEqual(old_date, article.public_version.update_date)
def test_accessible_ui_for_author(self): opinion = PublishedContentFactory(author_list=[self.user_author], type="OPINION") subcategory = SubCategoryFactory() opinion.subcategory.add(subcategory) opinion.save() self.assertEqual( self.client.login(username=self.user_author.username, password="******"), True) resp = self.client.get( reverse("opinion:view", kwargs={ "pk": opinion.pk, "slug": opinion.slug })) self.assertContains( resp, "Version brouillon", msg_prefix="Author must access their draft directly") self.assertNotContains( resp, "{}?subcategory=".format(reverse("publication:list"))) self.assertContains(resp, "{}?category=".format(reverse("opinion:list")))
def test_upercase_and_lowercase_search_give_same_results(self): """Pretty self-explanatory function name, isn't it ?""" if not self.manager.connected_to_es: return # 1. Index lowercase stuffs text_lc = 'test' topic_1_lc = TopicFactory(forum=self.forum, author=self.user, title=text_lc) tag_lc = TagFactory(title=text_lc) topic_1_lc.tags.add(tag_lc) topic_1_lc.subtitle = text_lc topic_1_lc.save() post_1_lc = PostFactory(topic=topic_1_lc, author=self.user, position=1) post_1_lc.text = post_1_lc.text_html = text_lc post_1_lc.save() tuto_lc = PublishableContentFactory(type='TUTORIAL') tuto_draft_lc = tuto_lc.load_version() tuto_lc.title = text_lc tuto_lc.authors.add(self.user) subcategory_lc = SubCategoryFactory(title=text_lc) tuto_lc.subcategory.add(subcategory_lc) tuto_lc.tags.add(tag_lc) tuto_lc.save() tuto_draft_lc.description = text_lc tuto_draft_lc.repo_update_top_container(text_lc, tuto_lc.slug, text_lc, text_lc) chapter1_lc = ContainerFactory(parent=tuto_draft_lc, db_object=tuto_lc) extract_lc = ExtractFactory(container=chapter1_lc, db_object=tuto_lc) extract_lc.repo_update(text_lc, text_lc) published_lc = publish_content(tuto_lc, tuto_draft_lc, is_major_update=True) tuto_lc.sha_public = tuto_draft_lc.current_version tuto_lc.sha_draft = tuto_draft_lc.current_version tuto_lc.public_version = published_lc tuto_lc.save() # 2. Index uppercase stuffs text_uc = 'TEST' topic_1_uc = TopicFactory(forum=self.forum, author=self.user, title=text_uc) topic_1_uc.tags.add( tag_lc) # Note: a constraint forces tags title to be unique topic_1_uc.subtitle = text_uc topic_1_uc.save() post_1_uc = PostFactory(topic=topic_1_uc, author=self.user, position=1) post_1_uc.text = post_1_uc.text_html = text_uc post_1_uc.save() tuto_uc = PublishableContentFactory(type='TUTORIAL') tuto_draft_uc = tuto_uc.load_version() tuto_uc.title = text_uc tuto_uc.authors.add(self.user) tuto_uc.subcategory.add(subcategory_lc) tuto_uc.tags.add(tag_lc) tuto_uc.save() tuto_draft_uc.description = text_uc tuto_draft_uc.repo_update_top_container(text_uc, tuto_uc.slug, text_uc, text_uc) chapter1_uc = ContainerFactory(parent=tuto_draft_uc, db_object=tuto_uc) extract_uc = ExtractFactory(container=chapter1_uc, db_object=tuto_uc) extract_uc.repo_update(text_uc, text_uc) published_uc = publish_content(tuto_uc, tuto_draft_uc, is_major_update=True) tuto_uc.sha_public = tuto_draft_uc.current_version tuto_uc.sha_draft = tuto_draft_uc.current_version tuto_uc.public_version = published_uc tuto_uc.save() # 3. Index and search: self.assertEqual( len( self.manager.setup_search(Search().query( MatchAll())).execute()), 0) # index for model in self.indexable: if model is FakeChapter: continue self.manager.es_bulk_indexing_of_model(model) self.manager.refresh_index() result = self.client.get(reverse('search:query') + '?q=' + text_lc, follow=False) self.assertEqual(result.status_code, 200) response_lc = result.context['object_list'].execute() self.assertEqual(response_lc.hits.total, 8) result = self.client.get(reverse('search:query') + '?q=' + text_uc, follow=False) self.assertEqual(result.status_code, 200) response_uc = result.context['object_list'].execute() self.assertEqual(response_uc.hits.total, 8) for responses in zip( response_lc, response_uc): # we should get results in the same order! self.assertEqual(responses[0].meta.id, responses[1].meta.id)
def test_category_and_subcategory_impact_search(self): """If two contents do not belong to the same (sub)category""" if not self.manager.connected_to_es: return text = 'Did you ever hear the tragedy of Darth Plagueis The Wise?' # 1. Create two contents with different subcategories category_1 = 'category 1' subcategory_1 = SubCategoryFactory(title=category_1) category_2 = 'category 2' subcategory_2 = SubCategoryFactory(title=category_2) tuto_1 = PublishableContentFactory(type='TUTORIAL') tuto_1_draft = tuto_1.load_version() tuto_1.title = text tuto_1.authors.add(self.user) tuto_1.subcategory.add(subcategory_1) tuto_1.save() tuto_1_draft.description = text tuto_1_draft.repo_update_top_container(text, tuto_1.slug, text, text) chapter_1 = ContainerFactory(parent=tuto_1_draft, db_object=tuto_1) extract_1 = ExtractFactory(container=chapter_1, db_object=tuto_1) extract_1.repo_update(text, text) published_1 = publish_content(tuto_1, tuto_1_draft, is_major_update=True) tuto_1.sha_public = tuto_1_draft.current_version tuto_1.sha_draft = tuto_1_draft.current_version tuto_1.public_version = published_1 tuto_1.save() tuto_2 = PublishableContentFactory(type='TUTORIAL') tuto_2_draft = tuto_2.load_version() tuto_2.title = text tuto_2.authors.add(self.user) tuto_2.subcategory.add(subcategory_2) tuto_2.save() tuto_2_draft.description = text tuto_2_draft.repo_update_top_container(text, tuto_2.slug, text, text) chapter_2 = ContainerFactory(parent=tuto_2_draft, db_object=tuto_2) extract_2 = ExtractFactory(container=chapter_2, db_object=tuto_2) extract_2.repo_update(text, text) published_2 = publish_content(tuto_2, tuto_2_draft, is_major_update=True) tuto_2.sha_public = tuto_2_draft.current_version tuto_2.sha_draft = tuto_2_draft.current_version tuto_2.public_version = published_2 tuto_2.save() # 2. Index: self.assertEqual( len( self.manager.setup_search(Search().query( MatchAll())).execute()), 0) # index for model in self.indexable: if model is FakeChapter: continue self.manager.es_bulk_indexing_of_model(model) self.manager.refresh_index() result = self.client.get(reverse('search:query') + '?q=' + text, follow=False) self.assertEqual(result.status_code, 200) response = result.context['object_list'].execute() self.assertEqual(response.hits.total, 4) # Ok # 3. Test result = self.client.get(reverse('search:query') + '?q=' + text + '&model=content&subcategory=' + subcategory_1.slug, follow=False) self.assertEqual(result.status_code, 200) response = result.context['object_list'].execute() self.assertEqual(response.hits.total, 2) self.assertEqual([ int(r.meta.id) for r in response if r.meta.doc_type == 'publishedcontent' ][0], published_1.pk) self.assertEqual([ r.meta.id for r in response if r.meta.doc_type == 'chapter' ][0], tuto_1.slug + '__' + chapter_1.slug) result = self.client.get(reverse('search:query') + '?q=' + text + '&model=content&subcategory=' + subcategory_2.slug, follow=False) self.assertEqual(result.status_code, 200) response = result.context['object_list'].execute() self.assertEqual(response.hits.total, 2) self.assertEqual([ int(r.meta.id) for r in response if r.meta.doc_type == 'publishedcontent' ][0], published_2.pk) self.assertEqual([ r.meta.id for r in response if r.meta.doc_type == 'chapter' ][0], tuto_2.slug + '__' + chapter_2.slug)
def test_content_ordering(self): category_1 = ContentCategoryFactory() category_2 = ContentCategoryFactory() subcategory_1 = SubCategoryFactory(category=category_1) subcategory_1.position = 5 subcategory_1.save() subcategory_2 = SubCategoryFactory(category=category_1) subcategory_2.position = 1 subcategory_2.save() subcategory_3 = SubCategoryFactory(category=category_2) tuto_1 = PublishableContentFactory(type="TUTORIAL") tuto_1.subcategory.add(subcategory_1) tuto_1_draft = tuto_1.load_version() publish_content(tuto_1, tuto_1_draft, is_major_update=True) top_categories_tuto = topbar_publication_categories("TUTORIAL").get( "categories") expected = [(subcategory_1.title, subcategory_1.slug, category_1.slug)] self.assertEqual(top_categories_tuto[category_1.title], expected) tuto_2 = PublishableContentFactory(type="TUTORIAL") tuto_2.subcategory.add(subcategory_2) tuto_2_draft = tuto_2.load_version() publish_content(tuto_2, tuto_2_draft, is_major_update=True) top_categories_tuto = topbar_publication_categories("TUTORIAL").get( "categories") # New subcategory is now first is the list expected.insert( 0, (subcategory_2.title, subcategory_2.slug, category_1.slug)) self.assertEqual(top_categories_tuto[category_1.title], expected) article_1 = PublishableContentFactory(type="TUTORIAL") article_1.subcategory.add(subcategory_3) article_1_draft = tuto_2.load_version() publish_content(article_1, article_1_draft, is_major_update=True) # New article has no impact top_categories_tuto = topbar_publication_categories("TUTORIAL").get( "categories") self.assertEqual(top_categories_tuto[category_1.title], expected) top_categories_contents = topbar_publication_categories( ["TUTORIAL", "ARTICLE"]).get("categories") expected_2 = [(subcategory_3.title, subcategory_3.slug, category_2.slug)] self.assertEqual(top_categories_contents[category_1.title], expected) self.assertEqual(top_categories_contents[category_2.title], expected_2)
def test_validation_list(self): """ensure the behavior of the `validation:list` page (with filters)""" text = u'Ceci est un éléphant' tuto_not_reserved = PublishableContentFactory( type='TUTORIAL', author_list=[self.user_author]) tuto_reserved = PublishableContentFactory( type='TUTORIAL', author_list=[self.user_author]) article_not_reserved = PublishableContentFactory( type='ARTICLE', author_list=[self.user_author]) article_reserved = PublishableContentFactory( type='ARTICLE', author_list=[self.user_author]) all_contents = [ tuto_not_reserved, tuto_reserved, article_not_reserved, article_reserved ] reserved_contents = [tuto_reserved, article_reserved] # apply a filter to test category filter subcat = SubCategoryFactory() article_reserved.subcategory.add(subcat) article_reserved.save() # send in validation for content in all_contents: v = ValidationFactory(content=content, status='PENDING') v.date_proposition = datetime.datetime.now() v.version = content.sha_draft v.comment_authors = text if content in reserved_contents: v.validator = self.user_staff v.date_reserve = datetime.datetime.now() v.status = 'PENDING_V' v.save() # first, test access for public result = self.client.get(reverse('validation:list'), follow=False) self.assertEqual(result.status_code, 302) # get 302 → redirection to login # connect with author: self.assertEqual( self.client.login(username=self.user_author.username, password='******'), True) result = self.client.get(reverse('validation:list'), follow=False) self.assertEqual(result.status_code, 403) # get 403 not allowed self.client.logout() # connect with staff: self.assertEqual( self.client.login(username=self.user_staff.username, password='******'), True) response = self.client.get(reverse('validation:list'), follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 4) # a total of 4 contents in validation # test filters response = self.client.get(reverse('validation:list') + '?type=article', follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 2) # 2 articles response = self.client.get(reverse('validation:list') + '?type=tuto', follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 2) # 2 articles response = self.client.get(reverse('validation:list') + '?type=orphan', follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 2) # 2 not-reserved content for validation in validations: self.assertFalse(validation.content in reserved_contents) response = self.client.get(reverse('validation:list') + '?type=reserved', follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 2) # 2 reserved content for validation in validations: self.assertTrue(validation.content in reserved_contents) response = self.client.get(reverse('validation:list') + '?subcategory={}'.format(subcat.pk), follow=False) self.assertEqual(response.status_code, 200) # OK validations = response.context['validations'] self.assertEqual(len(validations), 1) # 1 content with this category self.assertEqual(validations[0].content, article_reserved) # the right content
def setUp(self): settings.overridden_zds_app = overridden_zds_app # don't build PDF to speed up the tests overridden_zds_app['content']['build_pdf_when_published'] = False self.staff = StaffProfileFactory().user settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' self.mas = ProfileFactory().user overridden_zds_app['member']['bot_account'] = self.mas.username bot = Group(name=overridden_zds_app['member']['bot_group']) bot.save() self.external = UserFactory( username=overridden_zds_app['member']['external_account'], password='******') self.beta_forum = ForumFactory( pk=overridden_zds_app['forum']['beta_forum_id'], category=CategoryFactory(position=1), position_in_category=1 ) # ensure that the forum, for the beta versions, is created self.licence = LicenceFactory() self.subcategory = SubCategoryFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user # create a tutorial self.tuto = PublishableContentFactory(type='TUTORIAL') self.tuto.authors.add(self.user_author) UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W') self.tuto.licence = self.licence self.tuto.subcategory.add(self.subcategory) self.tuto.save() # fill it with one part, containing one chapter, containing one extract self.tuto_draft = self.tuto.load_version() self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto) self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto) self.extract1 = ExtractFactory(container=self.chapter1, db_object=self.tuto) # then, publish it ! version = self.tuto_draft.current_version self.published = publish_content(self.tuto, self.tuto_draft, is_major_update=True) self.tuto.sha_public = version self.tuto.sha_draft = version self.tuto.public_version = self.published self.tuto.save() self.tutofeed = LastTutorialsFeedRSS()
def test_filters(self): """ Test filtering by category & tag """ subcategory2 = SubCategoryFactory() subcategory3 = SubCategoryFactory() tag2 = TagFactory() tag3 = TagFactory() # Add a new tuto & publish it article2 = PublishableContentFactory(type="ARTICLE") article2.authors.add(self.user_author) article2.licence = self.licence article2.subcategory.add(subcategory2) article2.tags.add(self.tag) article2.tags.add(tag2) article2.save() article2_draft = article2.load_version() article2.sha_public = article2.sha_draft = article2_draft.current_version article2.public_version = publish_content(article2, article2_draft, is_major_update=True) article2.save() # Default view ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [article2, self.article]) # Filter by subcategory self.articlefeed.query_params = {"subcategory": self.subcategory.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [self.article]) self.articlefeed.query_params = { "subcategory": f" {self.subcategory.slug} " } ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [self.article]) self.articlefeed.query_params = {"subcategory": subcategory2.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [article2]) self.articlefeed.query_params = {"subcategory": subcategory3.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, []) self.articlefeed.query_params = {"subcategory": "invalid"} self.assertRaises(Http404, self.articlefeed.items) # Filter by tag self.articlefeed.query_params = {"tag": self.tag.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [article2, self.article]) self.articlefeed.query_params = {"tag": tag2.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [article2]) self.articlefeed.query_params = {"tag": f" {tag2.slug} "} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, [article2]) self.articlefeed.query_params = {"tag": tag3.slug} ret = [item.content for item in self.articlefeed.items()] self.assertEqual(ret, []) self.articlefeed.query_params = {"tag": "invalid"} self.assertRaises(Http404, self.articlefeed.items)
def setUp(self): self.author = ProfileFactory() self.staff = StaffProfileFactory() self.licence = LicenceFactory() self.subcategory = SubCategoryFactory()