예제 #1
0
    def test_docset_index_url_change(self):
        with self.debugMock() as mocktempdir:
            mocktempdir.set_subprefix("_scenario_10_")
            bundle_A_V1 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A)
            tasks.publish_drafts(bundle_A_V1.pk)  # simulate publish from UI

            docset = SalesforceArticles(bundle_A_V1.docset_id).sf_docset
            index_article_id = docset[
                settings.SALESFORCE_DOCSET_INDEX_REFERENCE_FIELD]
            index_article = self.salesforce.find_article_by_name(
                "SFDO-BundleA-Documentation", "Online")
            assert index_article["KnowledgeArticleId"] == index_article_id

            mocktempdir.set_subprefix("_scenario_11_")
            # this new bundle has a different UrlName for the index article
            # so it should end up with a new ID
            # which should change the docset ("Hub_Product_Description__c") too
            bundle_A_V6 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A_V6)
            tasks.publish_drafts(bundle_A_V6.pk)  # simulate publish from UI

            docset = SalesforceArticles(bundle_A_V1.docset_id).sf_docset
            index_article_id2 = docset[
                settings.SALESFORCE_DOCSET_INDEX_REFERENCE_FIELD]
            assert index_article_id != index_article_id2
            new_index_article = self.salesforce.find_article_by_name(
                "SFDO-BundleA-Documentation-URL2", "Online")
            assert new_index_article["KnowledgeArticleId"] == index_article_id2
            try:
                self.salesforce.find_article_by_name(
                    "SFDO-BundleA-Documentation", "Online")
                assert False, "Should not get to this line of code"
            except IndexError:
                pass  # we're good
예제 #2
0
 def test_same_bundle_force_republish(self):
     """Allow publishing identical bundle twice in a row if settings allow."""
     bundle_A = self.process_bundle_from_webhook(
         fake_easydita.fake_webhook_body_doc_A)
     tasks.publish_drafts(bundle_A.pk)  # simulate publish from UI
     # if the setting did not do what it is supposed to do, the next line
     # would throw an exception, as it does in test_same_bundle_push_and_publish_twice
     bundle_A2 = self.process_bundle_from_webhook(
         fake_easydita.fake_webhook_body_doc_A)
     tasks.publish_drafts(bundle_A2.pk)  # simulate publish from UI
예제 #3
0
    def test_same_bundle_push_and_publish_twice(self):
        """You can't publish identical bundles back to back usually."""
        bundle_A = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A)
        tasks.publish_drafts(bundle_A.pk)  # simulate publish from UI
        with self.assertRaises(SfdocError) as e:
            self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A)

        assert str(e.exception) == 'No articles or images changed'
예제 #4
0
 def test_same_bundle_old_bundle(self):
     """Should be able to revert a publish"""
     bundle_A = self.process_bundle_from_webhook(
         fake_easydita.fake_webhook_body_doc_A)
     tasks.publish_drafts(bundle_A.pk)  # simulate publish from UI
     bundle_A_V2 = self.process_bundle_from_webhook(
         fake_easydita.fake_webhook_body_doc_A_V2)
     tasks.publish_drafts(bundle_A_V2.pk)  # simulate publish from UI
     bundle_A = self.process_bundle_from_webhook(
         fake_easydita.fake_webhook_body_doc_A)
     tasks.publish_drafts(bundle_A.pk)  # simulate publish from UI
예제 #5
0
    def test_changes(self):
        # 1. Import a bundle
        bundle_A_V1 = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A)
        self.assertStringNotInArticles(settings.AWS_S3_DRAFT_IMG_DIR, "Online")

        # 2. Publish the first bundle.
        tasks.publish_drafts(bundle_A_V1.pk)  # simulate publish from UI
        # 3. Now import a different bundle.
        bundle_B = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_B)
        # 4. Publish the second bundle.
        tasks.publish_drafts(bundle_B.pk)  # simulate publish from UI

        # 5.
        #    Change an article's title. Check that it updates.
        #    Change another article's summary. Check that it updates.
        #    Check that all articles from the second bundle are included still. (TBD)
        bundle_A_V2 = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A_V2)
        self.assertIn(
            "Article A3! Updated",
            self.article_titles(self.salesforce.get_articles("draft")),
        )
        tasks.publish_drafts(bundle_A_V2.pk)  # simulate publish from UI
        self.assertIn(
            "Article A3! Updated",
            self.article_titles(self.salesforce.get_articles("online")),
        )

        kav = self.get_article("Article A2", "online")
        summary = kav["Summary"]
        # Updated article summary
        self.assertIn("This is a test article. Updated!", summary)

        public_articles = self.salesforce.get_articles("online")
        expected_articles = (fake_easydita.ditamap_A_V2_titles +
                             fake_easydita.ditamap_B_titles)

        self.assertTitles(public_articles, expected_articles)
        self.assertNoImagesScheduledForDeletion()
