예제 #1
0
    def test_fetch_to_jimi(self, update_renditions_mock):
        service = OrangelogicSearchProvider(self.provider)

        update_renditions_mock.side_effects = set_rendition

        self.app.media.get.return_value = io.BytesIO(
            read_fixture('9e627f74b97841b3b8562b6547ada9c7-d1538139479c43e88021152.jpg', 'rb')
        )

        with HTTMock(auth_ok, fetch_ok):
            with patch.dict(superdesk.resources, resources):
                fetched = service.fetch({})
            update_renditions_mock.assert_called_once_with(
                fetched,
                'https://example.com/htm/GetDocumentAPI.aspx?F=TRX&DocID=2RLQZBCB4R4R4&token=token.foo',
                None,
            )

        self.assertEqual('picture', fetched['type'])
        self.assertIsInstance(fetched['firstcreated'], datetime)

        # populate ids
        fetched['family_id'] = fetched['guid']
        fetched['unique_id'] = 1

        with patch.dict(superdesk.resources, resources):
            formatter = JimiFormatter()
            xml = formatter.format(fetched, {})[0][1]

        root = etree.fromstring(xml.encode(formatter.ENCODING))

        self.assertEqual('Pictures', root.find('Services').text)

        item = root.find('ContentItem')

        self.assertEqual('Zhang Yuwei', item.find('Byline').text)
        self.assertEqual('I', item.find('Category').text)
        self.assertEqual('News - Optional', item.find('Ranking').text)
        self.assertEqual('5', item.find('RankingValue').text)
        self.assertEqual('THE ASSOCIATED PRESS', item.find('Credit').text)
        self.assertEqual('Virus Outbreak China Vaccine', item.find('SlugProper').text)
        self.assertEqual('Unknown AP', item.find('Source').text)
        self.assertEqual('Beijing', item.find('City').text)
        self.assertEqual('China', item.find('Country').text)
        self.assertEqual('Beijing;;China', item.find('Placeline').text)
        # self.assertEqual('XIN902', item.find('OrigTransRef').text)
        self.assertEqual('SUB', item.find('BylineTitle').text)
        self.assertEqual('NHG', item.find('CaptionWriter').text)
        self.assertEqual('Xinhua', item.find('Copyright').text)
        self.assertIn("In this April 10, 2020, photo released by Xinhua News Agency, a staff",
                      item.find('EnglishCaption').text)
        self.assertEqual('2020-04-12T00:09:37', item.find('DateTaken').text)
        self.assertEqual('NO SALES, PHOTO RELEASED BY XINHUA NEWS AGENCY APRIL 10, 2020 PHOTO',
                         item.find('SpecialInstructions').text)
        self.assertEqual('Unknown AP', item.find('ArchiveSources').text)
        self.assertEqual('9e627f74b97841b3b8562b6547ada9c7', item.find('CustomField1').text)
        self.assertEqual('Xinhua', item.find('CustomField6').text)
        self.assertEqual('9e627f74b97841b3b8562b6547ada9c7', item.find('SystemSlug').text)
예제 #2
0
    def test_fetch_to_jimi(self, update_renditions_mock):
        service = OrangelogicSearchProvider(self.provider)

        update_renditions_mock.side_effects = set_rendition

        self.app.media.get.return_value = io.BytesIO(
            read_fixture(
                "9e627f74b97841b3b8562b6547ada9c7-d1538139479c43e88021152.jpg",
                "rb"))

        with HTTMock(auth_ok, fetch_ok):
            with patch.dict(superdesk.resources, resources):
                fetched = service.fetch({})
            update_renditions_mock.assert_called_once_with(
                fetched,
                "https://example.com/htm/GetDocumentAPI.aspx?F=TRX&DocID=2RLQZBCB4R4R4&token=token.foo",
                None,
            )

        self.assertEqual("picture", fetched["type"])
        self.assertIsInstance(fetched["firstcreated"], datetime)

        # populate ids
        fetched["family_id"] = fetched["guid"]
        fetched["unique_id"] = 1

        with patch.dict(superdesk.resources, resources):
            formatter = JimiFormatter()
            xml = formatter.format(fetched, {})[0][1]

        root = etree.fromstring(xml.encode(formatter.ENCODING))

        self.assertEqual("Pictures", root.find("Services").text)

        item = root.find("ContentItem")

        self.assertEqual("Zhang Yuwei", item.find("Byline").text)
        self.assertEqual("I", item.find("Category").text)
        self.assertEqual("News - Optional", item.find("Ranking").text)
        self.assertEqual("5", item.find("RankingValue").text)
        self.assertEqual("THE ASSOCIATED PRESS", item.find("Credit").text)
        self.assertEqual("Virus Outbreak China Vaccine",
                         item.find("SlugProper").text)
        self.assertEqual("Unknown AP", item.find("Source").text)
        self.assertEqual("Beijing", item.find("City").text)
        self.assertEqual("China", item.find("Country").text)
        self.assertEqual("Beijing;;China", item.find("Placeline").text)
        # self.assertEqual('XIN902', item.find('OrigTransRef').text)
        self.assertEqual("SUB", item.find("BylineTitle").text)
        self.assertEqual("NHG", item.find("CaptionWriter").text)
        self.assertEqual("Xinhua", item.find("Copyright").text)
        self.assertIn(
            "In this April 10, 2020, photo released by Xinhua News Agency, a staff",
            item.find("EnglishCaption").text,
        )
        self.assertEqual("2020-04-12T00:09:37", item.find("DateTaken").text)
        self.assertEqual(
            "NO SALES, PHOTO RELEASED BY XINHUA NEWS AGENCY APRIL 10, 2020 PHOTO",
            item.find("SpecialInstructions").text,
        )
        self.assertEqual("Unknown AP", item.find("ArchiveSources").text)
        self.assertEqual("9e627f74b97841b3b8562b6547ada9c7",
                         item.find("CustomField1").text)
        self.assertEqual("Xinhua", item.find("CustomField6").text)
        self.assertEqual("9e627f74b97841b3b8562b6547ada9c7",
                         item.find("SystemSlug").text)