Beispiel #1
0
 def test_do_suggest_without_predicate_definition(self, mock_get_predicate_ranges):
     query_params = {}
     suggest_params = {u'search': {"target": "something"}}
     with self.assertRaises(HTTPError) as exception:
         suggest.do_suggest(query_params, suggest_params)
         expected_error_msg = \
             u"Either the predicate something does not exists or it does not have any rdfs:range defined in the triplestore"
         self.assertEqual(exception.exception, expected_error_msg)
Beispiel #2
0
 def test_do_suggest_without_predicate_definition(self, mock_get_predicate_ranges):
     query_params = {}
     suggest_params = {u'search': {"target": "something"}}
     with self.assertRaises(HTTPError) as exception:
         suggest.do_suggest(query_params, suggest_params)
         expected_error_msg = \
             u"Either the predicate something does not exists or it does not have any rdfs:range defined in the triplestore"
         self.assertEqual(exception.exception, expected_error_msg)
Beispiel #3
0
    def post(self):
        valid_params = PAGING_PARAMS

        with safe_params(valid_params):

            try:
                raw_body_params = json.loads(self.request.body)
            except ValueError:
                error_message = _("JSON malformed. Received: {0}.")
                raise HTTPError(400,
                                log_message=error_message.format(
                                    self.request.body))

            body_params = normalize_all_uris_recursively(raw_body_params)
            if '@context' in body_params:
                del body_params['@context']

            validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA)

            self.query_params = ParamDict(self, **valid_params)

        response = do_suggest(self.query_params, body_params)
        if self.query_params['expand_uri'] == "0":
            response = normalize_all_uris_recursively(response, mode=SHORTEN)
        self.finalize(response)
Beispiel #4
0
    def test_do_suggest_with_data(self, mock_get_predicate_ranges, mock_get_subproperties, mock_run_analyze, mock_run_search, mock_build_items, mock_decorate):
        handler = MockHandler()
        params = {
            'lang': 'pt',
            'expand_uri': '0',
            'do_item_count': '0',
            'per_page': '10',
            'page': '0'
        }
        query_params = ParamDict(handler, **params)
        suggest_params = {
            u'search': {
                u'target': u'http://semantica.globo.com/upper/isPartOf',
                u'pattern': u'Globoland',
                u'graphs': [u'http://semantica.globo.com/place/'],
                u'classes': [u'http://semantica.globo.com/place/City'],
                u'fields': [u'http://semantica.globo.com/upper/name', u'http://semantica.globo.com/upper/fullName']
            }
        }

        computed = suggest.do_suggest(query_params, suggest_params)
        expected = {
            '@context': {'@language': 'pt'},
            '_base_url': 'http://mock.test.com/',
            'items': [
                {
                    '@id': u'http://semantica.globo.com/place/City/bc9e708f-35c4-4067-836d-48aaa51d746d',
                    '@type': u'http://semantica.globo.com/place/City',
                    'title': u'Globoland: is the best',
                    'type_title': u'Cidade'
                }
            ]
        }
        self.assertEqual(computed, expected)
Beispiel #5
0
    def test_do_suggest_with_data(self, mock_get_predicate_ranges, mock_get_subproperties, mock_run_analyze, mock_run_search, mock_build_items, mock_decorate):
        handler = MockHandler()
        params = {
            'lang': 'pt',
            'expand_uri': '0',
            'do_item_count': '0',
            'per_page': '10',
            'page': '0'
        }
        query_params = ParamDict(handler, **params)
        suggest_params = {
            u'search': {
                u'target': u'http://semantica.globo.com/upper/isPartOf',
                u'pattern': u'Globoland',
                u'graphs': [u'http://semantica.globo.com/place/'],
                u'classes': [u'http://semantica.globo.com/place/City'],
                u'fields': [u'http://semantica.globo.com/upper/name', u'http://semantica.globo.com/upper/fullName']
            }
        }

        computed = suggest.do_suggest(query_params, suggest_params)
        expected = {
            '@context': {'@language': 'pt'},
            '_base_url': 'http://mock.test.com/',
            'items': [
                {
                    '@id': u'http://semantica.globo.com/place/City/bc9e708f-35c4-4067-836d-48aaa51d746d',
                    '@type': u'http://semantica.globo.com/place/City',
                    'title': u'Globoland: is the best',
                    'type_title': u'Cidade'
                }
            ]
        }
        self.assertEqual(computed, expected)
Beispiel #6
0
    def post(self):
        valid_params = PAGING_PARAMS

        with safe_params(valid_params):
            self.query_params = ParamDict(self, **valid_params)

            raw_body_params = get_json_request_as_dict(self.request.body)
            body_params = normalize_all_uris_recursively(raw_body_params)
            if '@context' in body_params:
                del body_params['@context']

            validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA)

        response = do_suggest(self.query_params, body_params)
        if self.query_params['expand_uri'] == "0":
            response = normalize_all_uris_recursively(response, mode=SHORTEN)
        self.finalize(response)
Beispiel #7
0
    def test_do_suggest_without_data(self, mock_get_predicate_ranges, mock_get_subproperties, mock_run_analyze, mock_run_search):
        handler = MockHandler()
        params = {
            'lang': 'pt',
            'expand_uri': '0',
            'do_item_count': '0',
            'per_page': '10',
            'page': '0'
        }
        query_params = ParamDict(handler, **params)
        suggest_params = {
            u'search': {
                u'target': u'http://semantica.globo.com/upper/isPartOf',
                u'pattern': u'Globoland',
                u'graphs': [u'http://semantica.globo.com/place/'],
                u'classes': [u'http://semantica.globo.com/place/City'],
                u'fields': [u'http://semantica.globo.com/upper/name', u'http://semantica.globo.com/upper/fullName']
            }
        }

        computed = suggest.do_suggest(query_params, suggest_params)
        self.assertEqual(computed, {})
Beispiel #8
0
    def test_do_suggest_without_data(self, mock_get_predicate_ranges, mock_get_subproperties, mock_run_analyze, mock_run_search):
        handler = MockHandler()
        params = {
            'lang': 'pt',
            'expand_uri': '0',
            'do_item_count': '0',
            'per_page': '10',
            'page': '0'
        }
        query_params = ParamDict(handler, **params)
        suggest_params = {
            u'search': {
                u'target': u'http://semantica.globo.com/upper/isPartOf',
                u'pattern': u'Globoland',
                u'graphs': [u'http://semantica.globo.com/place/'],
                u'classes': [u'http://semantica.globo.com/place/City'],
                u'fields': [u'http://semantica.globo.com/upper/name', u'http://semantica.globo.com/upper/fullName']
            }
        }

        computed = suggest.do_suggest(query_params, suggest_params)
        self.assertEqual(computed, {})
Beispiel #9
0
    def post(self):
        valid_params = PAGING_PARAMS

        with safe_params(valid_params):

            try:
                raw_body_params = json.loads(self.request.body)
            except ValueError:
                error_message = _("JSON malformed. Received: {0}.")
                raise HTTPError(400, log_message=error_message.format(self.request.body))

            body_params = normalize_all_uris_recursively(raw_body_params)
            if '@context' in body_params:
                del body_params['@context']

            validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA)

            self.query_params = ParamDict(self, **valid_params)

        response = do_suggest(self.query_params, body_params)
        if self.query_params['expand_uri'] == "0":
            response = normalize_all_uris_recursively(response, mode=SHORTEN)
        self.finalize(response)