def test_badrequest_noquery(self): from pyramid.httpexceptions import HTTPBadRequest from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request() fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPBadRequest))
def test_badrequest_noquery(self): from pyramid.httpexceptions import HTTPBadRequest from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request() fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPBadRequest))
def test_nomatch(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request(params=dict(query="foo")) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 0)
def test_nomatch(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request(params=dict(query="foo")) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 0)
def test_badrequest_partitionlimit(self): from pyramid.httpexceptions import HTTPBadRequest from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="text", partitionlimit="bad")) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPBadRequest))
def test_unknown_laguage(self): from pyramid.httpexceptions import HTTPInternalServerError from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request() request.registry.settings["default_locale_name"] = "it" request.accept_language = webob.acceptparse.create_accept_language_header("es") fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPInternalServerError))
def test_badrequest_partitionlimit(self): from pyramid.httpexceptions import HTTPBadRequest from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="text", partitionlimit="bad") ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPBadRequest))
def test_private_with_role_nomatch(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request(params=dict(query="ven nei", limit=40), username="******") fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 0)
def test_interface(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="lausanne", limit=10, interface="main") ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual({feature.properties["label"] for feature in response.features}, set(["label5", "label6"]))
def test_interface(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="params", limit=10, interface="main") ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual({feature.properties["label"] for feature in response.features}, set(["label5", "label6"]))
def test_unknown_laguage(self): from pyramid.httpexceptions import HTTPInternalServerError from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView from webob.acceptparse import Accept request = self._create_dummy_request() request.registry.settings["default_locale_name"] = "it" request.accept_language = Accept("es") fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, HTTPInternalServerError))
def test_match_partitionlimit(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request(params=dict(query="tra sol", limit=40, partitionlimit=1)) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 1) self.assertEqual(response.features[0].properties["label"], "label1") self.assertEqual(response.features[0].properties["layer_name"], "layer1")
def test_private_with_role_nomatch(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="ven nei", limit=40), username="******" ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 0)
def test_match_partitionlimit(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="tra sol", limit=40, partitionlimit=1) ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 1) self.assertEqual(response.features[0].properties["label"], "label1") self.assertEqual(response.features[0].properties["layer_name"], "layer1")
def test_rank_order_with_ts_rank_cd(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="simi", limit=3, ranksystem="ts_rank_cd")) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 3) self.assertEqual(response.features[0].properties["label"], "A 70 simi") self.assertEqual(response.features[1].properties["label"], "A 71 simi") self.assertEqual(response.features[2].properties["label"], "A 7 simi")
def test_params_actions(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="params", limit=10) ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 1) self.assertEqual(response.features[0].properties["label"], "label5") self.assertEqual(response.features[0].properties["params"], {"floor": 5}) self.assertEqual(response.features[0].properties["actions"], [{"action": "add_layer", "data": "layer1"}])
def test_params_actions(self): from geojson.feature import FeatureCollection from c2cgeoportal_geoportal.views.fulltextsearch import FullTextSearchView request = self._create_dummy_request( params=dict(query="lausanne", limit=10) ) fts = FullTextSearchView(request) response = fts.fulltextsearch() self.assertTrue(isinstance(response, FeatureCollection)) self.assertEqual(len(response.features), 1) self.assertEqual(response.features[0].properties["label"], "label5") self.assertEqual(response.features[0].properties["params"], {"floor": 5}) self.assertEqual(response.features[0].properties["actions"], [{"action": "add_layer", "data": "layer1"}])