def test_search(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        library_obj = self.portal['library']

        criteria = library.get_criteria(library_obj)

        searchArgs = library.get_search_args(library_obj)
        fakeForm = {}
        searchArgs.update(
            library.get_form_fields_by_keys(fakeForm, criteria.keys()))

        catalog = getToolByName(self.portal, 'portal_catalog')

        indexContents = library.get_index_contents(catalog, criteria,
            searchArgs)
        availableValues = library.get_availible_values(criteria, indexContents)

        # TODO: assert

        brains = catalog(searchArgs)

        groupBy = 'rmMediaType'
        if not groupBy in criteria \
                or not criteria[groupBy].get('groupable', False):
            groupBy = 'rmMediaType'
        groupVocabulary = criteria[groupBy].get('vocabulary', None)
        groupInfo = indexContents[groupBy]
        groupedResults = library.group_brains(brains, groupBy, groupInfo)
        groupedResults = library.index_content_sorter(groupedResults,
            groupVocabulary)
Ejemplo n.º 2
0
    def test_search(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        self.portal.invokeFactory('LibrarySearch', 'library', title=u"Library")
        library_obj = self.portal['library']
        library_obj.libraryExtraSearchArgs = {
            'path': '/'.join(self.portal.getPhysicalPath()), }

        self.portal.invokeFactory('RichFile', 'file',
            rmMediaType='document',
            rmAuthor='Me',
            rmTags=['defcon'],
        )
        self.portal.invokeFactory('RichLink', 'link',
            rmMediaType='video',
            rmAuthor='Someone Else',
            rmTags=['defcon', 'scientific'],
        )

        criteria = library.get_criteria(library_obj)

        searchArgs = library.get_search_args(library_obj)
        fakeForm = {'rmTags': 'defcon', }
        searchArgs.update(
            library.get_form_fields_by_keys(fakeForm, criteria.keys()))

        self.assertIn('rmTags', searchArgs)
        self.assertEquals(searchArgs['rmTags'], [fakeForm['rmTags']])

        catalog = getToolByName(self.portal, 'portal_catalog')

        indexContents = library.get_index_contents(catalog, criteria, searchArgs)
        availableValues = library.get_availible_values(criteria, indexContents)

        # TODO: assert

        brains = catalog(searchArgs)

        groupBy = 'rmMediaType'
        if not groupBy in criteria \
                or not criteria[groupBy].get('groupable', False):
            groupBy = 'rmMediaType'
        groupVocabulary = criteria[groupBy].get('vocabulary', None)
        groupInfo = indexContents[groupBy]
        groupedResults = library.group_brains(brains, groupBy, groupInfo)
        groupedResults = library.index_content_sorter(groupedResults,
            groupVocabulary)
    def test_search(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        library_obj = self.portal['library']

        criteria = library.get_criteria(library_obj)

        searchArgs = library.get_search_args(library_obj)
        fakeForm = {}
        searchArgs.update(
            library.get_form_fields_by_keys(fakeForm, criteria.keys()))

        catalog = getToolByName(self.portal, 'portal_catalog')

        indexContents = library.get_index_contents(catalog, criteria,
            searchArgs)
        availableValues = library.get_availible_values(criteria, indexContents)

        self.assertIn('challengeIntIds', availableValues)
        self.assertIn('rmMediaType', availableValues)
        self.assertIn('rmTags', availableValues)
        self.assertIn('universityIntIds', availableValues)

        challengeIds = availableValues['challengeIntIds']
        universityIds = availableValues['universityIntIds']
        tags = availableValues['rmTags']
        mediaTypes = availableValues['rmMediaType']

        d_show_all = dict()
        d_show_all["count"] = 2
        d_show_all["value"] = 'show-all'
        d_show_all["label"] = u'All'

        self.assertIn(d_show_all, challengeIds)
        self.assertIn(d_show_all, universityIds)
        self.assertIn(d_show_all, tags)
        self.assertIn(d_show_all, mediaTypes)

        d_media_type = dict()
        d_media_type["count"] = 2
        d_media_type["value"] = 'images'
        d_media_type["label"] = u'Images'

        self.assertIn(d_media_type, mediaTypes)

        d_tag_bachelor = dict()
        d_tag_bachelor["count"] = 1
        d_tag_bachelor["value"] = 'bachelor'
        d_tag_bachelor["label"] = u'Bachelor'

        d_tag_handout = dict()
        d_tag_handout["count"] = 1
        d_tag_handout["value"] = 'handout'
        d_tag_handout["label"] = u'Handout'

        d_tag_scientific = dict()
        d_tag_scientific["count"] = 1
        d_tag_scientific["value"] = 'scientific'
        d_tag_scientific["label"] = u'Scientific'

        d_tag_untagged = dict()
        d_tag_untagged["count"] = 0
        d_tag_untagged["value"] = 'show-untagged'
        d_tag_untagged["label"] = u'Untagged'

        self.assertIn(d_tag_bachelor, tags)
        self.assertIn(d_tag_handout, tags)
        self.assertIn(d_tag_scientific, tags)
        self.assertIn(d_tag_untagged, tags)

        d_uni_unassigned = dict()
        d_uni_unassigned["count"] = 0
        d_uni_unassigned["value"] = 'show-unassigned'
        d_uni_unassigned["label"] = u'Unassigned'

        self.assertIn(d_uni_unassigned, universityIds)

        ok = False
        for d in universityIds:
            if d["label"] == u'University of Helsinki' and d["count"] == 2:
                ok = True
        self.assertTrue(ok)

        ok = False
        for d in challengeIds:
            if d["label"] == u'Challenge 1' and d["count"] == 0:
                ok = True
        self.assertTrue(ok)

        ok = False
        for d in challengeIds:
            if d["label"] == u'Challenge 2' and d["count"] == 2:
                ok = True
        self.assertTrue(ok)

        brains = catalog(searchArgs)

        groupBy = 'rmMediaType'
        if not groupBy in criteria \
                or not criteria[groupBy].get('groupable', False):
            groupBy = 'rmMediaType'
        groupVocabulary = criteria[groupBy].get('vocabulary', None)
        groupInfo = indexContents[groupBy]
        groupedResults = library.group_brains(brains, groupBy, groupInfo)
        groupedResults = library.index_content_sorter(groupedResults,
            groupVocabulary)

        groupedResult = groupedResults[0]
        result_brains = groupedResult['brains']

        ok = True
        for b in result_brains:
            if b.id == 'file-with-meta-data' or b.id == 'another-file-with-meta-data':
              ok &= True
            else:
              ok &= False

        self.assertTrue(ok)
        self.assertEqual(groupedResult['count'], 2)
        self.assertEqual(groupedResult['value'], 'images')
        self.assertEqual(groupedResult['label'], u'Images')