def test_render_content_template(self):
        template = {
            '_id': 'foo',
            'template_name': 'test',
            'template_desks': ['sports'],
            'data': {
                'headline': 'Foo Template: {{item.headline}}',
                'body_html': 'This article has slugline: {{item.slugline}} and dateline: {{item.dateline["text"]}} '
                             'at {{item.versioncreated | format_datetime("Australia/Sydney", "%d %b %Y %H:%S %Z")}}',
                'urgency': 1, 'priority': 3,
                'dateline': {},
                'anpa_take_key': 'this is test',
                'place': ['Australia']
            }
        }

        item = {
            '_id': '123', 'headline': 'Test Template',
            'slugline': 'Testing', 'body_html': 'This is test story',
            'dateline': {
                'text': 'hello world'
            },
            'urgency': 4, 'priority': 6,
            'versioncreated': '2015-06-01T22:54:53+0000',
            'place': ['NSW']
        }

        updates = render_content_template(item, template)
        self.assertEqual(updates['headline'], 'Foo Template: Test Template')
        self.assertEqual(updates['urgency'], 1)
        self.assertEqual(updates['priority'], 3)
        self.assertEqual(updates['body_html'], 'This article has slugline: Testing and dateline: '
                                               'hello world at 02 Jun 2015 08:53 AEST')
        self.assertListEqual(updates['place'], ['Australia'])
Пример #2
0
    def test_headline_strip_tags(self):
        template = {'data': {'headline': ' test\nit<br>'}}

        updates = render_content_template({}, template)
        self.assertEqual('test it', updates['headline'])

        item = get_item_from_template(template)
        self.assertEqual('test it', item['headline'])
    def test_headline_strip_tags(self):
        template = {"data": {"headline": " test\nit<br>"}}

        updates = render_content_template({}, template)
        self.assertEqual("test it", updates["headline"])

        item = get_item_from_template(template)
        self.assertEqual("test it", item["headline"])
    def test_headline_strip_tags(self):
        template = {'data': {'headline': ' test\nit<br>'}}

        updates = render_content_template({}, template)
        self.assertEqual('test it', updates['headline'])

        item = get_item_from_template(template)
        self.assertEqual('test it', item['headline'])
Пример #5
0
    def test_render_content_template(self):
        template = {
            '_id': 'foo',
            'template_name': 'test',
            'template_desks': ['sports'],
            'data': {
                'headline':
                'Foo Template: {{item.headline}}',
                'body_html':
                'This article has slugline: {{item.slugline}} and dateline: {{item.dateline["text"]}} '
                'at {{item.versioncreated | format_datetime("Australia/Sydney", "%d %b %Y %H:%S %Z")}}',
                'urgency':
                1,
                'priority':
                3,
                'dateline': {},
                'anpa_take_key':
                'this is test',
                'place': ['Australia']
            }
        }

        item = {
            '_id': '123',
            'headline': 'Test Template',
            'slugline': 'Testing',
            'body_html': 'This is test story',
            'dateline': {
                'text': 'hello world'
            },
            'urgency': 4,
            'priority': 6,
            'versioncreated': '2015-06-01T22:54:53+0000',
            'place': ['NSW']
        }

        updates = render_content_template(item, template)
        self.assertEqual(updates['headline'], 'Foo Template: Test Template')
        self.assertEqual(updates['urgency'], 1)
        self.assertEqual(updates['priority'], 3)
        self.assertEqual(
            updates['body_html'],
            'This article has slugline: Testing and dateline: '
            'hello world at 02 Jun 2015 08:53 AEST')
        self.assertListEqual(updates['place'], ['Australia'])
Пример #6
0
    def kill_item(self, item):
        """
        Kill the item after applying the template.
        :param dict item: Item
        """
        # get the kill template
        template = get_resource_service("content_templates").get_template_by_name("kill")
        if not template:
            SuperdeskApiError.badRequestError(message="Kill Template missing.")

        # apply the kill template
        updates = render_content_template(item, template)
        # resolve the document version
        resolve_document_version(document=updates, resource=ARCHIVE, method="PATCH", latest_doc=item)
        # kill the item
        self.patch(item.get(config.ID_FIELD), updates)
        # insert into versions
        insert_into_versions(id_=item[config.ID_FIELD])
Пример #7
0
    def kill_item(self, item):
        """
        Kill the item after applying the template.
        :param dict item: Item
        """
        # get the kill template
        template = get_resource_service(
            'content_templates').get_template_by_name('kill')
        if not template:
            SuperdeskApiError.badRequestError(message="Kill Template missing.")

        # apply the kill template
        updates = render_content_template(item, template)
        # resolve the document version
        resolve_document_version(document=updates,
                                 resource=ARCHIVE,
                                 method='PATCH',
                                 latest_doc=item)
        # kill the item
        self.patch(item.get(config.ID_FIELD), updates)
        # insert into versions
        insert_into_versions(id_=item[config.ID_FIELD])
    def test_render_dateline_current_time(self):
        now = datetime(2020, 12, 8, 13, 0, 0)
        template = {
            "data": {
                "dateline": {
                    "located": {
                        "dateline": "city",
                        "tz": "Europe/Prague",
                        "city": "Prague",
                        "city_code": "Prague",
                        "country_code": "CZ",
                        "state_code": "52",
                    },
                    "date": now - timedelta(days=5),
                    "text": "PRAGUE, Dec 3 -",
                },
            }
        }

        with patch("apps.templates.content_templates.utcnow", return_value=now):
            updates = render_content_template({}, template)
        self.assertEqual("PRAGUE, Dec 8  -", updates["dateline"]["text"])
    def test_render_content_template(self):
        template = {
            "_id": "foo",
            "template_name": "test",
            "template_desks": ["sports"],
            "data": {
                "headline": "Foo Template: {{item.headline}}",
                "body_html": 'This article has slugline: {{item.slugline}} and dateline: {{item.dateline["text"]}} '
                'at {{item.versioncreated | format_datetime("Australia/Sydney", "%d %b %Y %H:%S %Z")}}',
                "urgency": 1,
                "priority": 3,
                "dateline": {},
                "anpa_take_key": "this is test",
                "place": ["Australia"],
            },
        }

        item = {
            "_id": "123",
            "headline": "Test Template",
            "slugline": "Testing",
            "body_html": "This is test story",
            "dateline": {"text": "hello world"},
            "urgency": 4,
            "priority": 6,
            "versioncreated": "2015-06-01T22:54:53+0000",
            "place": ["NSW"],
        }

        updates = render_content_template(item, template)
        self.assertEqual(updates["headline"], "Foo Template: Test Template")
        self.assertEqual(updates["urgency"], 1)
        self.assertEqual(updates["priority"], 3)
        self.assertEqual(
            updates["body_html"],
            "This article has slugline: Testing and dateline: " "hello world at 02 Jun 2015 08:53 AEST",
        )
        self.assertListEqual(updates["place"], ["Australia"])