Exemple #1
0
 def get(self):
     if self.search_adapter:
         result = search.query(self.search_adapter, **multi_to_dict(request.args))
         objects = result.get_objects()
     else:
         objects = list(self.model.objects)
     return marshal(objects, self.fields)
Exemple #2
0
    def test_empty_search_with_filter_and_match(self):
        '''Should match both the topic criteria and the query'''
        with self.autoindex():
            # Match both the topic condition but the queried tag
            match = VisibleDatasetFactory.create_batch(2, tags=[
                'in', 'filtered'
            ])
            # Match the topic condition but not the queried tag
            no_match = VisibleDatasetFactory.create_batch(2, tags=['in'])
            # Excluded because not matching one of the topic tag
            excluded = VisibleDatasetFactory.create_batch(2, tags=[
                'out', 'filtered'
            ])
        topic = TopicFactory(tags=['in', 'no-match'])

        query = topic_search_for(topic, DatasetSearch, tag='filtered')
        result = search.query(query)

        found = [d.id for d in result]

        self.assertEqual(len(found), 2)

        for dataset in match:
            self.assertIn(dataset.id, found)
        for dataset in no_match + excluded:
            self.assertNotIn(dataset.id, found)
Exemple #3
0
 def get(self):
     """List all objects"""
     if self.search_adapter:
         objects = search.query(self.search_adapter, **multi_to_dict(request.args))
     else:
         objects = list(self.model.objects)
     return marshal_page(objects, self.fields)
Exemple #4
0
 def get(self):
     '''List all objects'''
     if self.search_adapter:
         objects = search.query(self.search_adapter,
                                **multi_to_dict(request.args))
     else:
         objects = list(self.model.objects)
     return marshal_page(objects, self.fields)
Exemple #5
0
def reuses(topic):
    kwargs = multi_to_dict(request.args)
    kwargs.pop('topic', None)
    topic_search = topic_search_for(topic, ReuseSearch, facets=True, **kwargs)

    return theme.render('topic/reuses.html',
                        topic=topic,
                        reuses=search.query(topic_search))
Exemple #6
0
 def get_queryset(self):
     adapter = search.adapter_for(self.search_adapter or self.model)
     parser = adapter.as_request_parser()
     params = not_none_dict(parser.parse_args())
     params['facets'] = True
     adapter = self.search_adapter or self.model
     result = search.query(adapter, **params)
     return result
Exemple #7
0
 def get_queryset(self):
     adapter = search.adapter_for(self.search_adapter or self.model)
     parser = adapter.as_request_parser()
     params = not_none_dict(parser.parse_args())
     params['facets'] = True
     adapter = self.search_adapter or self.model
     result = search.query(adapter, **params)
     return result
Exemple #8
0
 def get(self):
     '''List or search all datasets'''
     search_parser.parse_args()
     try:
         return search.query(Dataset, **multi_to_dict(request.args))
     except NotImplementedError:
         abort(501, 'Search endpoint not enabled')
     except RuntimeError:
         abort(500, 'Internal search service error')
Exemple #9
0
    def test_empty_search_no_match(self):
        '''Should return no result if no data match the tags'''
        with self.autoindex():
            VisibleDatasetFactory.create_batch(2, tags=['whatever'])
        topic = TopicFactory(tags=['no-match'])

        query = topic_search_for(topic, DatasetSearch)
        result = search.query(query)

        self.assertEqual(len(result), 0)
Exemple #10
0
def datasets(topic):
    kwargs = multi_to_dict(request.args)
    kwargs.pop('topic', None)
    topic_search = topic_search_for(topic,
                                    DatasetSearch,
                                    facets=True,
                                    **kwargs)

    return theme.render('topic/datasets.html',
                        topic=topic,
                        datasets=search.query(topic_search))
Exemple #11
0
def datasets(topic):
    kwargs = multi_to_dict(request.args)
    kwargs.pop('topic', None)
    topic_search = topic_search_for(topic,
                                    DatasetSearch,
                                    facets=True,
                                    **kwargs)

    return theme.render(
        'topic/datasets.html',
        topic=topic,
        datasets=search.query(topic_search)
    )
Exemple #12
0
def reuses(topic):
    kwargs = multi_to_dict(request.args)
    kwargs.pop('topic', None)
    topic_search = topic_search_for(topic,
                                    ReuseSearch,
                                    facets=True,
                                    **kwargs)

    return theme.render(
        'topic/reuses.html',
        topic=topic,
        reuses=search.query(topic_search)
    )
Exemple #13
0
    def test_should_not_fail_on_missing_objects(self, autoindex):
        with autoindex:
            FakeFactory.create_batch(3)
            deleted_fake = FakeFactory()

        result = search.query(FakeSearch)
        deleted_fake.delete()
        assert len(result) == 4

        # Missing object should be filtered out
        objects = result.objects
        assert len(objects) == 3
        for o in objects:
            assert isinstance(o, Fake)
