def setUp(self): 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.user_author = ProfileFactory().user self.staff = StaffProfileFactory().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.save() 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)
def setUp(self): 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.client.force_login(self.user1)
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.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): self.overridden_zds_app["member"]["bot_account"] = ProfileFactory().user.username self.licence = LicenceFactory() self.user_author = ProfileFactory().user self.user_staff = StaffProfileFactory().user self.user_guest = ProfileFactory().user
def setUp(self): # Create a user self.author = ProfileFactory() # Create licenses self.license_1 = LicenceFactory() self.license_2 = LicenceFactory() # Create a content self.content = PublishableContentFactory( author_list=[self.author.user], add_license=False) # Get information to be reused in tests self.form_url = reverse("content:edit-license", kwargs={"pk": self.content.pk}) # Log in with an authorized user (e.g the author of the content) to perform the tests self.client.force_login(self.author.user)
def get_small_opinion(self): """ Returns a published opinion without extract. """ opinion = PublishableContentFactory(type="OPINION") opinion.authors.add(self.user_author) UserGalleryFactory(gallery=opinion.gallery, user=self.user_author, mode="W") opinion.licence = LicenceFactory() opinion.save() opinion_draft = opinion.load_version() return publish_content(opinion, opinion_draft)
def setUp(self): self.licence = LicenceFactory() self.user_author = ProfileFactory().user self.old_registry = { key: value for key, value in PublicatorRegistry.get_all_registered() } self.old_build_pdf_when_published = self.overridden_zds_app["content"][ "build_pdf_when_published"] self.overridden_zds_app["content"]["build_pdf_when_published"] = True
def get_published_content(self, author, user_staff, nb_part=1, nb_chapter=1, nb_extract=1): bigtuto = PublishableContentFactory(type="TUTORIAL") bigtuto.authors.add(author) UserGalleryFactory(gallery=bigtuto.gallery, user=author, mode="W") bigtuto.licence = LicenceFactory() bigtuto.save() # populate the bigtuto bigtuto_draft = bigtuto.load_version() for i in range(nb_part): part = ContainerFactory(parent=bigtuto_draft, db_object=bigtuto) for j in range(nb_chapter): chapter = ContainerFactory(parent=part, db_object=bigtuto) for k in range(nb_extract): ExtractFactory(container=chapter, db_object=bigtuto) # connect with author: self.client.force_login(author) # ask validation self.client.post( reverse("validation:ask", kwargs={"pk": bigtuto.pk, "slug": bigtuto.slug}), {"text": "ask for validation", "source": "", "version": bigtuto_draft.current_version}, follow=False, ) # login with staff and publish self.client.force_login(user_staff) validation = Validation.objects.filter(content=bigtuto).last() self.client.post( reverse("validation:reserve", kwargs={"pk": validation.pk}), {"version": validation.version}, follow=False ) # accept self.client.post( reverse("validation:accept", kwargs={"pk": validation.pk}), {"text": "accept validation", "is_major": True, "source": ""}, follow=False, ) self.client.logout() published = PublishedContent.objects.filter(content=bigtuto).first() self.assertIsNotNone(published) return published
def _generate(cls, create, attrs): # These parameters are only used inside _generate() and won't be saved in the database, # which is why we use attrs.pop() (they are removed from attrs). light = attrs.pop("light", True) author_list = attrs.pop("author_list", None) add_license = attrs.pop("add_license", True) add_category = attrs.pop("add_category", True) # This parameter will be saved in the database, # which is why we use attrs.get() (it stays in attrs). licence = attrs.get("licence", None) auths = author_list or [] if add_license: given_licence = licence or Licence.objects.first() if isinstance(given_licence, str) and given_licence: given_licence = Licence.objects.filter( title=given_licence).first() or Licence.objects.first() licence = given_licence or LicenceFactory() text = text_content if not light: text = tricky_text_content intro_content = attrs.pop("intro", text) conclusion_content = attrs.pop("conclusion", text) publishable_content = super()._generate(create, attrs) publishable_content.gallery = GalleryFactory() publishable_content.licence = licence for auth in auths: publishable_content.authors.add(auth) if add_category: publishable_content.subcategory.add(SubCategoryFactory()) publishable_content.save() for author in publishable_content.authors.all(): UserGalleryFactory(user=author, gallery=publishable_content.gallery, mode="W") init_new_repo(publishable_content, intro_content, conclusion_content) return publishable_content
def test_update_manifest(self): opts = {} path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "balise_audio" / "manifest.json" path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "balise_audio" / "manifest2.json" args = [str(path_manifest2)] shutil.copy(path_manifest1, path_manifest2) LicenceFactory(code="CC BY") call_command("upgrade_manifest_to_v2", *args, **opts) manifest = path_manifest2.open("r") json = json_handler.loads(manifest.read()) self.assertTrue("version" in json) self.assertTrue("licence" in json) self.assertTrue("children" in json) self.assertEqual(len(json["children"]), 3) self.assertEqual(json["children"][0]["object"], "extract") os.unlink(args[0]) path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "big_tuto_v1" / "manifest.json" path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "big_tuto_v1" / "manifest2.json" args = [str(path_manifest2)] shutil.copy(path_manifest1, path_manifest2) call_command("upgrade_manifest_to_v2", *args, **opts) manifest = path_manifest2.open("r") json = json_handler.loads(manifest.read()) os.unlink(args[0]) self.assertTrue("version" in json) self.assertTrue("licence" in json) self.assertTrue("children" in json) self.assertEqual(len(json["children"]), 5) self.assertEqual(json["children"][0]["object"], "container") self.assertEqual(len(json["children"][0]["children"]), 3) self.assertEqual(len(json["children"][0]["children"][0]["children"]), 3) path_manifest1 = settings.BASE_DIR / "fixtures" / "tuto" / "article_v1" / "manifest.json" path_manifest2 = settings.BASE_DIR / "fixtures" / "tuto" / "article_v1" / "manifest2.json" args = [path_manifest2] shutil.copy(path_manifest1, path_manifest2) call_command("upgrade_manifest_to_v2", *args, **opts) manifest = path_manifest2.open("r") json = json_handler.loads(manifest.read()) self.assertTrue("version" in json) self.assertTrue("licence" in json) self.assertTrue("children" in json) self.assertEqual(len(json["children"]), 1) os.unlink(args[0])
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=ForumCategoryFactory(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() self.external = UserFactory( username=self.overridden_zds_app["member"]["external_account"], password="******")
def setUp(self): # Create a user self.author = ProfileFactory() # Create a license self.license = LicenceFactory() # Create a content self.content = PublishableContentFactory( author_list=[self.author.user], add_license=False) # Get information to be reused in tests self.form_url = reverse("content:edit-license", kwargs={"pk": self.content.pk}) self.error_messages = EditContentLicenseForm.declared_fields[ "license"].error_messages self.success_message_license = EditContentLicense.success_message_license self.success_message_profile_update = EditContentLicense.success_message_profile_update # Log in with an authorized user (e.g the author of the content) to perform the tests self.client.force_login(self.author.user)
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.add_participant(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): # Create users self.author = ProfileFactory().user self.staff = StaffProfileFactory().user self.outsider = ProfileFactory().user # Create a license self.licence = LicenceFactory() # Create a content self.content = PublishableContentFactory(author_list=[self.author]) # Get information to be reused in tests self.form_url = reverse("content:edit-license", kwargs={"pk": self.content.pk}) self.form_data = { "license": self.licence.pk, "update_preferred_license": False } self.content_data = {"pk": self.content.pk, "slug": self.content.slug} self.content_url = reverse("content:view", kwargs=self.content_data) self.login_url = reverse("member-login") + "?next=" + self.form_url
def test_move_no_slug_update(self): """ this test comes from issue #3328 (https://github.com/zestedesavoir/zds-site/issues/3328) telling it is tricky is kind of euphemism. :return: """ LicenceFactory(code="CC BY") self.client.force_login(self.user_author) draft_zip_path = join(dirname(__file__), "fake_lasynchrone-et-le-multithread-en-net.zip") result = self.client.post( reverse("content:import-new"), { "archive": open(draft_zip_path, "rb"), "subcategory": self.subcategory.pk }, follow=False, ) self.assertEqual(result.status_code, 302) tuto = PublishableContent.objects.last() published = publish_content(tuto, tuto.load_version(), True) tuto.sha_public = tuto.sha_draft tuto.public_version = published tuto.save() extract1 = tuto.load_version().children[0] # test moving up smoothly result = self.client.post( reverse("content:move-element"), { "child_slug": extract1.slug, "first_level_slug": "", "container_slug": tuto.slug, "moving_method": "down", "pk": tuto.pk, }, follow=True, ) self.assertEqual(200, result.status_code) self.assertTrue(isdir(tuto.get_repo_path()))
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.client.force_login(self.user_author) 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 setUp(self): self.mas = ProfileFactory().user self.overridden_zds_app["member"]["bot_account"] = self.mas.username self.licence = LicenceFactory() self.user_author = ProfileFactory().user self.staff = StaffProfileFactory().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.save() 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.old_registry = { key: value for key, value in PublicatorRegistry.get_all_registered() } class TestPdfPublicator(Publicator): def publish(self, md_file_path, base_name, **kwargs): with Path(base_name + ".pdf").open("w") as f: f.write("bla") shutil.copy2( str(Path(base_name + ".pdf")), str(Path(md_file_path.replace("__building", "")).parent)) PublicatorRegistry.registry["pdf"] = TestPdfPublicator()
def setUp(self): self.author = ProfileFactory() self.staff = StaffProfileFactory() self.licence = LicenceFactory() self.subcategory = SubCategoryFactory()