예제 #6
0
    def test_two_bundles_interleaved(self):
        """Test two bundles being ready for review at the same time"""
        with self.debugMock() as mocktempdir:
            mocktempdir.set_subprefix("_scenario_1_")
            assert os.path.exists(TESTING_CACHE)

            # 1. Import a bundle
            bundle_A_V1 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A)
            assert bundle_A_V1.status == bundle_A_V1.STATUS_DRAFT

            self.assertStringNotInArticles(settings.AWS_S3_PUBLIC_IMG_DIR,
                                           "DRAFT")
            assert os.path.exists(TESTING_CACHE)

            # Check that we imported articles into both local DB and SF Org
            # compare # of database models to draft articles
            sforg_article_list = self.salesforce.get_articles("draft")
            self.assertEqual(len(sforg_article_list),
                             len(Article.objects.all()))
            self.assertTitles(
                sforg_article_list,
                fake_easydita.ditamap_A_titles,
            )

            # check that we created the right number of "NEW" status models in PG
            pg_models = Article.objects.filter(bundle=bundle_A_V1)
            self.assertEqual(len(sforg_article_list), len(pg_models))

            self.assertNoImagesScheduledForDeletion()

            # 2. Now import a different bundle. Check that the new articles
            #    are drafts and the old ones are still draft also.
            mocktempdir.set_subprefix("_scenario_2_")
            bundle_B = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_B)
            sforg_article_list = self.salesforce.get_articles("draft")

            # check that they were added to SF
            self.assertTitles(
                sforg_article_list, fake_easydita.ditamap_A_titles +
                fake_easydita.ditamap_B_titles)

            # check that we created "NEW" status models in PG for all bundle_B
            # objects
            pg_models = Article.objects.filter(bundle=bundle_B, status="N")
            self.assertTitles(pg_models, fake_easydita.ditamap_B_titles)

            # check that no articles were deleted or changed.
            other_stuff = Article.objects.filter(bundle=bundle_B).exclude(
                status="N")
            assert not other_stuff
            self.assertNoImagesScheduledForDeletion()

            # 3. Add another bundle "bundle_A" and ensure that it stays queued, not processing.
            bundle_A_V2 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A_V2)
            assert bundle_A_V2.status == bundle_A_V2.STATUS_QUEUED

            # 4. Publish the first bundle. Check that the articles are published.
            mocktempdir.set_subprefix("_scenario_4_")
            tasks.publish_drafts(bundle_A_V1.pk)  # simulate publish from UI
            self.assertStringNotInArticles(settings.AWS_S3_DRAFT_IMG_DIR,
                                           "Online")
            self.assertTitles(
                self.salesforce.get_articles("online"),
                fake_easydita.ditamap_A_titles,
            )
            self.assertNoImagesScheduledForDeletion()

            # bundle B stuff should still be unpublished
            self.assertTitles(self.salesforce.get_articles("draft"),
                              fake_easydita.ditamap_B_titles)

            # 5. Publish the second bundle. Check that both sets of articles
            #    stay published.
            mocktempdir.set_subprefix("_scenario_5_")

            tasks.publish_drafts(bundle_B.pk)  # simulate publish from UI
            self.assertStringNotInArticles(settings.AWS_S3_DRAFT_IMG_DIR,
                                           "Online")

            self.assertTitles(
                self.salesforce.get_articles("online"),
                fake_easydita.ditamap_A_titles +
                fake_easydita.ditamap_B_titles,
            )
            # no articles should still be in draft
            self.assertEqual(self.salesforce.get_articles("draft"), [])
