def test_badrequest_noquery(self):
        from pyramid.httpexceptions import HTTPBadRequest
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request()
        response = fulltextsearch(request)
        self.assertTrue(isinstance(response, HTTPBadRequest))
    def test_nomatch(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(params=dict(query='foo'))
        resp = fulltextsearch(request)
        self.assertTrue(isinstance(resp, FeatureCollection))
        self.assertEqual(len(resp.features), 0)
    def test_badrequest_partitionlimit(self):
        from pyramid.httpexceptions import HTTPBadRequest
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(
                params=dict(query='text', partitionlimit='bad'))
        response = fulltextsearch(request)
        self.assertTrue(isinstance(response, HTTPBadRequest))
    def test_unknown_laguage(self):
        from pyramid.httpexceptions import HTTPInternalServerError
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        self.config.registry.settings['default_locale_name'] = 'it'
        request = self._create_dummy_request()
        response = fulltextsearch(request)
        self.assertTrue(isinstance(response, HTTPInternalServerError))
    def test_private_with_role_nomatch(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(
                params=dict(query='ven nei', limit=40),
                username=u'__test_user1')
        resp = fulltextsearch(request)
        self.assertTrue(isinstance(resp, FeatureCollection))
        self.assertEqual(len(resp.features), 0)
    def test_match_partitionlimit(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(
                params=dict(query='tra sol', limit=40, partitionlimit=1))
        resp = fulltextsearch(request)
        self.assertTrue(isinstance(resp, FeatureCollection))
        self.assertEqual(len(resp.features), 1)
        self.assertEqual(resp.features[0].properties['label'], 'label1')
        self.assertEqual(resp.features[0].properties['layer_name'], 'layer1')
    def test_private_match(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(
                params=dict(query='pl sem', limit=40),
                username=u'__test_user1')
        resp = fulltextsearch(request)
        self.assertTrue(isinstance(resp, FeatureCollection))
        self.assertEqual(len(resp.features), 1)
        self.assertEqual(resp.features[0].properties['label'], 'label2')
        self.assertEqual(resp.features[0].properties['layer_name'], 'layer2')
    def test_toobig_partitionlimit(self):
        from geojson.feature import FeatureCollection
        from pyramid.httpexceptions import HTTPBadRequest
        from c2cgeoportal.views.fulltextsearch import fulltextsearch

        request = self._create_dummy_request(
                params=dict(query='tra sol', partitionlimit=2000))
        resp = fulltextsearch(request)
        self.assertTrue(isinstance(resp, FeatureCollection))
        self.assertEqual(len(resp.features), 2)
        self.assertEqual(resp.features[0].properties['label'], 'label1')
        self.assertEqual(resp.features[0].properties['layer_name'], 'layer1')
        self.assertEqual(resp.features[1].properties['label'], 'label4')
        self.assertEqual(resp.features[1].properties['layer_name'], 'layer1')