Exemple #14
0
    def test_should_not_fail_on_missing_objects(self):
        with self.autoindex():
            FakeFactory.create_batch(3)
            deleted_fake = FakeFactory()

        result = search.query(FakeSearch)
        deleted_fake.delete()
        self.assertEqual(len(result), 4)

        # Missing object should be filtered out
        objects = result.objects
        self.assertEqual(len(objects), 3)
        for o in objects:
            self.assertIsInstance(o, Fake)
Exemple #15
0
    def test_should_not_fail_on_missing_objects(self, autoindex):
        with autoindex:
            FakeFactory.create_batch(3)
            deleted_fake = FakeFactory()

        result = search.query(FakeSearch)
        deleted_fake.delete()
        assert len(result) == 4

        # Missing object should be filtered out
        objects = result.objects
        assert len(objects) == 3
        for o in objects:
            assert isinstance(o, Fake)
Exemple #16
0
    def test_empty_search_with_match(self):
        '''Should only return data with at least one tag'''
        with self.autoindex():
            included = VisibleDatasetFactory.create_batch(2, tags=['in'])
            excluded = VisibleDatasetFactory.create_batch(2, tags=['out'])
        topic = TopicFactory(tags=['in', 'no-match'])

        query = topic_search_for(topic, DatasetSearch)
        result = search.query(query)

        found = [d.id for d in result]

        self.assertEqual(len(found), 2)

        for dataset in included:
            self.assertIn(dataset.id, found)
        for dataset in excluded:
            self.assertNotIn(dataset.id, found)
Exemple #17
0
 def get(self):
     return search.query(DatasetSearch, **multi_to_dict(request.args))
Exemple #18
0
 def get(self):
     search_parser.parse_args()
     return search.query(ReuseSearch, **multi_to_dict(request.args))
Exemple #19
0
 def get(self):
     '''List all users'''
     search_parser.parse_args()
     return search.query(UserSearch, **multi_to_dict(request.args))
Exemple #20
0
 def get_queryset(self):
     params = multi_to_dict(request.args)
     params['facets'] = True
     return search.query(self.search_adapter or self.model, **params)
Exemple #21
0
 def get(self):
     return search.query(ReuseSearch, **multi_to_dict(request.args))
Exemple #22
0
 def get(self):
     '''List all users'''
     search_parser.parse_args()
     return search.query(UserSearch, **multi_to_dict(request.args))
Exemple #23
0
 def get(self):
     '''List or search all organizations'''
     search_parser.parse_args()
     return search.query(OrganizationSearch, **multi_to_dict(request.args))
Exemple #24
0
 def test_execute_search_result_with_model(self):
     '''Should return a SearchResult with the right model'''
     result = search.query(Fake)
     assert isinstance(result, search.SearchResult)
     assert result.query.adapter == FakeSearch
Exemple #25
0
 def get(self):
     search_parser.parse_args()
     return search.query(ReuseSearch, **multi_to_dict(request.args))
Exemple #26
0
 def get(self):
     '''List or search all datasets'''
     return search.query(DatasetSearch, **multi_to_dict(request.args))
Exemple #27
0
 def test_execute_search_result(self):
     '''SearchQuery execution should return a SearchResult with the right model'''
     result = search.query(FakeSearch)
     self.assertIsInstance(result, search.SearchResult)
     self.assertEqual(result.query.adapter, FakeSearch)
Exemple #28
0
 def get(self):
     """List or search all organizations"""
     return search.query(OrganizationSearch, **multi_to_dict(request.args))
Exemple #29
0
 def test_execute_search_result_with_model(self):
     '''SearchQuery execution from a model should return a SearchResult with the right model'''
     result = search.query(Fake)
     self.assertIsInstance(result, search.SearchResult)
     self.assertEqual(result.query.adapter, FakeSearch)
Exemple #30
0
 def get_queryset(self):
     return search.query(self.search_adapter, **multi_to_dict(request.args))
Exemple #31
0
 def test_execute_search_result_with_model(self):
     '''Should return a SearchResult with the right model'''
     self.init_search()
     result = search.query(Fake)
     self.assertIsInstance(result, search.SearchResult)
     self.assertEqual(result.query.adapter, FakeSearch)
Exemple #32
0
 def get(self):
     '''List or search all datasets'''
     return search.query(DatasetSearch, **multi_to_dict(request.args))
Exemple #33
0
 def get(self):
     '''List or search all datasets'''
     search_parser.parse_args()
     return search.query(Dataset, **multi_to_dict(request.args))
Exemple #34
0
 def get(self):
     return search.query(DatasetSearch, **multi_to_dict(request.args))
Exemple #35
0
 def test_execute_search_result_with_model(self):
     '''Should return a SearchResult with the right model'''
     result = search.query(Fake)
     assert isinstance(result, search.SearchResult)
     assert result.query.adapter == FakeSearch
Exemple #36
0
 def get(self):
     return search.query(ReuseSearch, **multi_to_dict(request.args))
Exemple #37
0
 def get(self):
     '''List or search all datasets'''
     search_parser.parse_args()
     return search.query(Dataset, **multi_to_dict(request.args))
Exemple #38
0
 def get(self):
     '''List or search all organizations'''
     search_parser.parse_args()
     return search.query(OrganizationSearch, **multi_to_dict(request.args))