def test_should_return_service_by_id(self): service = default_service() self.client.put( '/index-to-create/services/' + str(service["service"]["id"]), data=json.dumps(service), content_type='application/json' ) with self.app.app_context(): search_service.refresh('index-to-create') response = self.client.get( '/index-to-create/services/' + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 200) assert_equal( data['services']["_id"], str(service["service"]["id"])) assert_equal( data['services']["_source"]["id"], str(service["service"]["id"])) cases = [ # (indexed name, original name) ("filter_lot", "lot"), ("serviceName", "serviceName"), ("serviceSummary", "serviceSummary"), ("serviceBenefits", "serviceBenefits"), ("serviceFeatures", "serviceFeatures"), ("serviceTypes", "serviceTypes"), ("filter_serviceTypes", "serviceTypes"), ("supplierName", "supplierName"), ("filter_freeOption", "freeOption"), ("filter_trialOption", "trialOption"), ("filter_minimumContractPeriod", "minimumContractPeriod"), ("filter_supportForThirdParties", "supportForThirdParties"), ("filter_selfServiceProvisioning", "selfServiceProvisioning"), ("filter_datacentresEUCode", "datacentresEUCode"), ("filter_dataBackupRecovery", "dataBackupRecovery"), ("filter_dataExtractionRemoval", "dataExtractionRemoval"), ("filter_networksConnected", "networksConnected"), ("filter_apiAccess", "apiAccess"), ("filter_openStandardsSupported", "openStandardsSupported"), ("filter_openSource", "openSource"), ("filter_persistentStorage", "persistentStorage"), ("filter_guaranteedResources", "guaranteedResources"), ("filter_elasticCloud", "elasticCloud") ] # filter fields are processed (lowercase etc) # and also have a new key (filter_FIELDNAME) for key in cases: original = service["service"][key[1]] indexed = data['services']["_source"][key[0]] if key[0].startswith("filter"): original = process_values_for_matching(service["service"][key[1]]) assert_equal(original, indexed)
def _put_into_and_get_back_from_elasticsearch(self, service, query_string): self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') with self.app.app_context(): search_service.refresh('test-index') return self.client.get( '/test-index/services/search?{}'.format(query_string))
def setup(self): super(TestSearchEndpoint, self).setup() with self.app.app_context(): services = create_services(10) for service in services: self.client.put( "/index-to-create/services/" + str(service["service"]["id"]), data=json.dumps(service), content_type="application/json", ) search_service.refresh("index-to-create")
def _put_into_and_get_back_from_elasticsearch(self, service, query_string): self.client.put( '/index-to-create/services/{}'.format(service["service"]["id"]), data=json.dumps(service), content_type='application/json') with self.app.app_context(): search_service.refresh('index-to-create') return self.client.get( '/index-to-create/services/search?{}'.format(query_string) )
def setup(self): super(TestSearchEndpoint, self).setup() self.create_index() with self.app.app_context(): services = create_services(10) for service in services: self.client.put( '/index-to-create/services/' + str(service["service"]["id"]), data=json.dumps(service), content_type='application/json') search_service.refresh('index-to-create')
def setup(self): super(BaseSearchTestWithServices, self).setup() with self.app.app_context(): services = [] for i in range(10): service = make_service(id=str(i)) services.append(service) response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 200 search_service.refresh('test-index')
def test_should_index_a_document(self, service): response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 200 with self.app.app_context(): search_service.refresh('test-index') response = self.client.get('/test-index') assert response.status_code == 200 assert response.json["status"]["num_docs"] == 1
def setup_module(): app = create_app('test') test_client = app.test_client() setup_authorization(app) with app.app_context(): services = list(create_services(120)) for service in services: test_client.put( '/index-to-create/services/%s' % service["service"]["id"], data=json.dumps(service), content_type='application/json' ) search_service.refresh('index-to-create')
def setup(self): super().setup() def put(s): response = self.client.put( make_search_api_url(s), data=json.dumps(s), content_type="application/json", ) assert response.status_code == 200 return response with self.app.app_context(): put( make_service( id="1", serviceDescription= "Accessing, storing and retaining email.", lot="cloud-support", )) put( make_service( id="2", serviceDescription= "The <em>quick</em> brown fox jumped over the <em>lazy</em> dog.", lot="mother-goose", )) put( make_service( id="3", serviceDescription=( # serviceDescription is limited to 500 characters by validator in # digitalmarketplace-frameworks/frameworks/g-cloud-10/questions/services "This service description has 500 characters. " "It is made of 5 repetitions of a 100 character string.\n" * 5), lot="long-text", )) put( make_service( id="4", serviceDescription=( "This service description has <em>2</em> sentences. " "There is HTML in <b>each</b> sentence."), lot="two-sentences", )) search_service.refresh("test-index")
def test_should_index_a_document(self): service = default_service() response = self.client.put( "/index-to-create/services/" + str(service["service"]["id"]), data=json.dumps(service), content_type="application/json", ) assert_equal(response.status_code, 200) with self.app.app_context(): search_service.refresh("index-to-create") response = self.client.get("/index-to-create/status") assert_equal(response.status_code, 200) assert_equal(get_json_from_response(response)["status"]["num_docs"], 1)
def test_should_delete_service_by_id(self, service): self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') with self.app.app_context(): search_service.refresh('test-index') response = self.client.delete(make_search_api_url(service), ) data = response.json assert response.status_code == 200 assert data["message"]["result"] == "deleted" response = self.client.get(make_search_api_url(service), ) data = response.json assert response.status_code == 404 assert data['error']['found'] is False
def test_should_index_a_document(self): service = default_service() response = self.client.put( '/index-to-create/services/' + str(service["service"]["id"]), data=json.dumps(service), content_type='application/json') assert_equal(response.status_code, 200) with self.app.app_context(): search_service.refresh('index-to-create') response = self.client.get('/index-to-create') assert_equal(response.status_code, 200) assert_equal( get_json_from_response(response)["status"]["num_docs"], 1)
def test_highlighting_should_use_defined_html_tags(self): with self.app.app_context(): service = default_service() service["service"]["serviceSummary"] = u"Accessing, storing and retaining email" highlighted_summary = ( "Accessing, <em class='search-result-highlighted-text'>" + "storing</em> and retaining email" ) self.client.put( "/index-to-create/services/" + str(service["service"]["id"]), data=json.dumps(service), content_type="application/json", ) search_service.refresh("index-to-create") response = self.client.get("/index-to-create/services/search?q=storing") assert_equal(response.status_code, 200) search_results = get_json_from_response(response)["services"] assert_equal(search_results[0]["highlight"]["serviceSummary"][0], highlighted_summary)
def setup_module(): app = create_app('test') test_client = app.test_client() setup_authorization(app) with app.app_context(): test_client.put( '/index-to-create', data=json.dumps({"type": "index"}), content_type="application/json", ) services = list(create_services(120)) for service in services: test_client.put( '/index-to-create/services/%s' % service["service"]["id"], data=json.dumps(service), content_type='application/json' ) search_service.refresh('index-to-create')
def test_should_delete_service_by_id(self): service = default_service() self.client.put( "/index-to-create/services/" + str(service["service"]["id"]), data=json.dumps(service), content_type="application/json", ) with self.app.app_context(): search_service.refresh("index-to-create") response = self.client.delete("/index-to-create/services/" + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 200) assert_equal(data["message"]["found"], True) response = self.client.get("/index-to-create/services/" + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 404) assert_equal(data["message"]["found"], False)
def test_highlighting_should_escape_html(self): service = default_service(serviceSummary="accessing, storing <h1>and retaining</h1> email") self.client.put( "/index-to-create/services/%s" % service["service"]["id"], data=json.dumps(service), content_type="application/json", ) with self.app.app_context(): search_service.refresh("index-to-create") response = self.client.get("/index-to-create/services/search?q=storing") assert_equal(response.status_code, 200) search_results = get_json_from_response(response)["services"] assert_equal( search_results[0]["highlight"]["serviceSummary"][0], "accessing, <em class='search-result-highlighted-text'>" + "storing</em> <h1>and retaining</h1> email", )
def test_service_should_have_all_exact_match_fields(self): service = default_service() self.client.put( '/index-to-create/services/' + str(service["service"]["id"]), data=json.dumps(service), content_type='application/json' ) with self.app.app_context(): search_service.refresh('index-to-create') response = self.client.get( '/index-to-create/services/' + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 200) cases = [ "lot", "serviceTypes", "freeOption", "trialOption", "minimumContractPeriod", "supportForThirdParties", "selfServiceProvisioning", "datacentresEUCode", "dataBackupRecovery", "dataExtractionRemoval", "networksConnected", "apiAccess", "openStandardsSupported", "openSource", "persistentStorage", "guaranteedResources", "elasticCloud" ] for key in cases: assert_equal( data['services']["_source"]["filter_" + key], process_values_for_matching(service["service"][key]))
def test_service_should_have_all_exact_match_fields(self, service): self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') with self.app.app_context(): search_service.refresh('test-index') response = self.client.get(make_search_api_url(service)) data = response.json assert response.status_code == 200 cases = [ "lot", "publicSectorNetworksTypes", "serviceCategories", ] for key in cases: assert ( data['services']["_source"]["dmfilter_" + key] == service.get( 'document', service.get('service'))[key])
def test_should_delete_service_by_id(self): service = default_service() self.client.put( '/index-to-create/services/' + str(service["service"]["id"]), data=json.dumps(service), content_type='application/json' ) with self.app.app_context(): search_service.refresh('index-to-create') response = self.client.delete( '/index-to-create/services/' + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 200) assert_equal(data['message']['found'], True) response = self.client.get( '/index-to-create/services/' + str(service["service"]["id"])) data = get_json_from_response(response) assert_equal(response.status_code, 404) assert_equal(data['error']['found'], False)
def test_should_return_service_by_id(self, service): self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') with self.app.app_context(): search_service.refresh('test-index') response = self.client.get(make_search_api_url(service)) data = response.json assert response.status_code == 200 original_service_id = service.get( 'document', service.get('service'))['id'] # TODO remove compat shim assert data['services']["_id"] == str(original_service_id) assert data['services']["_source"]["dmtext_id"] == str( original_service_id) cases = ( "lot", "serviceName", "serviceDescription", "serviceBenefits", "serviceFeatures", "serviceCategories", "supplierName", ) # filter fields are processed (lowercase etc) # and also have a new key (filter_FIELDNAME) for key in cases: original = service.get( 'document', service.get('service'))[key] # TODO remove compat shim indexed = data['services']["_source"]["dmtext_" + key] assert original == indexed
def dummy_services(services_mapping_file_name_and_path): """Fixture that indexes a bunch of fake G-Cloud services so that searching can be tested.""" app = create_app('test') test_client = app.test_client() setup_authorization(app) with app.app_context(): response = test_client.put( '/test-index', data=json.dumps({"type": "index", "mapping": services_mapping_file_name_and_path[0]}), content_type="application/json", ) assert response.status_code in (200, 201) services = list(create_services(120)) for service in services: test_client.put( '/test-index/services/%s' % service["document"]["id"], data=json.dumps(service), content_type='application/json' ) search_service.refresh('test-index') yield test_client.delete('/test-index')