Ejemplo n.º 1
0
 def test_subject_untags(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     uuid = IUUID(doc1)
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     wrapped.subjects = ('foo', 'beer')
     tags = self.graph.get_tags('content', uuid, 'john_doe')
     self.assertEqual(sorted(tags), ['beer', 'foo'])
Ejemplo n.º 2
0
 def test_subject_untags(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     uuid = IUUID(doc1)
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     wrapped.subjects = ('foo', 'beer')
     tags = self.graph.get_tags('content', uuid, 'john_doe')
     self.assertEqual(sorted(tags), ['beer', 'foo'])
Ejemplo n.º 3
0
def create_library_content(parent,
                           spec,
                           force=False,
                           creator='alice_lindstrom',
                           bigsetup=False):
    if parent is None:
        # initial recursion
        portal = api.portal.get()
        parent = portal.library
        api.user.grant_roles(
            username=creator,
            roles=['Contributor', 'Reviewer', 'Editor'],
            obj=portal.library
        )
        try:
            api.content.transition(portal.library, 'publish')
        except api.exc.InvalidParameterError:
            # subsequent runs, already published
            pass
        # initial (automated testing) testcontent run: no children
        # second manual testcontent run: 1 child HR -> do big setup
        # subsequent manual testcontent runs: skip for speed
        already_setup = bool(len(portal.library.objectIds()) > 1)
        if already_setup and not force:
            log.info("library already setup. skipping for speed.")
            return

    # recursively called
    while spec:
        # avoiding side effects here cost me 4 hours!!
        item = copy.deepcopy(spec.pop(0))
        if 'title' not in item and not bigsetup:
            # skip lorem ipsum creation unless we're running bigsetup
            continue

        contents = item.pop('contents', None)
        if 'title' not in item:
            global idcounter
            idcounter += 1
            item['title'] = 'Lorem Ipsum %s' % idcounter
        if 'description' not in item:
            item['description'] = loremipsum.get_sentence()
        if item['type'] in ('Document',):
            raw_text = "\n\n".join(loremipsum.get_paragraphs(3))
            item['text'] = RichTextValue(raw=raw_text,
                                         mimeType='text/plain',
                                         outputMimeType='text/x-html-safe')

        obj = create_as(creator, container=parent, **item)
        if not item['type'].startswith('ploneintranet'):
            # only tag non-folderish content
            tags = random.sample(library_tags, random.choice(range(4)))
            tags.append(u'I ♥ UTF-8')
            wrapped = IDublinCore(obj)
            wrapped.subjects = tags
        api.content.transition(obj, 'publish')
        obj.reindexObject()  # or solr doesn't find it
        if contents:
            create_library_content(obj, contents, creator=creator,
                                   bigsetup=bigsetup)
Ejemplo n.º 4
0
def create_library_content(parent,
                           spec,
                           force=False,
                           creator='alice_lindstrom',
                           bigsetup=False):
    if parent is None:
        # initial recursion
        portal = api.portal.get()
        parent = portal.library
        api.user.grant_roles(username=creator,
                             roles=['Contributor', 'Reviewer', 'Editor'],
                             obj=portal.library)
        try:
            api.content.transition(portal.library, 'publish')
        except api.exc.InvalidParameterError:
            # subsequent runs, already published
            pass
        # initial (automated testing) testcontent run: no children
        # second manual testcontent run: 1 child HR -> do big setup
        # subsequent manual testcontent runs: skip for speed
        already_setup = bool(len(portal.library.objectIds()) > 1)
        if already_setup and not force:
            log.info("library already setup. skipping for speed.")
            return

    # recursively called
    while spec:
        # avoiding side effects here cost me 4 hours!!
        item = copy.deepcopy(spec.pop(0))
        if 'title' not in item and not bigsetup:
            # skip lorem ipsum creation unless we're running bigsetup
            continue

        contents = item.pop('contents', None)
        if 'title' not in item:
            global idcounter
            idcounter += 1
            item['title'] = 'Lorem Ipsum %s' % idcounter
        if 'description' not in item:
            item['description'] = loremipsum.get_sentence()
        if item['type'] in ('Document', ):
            raw_text = "\n\n".join(loremipsum.get_paragraphs(3))
            item['text'] = RichTextValue(raw=raw_text,
                                         mimeType='text/plain',
                                         outputMimeType='text/x-html-safe')

        obj = create_as(creator, container=parent, **item)
        if not item['type'].startswith('ploneintranet'):
            # only tag non-folderish content
            tags = random.sample(library_tags, random.choice(range(4)))
            tags.append(u'I ♥ UTF-8')
            wrapped = IDublinCore(obj)
            wrapped.subjects = tags
        api.content.transition(obj, 'publish')
        obj.reindexObject()  # or solr doesn't find it
        if contents:
            create_library_content(obj,
                                   contents,
                                   creator=creator,
                                   bigsetup=bigsetup)
Ejemplo n.º 5
0
def tag_subjects(context, event):
    """
    We can resolve a UUID and store subjects as tags
    only after a new content item has been added to it's container.
    """
    wrapped = IDublinCore(context, None)
    if wrapped:  # only if the behavior is enabled
        # re-setting subjects should now trigger graph.tag()
        wrapped.subjects = context.subject
Ejemplo n.º 6
0
 def test_subject_tags_set_empty(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     wrapped = IDublinCore(doc1)
     # the check is that this doesn't raise a KeyError
     wrapped.subjects = ()
Ejemplo n.º 7
0
 def test_subject_multiuser(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     uuid = IUUID(doc1)
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     self.login('mary_jane')
     wrapped.subjects = ('foo', 'beer')
     g = self.graph
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'beer')),
                      ['mary_jane'])
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'bar')),
                      ['john_doe'])
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'foo')),
                      ['john_doe', 'mary_jane'])
Ejemplo n.º 8
0
 def test_subject_tags_set_empty(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     wrapped = IDublinCore(doc1)
     # the check is that this doesn't raise a KeyError
     wrapped.subjects = ()
Ejemplo n.º 9
0
 def test_subject_multiuser(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     uuid = IUUID(doc1)
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     self.login('mary_jane')
     wrapped.subjects = ('foo', 'beer')
     g = self.graph
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'beer')),
                      ['mary_jane'])
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'bar')),
                      ['john_doe'])
     self.assertEqual(g.unpack(g.get_taggers('content', uuid, 'foo')),
                      ['john_doe', 'mary_jane'])
Ejemplo n.º 10
0
 def test_subject_set_get(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     # adapter.subjects - obj.subject
     # ---------------^   -----------!
     self.assertEqual(doc1.subject, ('foo', 'bar'))
Ejemplo n.º 11
0
 def test_subject_set_get(self):
     self.login('john_doe')
     doc1 = api.content.create(
         container=self.portal,
         type='Document',
         id='doc1',
         title='Doc 1',
     )
     wrapped = IDublinCore(doc1)
     wrapped.subjects = ('foo', 'bar')
     # adapter.subjects - obj.subject
     # ---------------^   -----------!
     self.assertEqual(doc1.subject, ('foo', 'bar'))