예제 #7
0
    def test_images(self):
        # 1. Import a bundle
        bundle_A_V1 = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A)
        new_images = list(
            Image.objects.filter(status=Image.STATUS_NEW, bundle=bundle_A_V1))
        assert (len(new_images) == 3)
        assert not Image.objects.filter(status=Image.STATUS_CHANGED,
                                        bundle=bundle_A_V1)
        assert not Image.objects.filter(status=Image.STATUS_DELETED,
                                        bundle=bundle_A_V1)

        # 2. Publish the first bundle.
        tasks.publish_drafts(bundle_A_V1.pk)  # simulate publish from UI

        # 3. Add an image. Check that it ends up on S3.
        bundle_A_V3 = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A_V3)
        testing_file = "Testing/Paul_test/bundleA/CategoryA/Article1/images/small.png"
        draft_img_s3_object = os.path.join(settings.AWS_S3_DRAFT_IMG_DIR,
                                           bundle_A_V3.docset_id + "/",
                                           testing_file)
        self.assertS3ObjectExists(draft_img_s3_object)
        new_images = list(
            Image.objects.filter(status=Image.STATUS_NEW, bundle=bundle_A_V3))
        assert (len(new_images) == 1)
        assert not Image.objects.filter(status=Image.STATUS_CHANGED)
        assert not Image.objects.filter(status=Image.STATUS_DELETED)

        self.assertImgUrlInArticle("Article A1", "draft", draft_img_s3_object)

        tasks.publish_drafts(bundle_A_V3.pk)  # simulate publish from UI

        # image should be on S3/drafts now
        # image should be on S3 / now
        public_img_s3_object = draft_img_s3_object.replace(
            settings.AWS_S3_DRAFT_IMG_DIR, settings.AWS_S3_PUBLIC_IMG_DIR)

        self.assertS3ObjectExists(public_img_s3_object)

        # image should be referred to in published version
        kav = self.get_article("Article A1", "online")
        self.assertImgUrlInArticle("Article A1", "online",
                                   public_img_s3_object)
        self.assertS3ObjectExists(public_img_s3_object)

        # 4. Remove an image. Checks that it disappears from HTML and S3.

        # we haven't deleted any images yet so the DB should have no records
        # of this type:
        deleted_images_in_db = Image.objects.filter(
            status=Image.STATUS_DELETED)
        self.assertEqual(len(deleted_images_in_db), 0)

        numdraftimages = len(
            list(
                self.bucket.objects.filter(
                    Prefix=settings.AWS_S3_DRAFT_IMG_DIR)))
        self.assertTrue(numdraftimages, "Should be draft images!")
        numpubimages = len(
            list(
                self.bucket.objects.filter(
                    Prefix=settings.AWS_S3_PUBLIC_IMG_DIR)))
        self.assertTrue(numpubimages, "Should be public images!")

        bundle_A_V4 = self.process_bundle_from_webhook(
            fake_easydita.fake_webhook_body_doc_A_V4)
        kav = self.get_article("Article A1", "draft")

        # now we've deleted an image, so there should be 1 and only 1 such
        # record. This is the first one we have deleted
        self.assertEqual(
            Image.objects.filter(status=Image.STATUS_DELETED).count(), 1)
        self.assertEqual(
            Image.objects.filter(status=Image.STATUS_NEW,
                                 bundle=bundle_A_V4).count(), 0)
        self.assertEqual(
            Image.objects.filter(status=Image.STATUS_CHANGED,
                                 bundle=bundle_A_V4).count(), 0)

        # should be 1 less image on S3 drafts
        numdraftimages_now = len(
            list(
                self.bucket.objects.filter(
                    Prefix=settings.AWS_S3_DRAFT_IMG_DIR)))
        self.assertEqual(numdraftimages_now, numdraftimages - 1)
        numpubimages_now = len(
            list(
                self.bucket.objects.filter(
                    Prefix=settings.AWS_S3_PUBLIC_IMG_DIR)))
        self.assertEqual(numpubimages_now, numpubimages)

        self.assertNotIn("small.png",
                         kav[settings.SALESFORCE_ARTICLE_BODY_FIELD])
        self.assertS3ObjectDoesNotExist(draft_img_s3_object)

        tasks.publish_drafts(bundle_A_V4.pk)
        kav = self.get_article("Article A1", "online")
        self.assertNotIn("small.png",
                         kav[settings.SALESFORCE_ARTICLE_BODY_FIELD])

        # should be 1 less public image on S3
        numpubimages_now = len(
            list(
                self.bucket.objects.filter(
                    Prefix=settings.AWS_S3_PUBLIC_IMG_DIR)))
        self.assertEqual(numpubimages_now, numpubimages - 1)

        self.assertS3ObjectDoesNotExist(public_img_s3_object)
