Beispiel #1
0
    def test_no_bad_slug_renaming_on_rename(self):
        """
        this test embodies the #5320 issue (first case simple workflow):

        - create an opinion with title "title"
        - create an article with the same title => it gets "-1" slug
        - rename opinion
        - make any update to article
        - try to access article
        """
        opinion = PublishedContentFactory(type="OPINION",
                                          title="title",
                                          author_list=[self.author.user],
                                          licence=self.licence)
        article = PublishedContentFactory(type="ARTICLE",
                                          title="title",
                                          author_list=[self.author.user],
                                          licence=self.licence)
        # login with author
        self.client.force_login(self.author.user)
        result = self.client.post(
            reverse("content:edit", args=[opinion.pk, opinion.slug]),
            {
                "title": "new title",
                "description": "subtitle",
                "introduction": "introduction",
                "conclusion": "conclusion",
                "type": "OPINION",
                "licence": self.licence.pk,
                "subcategory": self.subcategory.pk,
                "last_hash": opinion.load_version().compute_hash(),
                "image":
                (settings.BASE_DIR / "fixtures" / "logo.png").open("rb"),
            },
            follow=False,
        )
        self.assertEqual(result.status_code, 302)
        updated_opinion = PublishableContent.objects.get(pk=opinion.pk)
        self.assertEqual("new-title", updated_opinion.slug)
        result = self.client.get(article.get_absolute_url())
        self.assertEqual(200, result.status_code)
        result = self.client.post(
            reverse("content:edit", args=[article.pk, article.slug]),
            {
                "title": "title",
                "description": "subtitle",
                "introduction": "introduction",
                "conclusion": "conclusion",
                "type": "ARTICLE",
                "licence": self.licence.pk,
                "subcategory": self.subcategory.pk,
                "last_hash": article.load_version().compute_hash(),
                "image":
                (settings.BASE_DIR / "fixtures" / "logo.png").open("rb"),
            },
            follow=True,
        )
        self.assertEqual(200, result.status_code)
        result = self.client.get(article.get_absolute_url())
        self.assertEqual(200, result.status_code)
Beispiel #2
0
    def test_no_bad_slug_renaming_on_rename(self):
        """
        this test embodies the #5320 issue (first case simple workflow):

        - create an opinion with title "title"
        - create an article with the same title => it gets "-1" slug
        - rename opinion
        - make any update to article
        - try to access article
        """
        opinion = PublishedContentFactory(type='OPINION',
                                          title='title',
                                          author_list=[self.author.user],
                                          licence=self.licence)
        article = PublishedContentFactory(type='ARTICLE',
                                          title='title',
                                          author_list=[self.author.user],
                                          licence=self.licence)
        # login with author
        self.assertEqual(
            self.client.login(username=self.author.user.username,
                              password='******'), True)
        result = self.client.post(
            reverse('content:edit', args=[opinion.pk, opinion.slug]), {
                'title': 'new title',
                'description': 'subtitle',
                'introduction': 'introduction',
                'conclusion': 'conclusion',
                'type': 'OPINION',
                'licence': self.licence.pk,
                'subcategory': self.subcategory.pk,
                'last_hash': opinion.load_version().compute_hash(),
                'image':
                (settings.BASE_DIR / 'fixtures' / 'logo.png').open('rb')
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        updated_opinion = PublishableContent.objects.get(pk=opinion.pk)
        self.assertEqual('new-title', updated_opinion.slug)
        result = self.client.get(article.get_absolute_url())
        self.assertEqual(200, result.status_code)
        result = self.client.post(
            reverse('content:edit', args=[article.pk, article.slug]), {
                'title': 'title',
                'description': 'subtitle',
                'introduction': 'introduction',
                'conclusion': 'conclusion',
                'type': 'ARTICLE',
                'licence': self.licence.pk,
                'subcategory': self.subcategory.pk,
                'last_hash': article.load_version().compute_hash(),
                'image':
                (settings.BASE_DIR / 'fixtures' / 'logo.png').open('rb')
            },
            follow=True)
        self.assertEqual(200, result.status_code)
        result = self.client.get(article.get_absolute_url())
        self.assertEqual(200, result.status_code)
Beispiel #3
0
 def test_only_one_notif_on_major_update(self):
     NewPublicationSubscription.objects.get_or_create_active(self.user1, self.user2)
     content = PublishedContentFactory(author_list=[self.user2])
     notify_update(content, False, True)
     versioned = content.load_version()
     content.sha_draft = versioned.repo_update(introduction='new intro', conclusion='new conclusion',
                                               title=versioned.title)
     content.save(force_slug_update=False)
     publish_content(content, content.load_version(), True)
     notify_update(content, True, True)
     notifs = get_header_notifications(self.user1)['general_notifications']['list']
     self.assertEqual(1, len(notifs), str(notifs))
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)