Esempio n. 1
0
 def _create_tag(self, label, entity_type):
     tag = Tag(label, entity_type)
     if tag.code in self.pinned:
         tag.pinned = True
     # XXX it is not understood by the writer, whether we really need this.
     # It was kept from the former implementation in `zeit.cms.tagging`.
     tag.__parent__ = self
     return tag
Esempio n. 2
0
 def _create_tag(self, label, entity_type):
     tag = Tag(label, entity_type)
     if tag.code in self.pinned:
         tag.pinned = True
     # XXX it is not understood by the writer, whether we really need this.
     # It was kept from the former implementation in `zeit.cms.tagging`.
     tag.__parent__ = self
     return tag
Esempio n. 3
0
 def test_update_should_discard_disabled_tags(self):
     extract_keywords = 'zeit.retresco.connection.TMS.extract_keywords'
     with mock.patch(extract_keywords) as extract_keywords:
         extract_keywords.return_value = [Tag('Foo', ''), Tag('Bar', '')]
         content = create_testcontent()
         tagger = Tagger(content)
         tagger.update()
         self.assertEqual(2, len(tagger))
         del tagger[u'☃Foo']
         tagger.update()
         self.assertEqual([u'☃Bar'], list(tagger))
Esempio n. 4
0
 def test_links_to_topicpages_are_retrieved_from_tms(self):
     content = create_testcontent()
     tagger = Tagger(content)
     article_keywords = 'zeit.retresco.connection.TMS.get_article_keywords'
     with mock.patch(article_keywords) as article_keywords:
         tag1 = Tag('Foo', '')
         tag1.link = 'thema/foo'
         tag2 = Tag('Bar', '')
         article_keywords.return_value = [tag1, tag2]
         self.assertEqual({
             tag1.uniqueId: 'http://localhost/live-prefix/thema/foo',
             tag2.uniqueId: None,
         }, tagger.links)
Esempio n. 5
0
 def test_links_to_topicpages_are_retrieved_from_tms(self):
     content = create_testcontent()
     tagger = Tagger(content)
     article_keywords = 'zeit.retresco.connection.TMS.get_article_keywords'
     with mock.patch(article_keywords) as article_keywords:
         tag1 = Tag('Foo', '')
         tag1.link = 'thema/foo'
         tag2 = Tag('Bar', '')
         article_keywords.return_value = [tag1, tag2]
         self.assertEqual(
             {
                 tag1.uniqueId: 'http://localhost/live-prefix/thema/foo',
                 tag2.uniqueId: None,
             }, tagger.links)
Esempio n. 6
0
 def test_update_should_not_duplicate_pinned_tags(self):
     # this is a rather tricky edge case:
     # when we pin a manual tag first, and then also pin a tag that
     # comes in via update() again, we used to screw it up,
     # since we compared against a generator multiple times
     extract_keywords = 'zeit.retresco.connection.TMS.extract_keywords'
     with mock.patch(extract_keywords) as extract_keywords:
         extract_keywords.return_value = [Tag('Foo', ''), Tag('Bar', '')]
         content = create_testcontent()
         tagger = Tagger(content)
         tagger.update()
         self.assertEqual(2, len(tagger))
         tagger[u'☃Qux'] = Tag('Qux', '')
         tagger.set_pinned([u'☃Qux', u'☃Foo'])
         tagger.update()
         self.assertEqual([u'Foo', u'Bar', u'Qux'],
                          [tagger[x].label.strip() for x in tagger])
Esempio n. 7
0
 def test_search_for_locations(self):
     request = zope.publisher.browser.TestRequest(
         skin=zeit.cms.browser.interfaces.ICMSLayer,
         SERVER_URL='http://localhost/++skin++vivi')
     url = zope.component.getMultiAdapter(
         (zeit.cms.tagging.source.locationSource(None), request),
         zeit.cms.browser.interfaces.ISourceQueryURL)
     with mock.patch('zeit.retresco.connection.TMS.get_locations') as gl:
         gl.return_value = [Tag(u'Schweiz', u'location'),
                            Tag(u'Frankreich', u'location')]
         b = self.browser
         b.open(url + '?term=ei')
         result = json.loads(b.contents)
     self.assertEqual([{u'label': u'Schweiz',
                        u'value': u'tag://location\\u2603Schweiz'},
                       {u'label': u'Frankreich',
                        u'value': u'tag://location\\u2603Frankreich'}],
                      result)
Esempio n. 8
0
    def _find_tag_node(self, key, tags=None):
        if tags is None:
            tags = self.to_xml()
        if tags is self.EMPTY_NODE:
            raise KeyError(key)

        node = [
            x for x in tags.iterchildren()
            if Tag(x.text, x.get('type', '')).code == key
        ]
        if not node:
            raise KeyError(key)
        return node[0]
Esempio n. 9
0
 def test_setitem_should_set_entity_type(self):
     tagger = Tagger(ExampleContentType())
     tagger[u'☃Berlin'] = Tag('Berlin', entity_type='Location')
     self.assertEqual('Location', tagger[u'Location☃Berlin'].entity_type)
Esempio n. 10
0
 def test_setitem_should_add_tag(self):
     tagger = Tagger(ExampleContentType())
     tagger[u'☃Berlin'] = Tag('Berlin', '')
     self.assertEqual([u'☃Berlin'], list(tagger))
     self.assertEqual('Berlin', tagger[u'☃Berlin'].label)
Esempio n. 11
0
 def __iter__(self):
     tags = self.to_xml()
     return (Tag(x.text, x.get('type', '')).code
             for x in tags.iterchildren())
Esempio n. 12
0
 def test_checkin_should_not_update_keywords_if_already_present(self):
     content = self.repository['testcontent']
     with zeit.cms.checkout.helper.checked_out(content) as co:
         co.keywords = (Tag('Berlin', 'location'), )
     self.assertEqual(False, self.tms.generate_keyword_list.called)