예제 #8
0
    def test_remove_article(self):
        with self.debugMock() as mocktempdir:
            # 1. Import a bundle
            mocktempdir.set_subprefix("_scenario_1_")
            bundle_A_V1 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A)
            articles = Article.objects.filter(bundle=bundle_A_V1,
                                              status__in=(Article.STATUS_NEW))
            self.assertTitles(articles, fake_easydita.ditamap_A_titles)
            self.assertTitles(self.salesforce.get_articles("draft"),
                              fake_easydita.ditamap_A_titles)

            # 2. User publishes the first bundle.
            mocktempdir.set_subprefix("_scenario_2_")
            tasks.publish_drafts(bundle_A_V1.pk)  # simulate publish from UI
            self.assertTitles(self.salesforce.get_articles("online"),
                              fake_easydita.ditamap_A_titles)

            # 3. Now import a different bundle with our to-be-deleted file
            mocktempdir.set_subprefix("_scenario_3_")
            bundle_B = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_B)
            articles = Article.objects.filter(bundle=bundle_B,
                                              status__in=(Article.STATUS_NEW))
            self.assertTitles(articles, fake_easydita.ditamap_B_titles)
            self.assertTitles(self.salesforce.get_articles("draft"),
                              fake_easydita.ditamap_B_titles)

            # should be able to find the article we're going to delete later
            self.assertIn(
                "Article 2, Bundle B",
                self.article_titles(self.salesforce.get_articles("draft")),
            )

            # 4. Publish the second bundle.
            mocktempdir.set_subprefix("_scenario_4_")
            tasks.publish_drafts(bundle_B.pk)  # simulate publish from UI

            # 5. Import a bundle with a single missing article and check that it disappears as a draft
            mocktempdir.set_subprefix("_scenario_5_")
            bundle_B_V3 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_b_V3)

            deleted = Article.objects.filter(bundle=bundle_B_V3, status="D")

            self.assertTitles(deleted, ["Article 2, Bundle B"])

            articles = self.salesforce.get_articles("draft")
            assert "Product Documentation" in (article["Article_Type__c"]
                                               for article in articles)
            assert "End Users;IT/Developers;LGBTQIA+" in (
                article["Topics__c"] for article in articles)

            # 6. Publish the bundle and check that it disappears as public
            mocktempdir.set_subprefix("_scenario_6_")
            self.assertTitles(
                self.salesforce.get_articles("online"),
                fake_easydita.ditamap_A_titles +
                fake_easydita.ditamap_B_titles)
            tasks.publish_drafts(bundle_B_V3.pk)  # simulate publish from UI
            self.assertTitles(
                self.salesforce.get_articles("online"),
                fake_easydita.ditamap_A_titles +
                fake_easydita.ditamap_B_V3_titles)
            self.assertNotIn(
                "Article 2, Bundle B",
                self.article_titles(self.salesforce.get_articles("online")),
            )

            # 7. Import and publish a version of the the other bundle and ensure that the first draft doesn't reappear
            mocktempdir.set_subprefix("_scenario_7_")
            bundle_A_V2 = self.process_bundle_from_webhook(
                fake_easydita.fake_webhook_body_doc_A_V2)
            tasks.publish_drafts(bundle_A_V2.pk)  # simulate publish from UI

            self.assertTitles(
                self.salesforce.get_articles("online"),
                fake_easydita.ditamap_A_V2_titles +
                fake_easydita.ditamap_B_V3_titles)
            self.assertNotIn(
                "Article 2, Bundle B",
                self.article_titles(self.salesforce.get_articles("online")),
            )