def test_save_instance_return_400(self, request_mock):
     expected_msg = 'Error on Elastic Search when saving an instance.\n  PUT http://localhost:9200/index/type/id - 400\n  Body: {"error"}'
     try:
         search_engine.save_instance({"error": "json not in conformance with mapping, ES returns 400"}, "index", "type", "id")
     except ClientHTTPError as e:
         self.assertEqual(e.status_code, 400)
         self.assertEqual(e.log_message, expected_msg)
 def test_save_instance_return_400(self, request_mock):
     expected_msg = 'Error on Elastic Search when saving an instance.\n  PUT http://localhost:9200/index/type/id - 400\n  Body: {"error"}'
     try:
         search_engine.save_instance({"error": "json not in conformance with mapping, ES returns 400"}, "index", "type", "id")
     except ClientHTTPError as e:
         self.assertEqual(e.status_code, 400)
         self.assertEqual(e.log_message, expected_msg)
示例#3
0
def store_query(entry, query_id, client_id):
    if not _allowed_query(entry["sparql_template"]):
        raise HTTPError(400, log_message=FORBIDDEN_SPARUL_MESSAGE)

    stored_query = get_stored_query(query_id)
    if stored_query:
        validate_client_id(client_id, stored_query)
        save_instance(entry, ES_INDEX_NAME, ES_TYPE_NAME, query_id)
        return 200
    else:
        save_instance(entry, ES_INDEX_NAME, ES_TYPE_NAME, query_id)
        return 201
示例#4
0
def store_query(entry, query_id, client_id):
    if not _allowed_query(entry["sparql_template"]):
        raise HTTPError(400, log_message=FORBIDDEN_SPARUL_MESSAGE)

    stored_query = get_stored_query(query_id)
    if stored_query:
        validate_client_id(client_id, stored_query)
        save_instance(entry, ES_INDEX_NAME, ES_TYPE_NAME, query_id)
        return 200
    else:
        save_instance(entry, ES_INDEX_NAME, ES_TYPE_NAME, query_id)
        return 201
    def test_save_instance_return_200(self, request_mock):
        response = search_engine.save_instance({"test": "a"}, "index", "type", "id")
        expected_url = u"http://localhost:9200/index/type/id"
        expected_method = "PUT"
        expected_body = u'{"test": "a"}'
        call_args = request_mock.call_args[0][0]
        self.assertEqual(call_args["url"], expected_url)
        self.assertEqual(call_args["method"], expected_method)
        self.assertEqual(call_args["body"], expected_body)

        expected_returned_code = 200
        self.assertEquals(response, expected_returned_code)
    def test_save_instance_return_200(self, request_mock):
        response = search_engine.save_instance({"test": "a"}, "index", "type", "id")
        expected_url = u"http://localhost:9200/index/type/id"
        expected_method = "PUT"
        expected_body = u'{"test": "a"}'
        call_args = request_mock.call_args[0][0]
        self.assertEqual(call_args["url"], expected_url)
        self.assertEqual(call_args["method"], expected_method)
        self.assertEqual(call_args["body"], expected_body)

        expected_returned_code = 200
        self.assertEquals(response, expected_returned_code)