def test_should_raise_400_on_bad_doc_type(self, service): response = self.client.put(make_search_api_url( service, type_name='some-bad-type'), data=json.dumps(service), content_type='application/json') assert response.status_code == 400
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
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_with_incorrect_types(self, service): service.get('document', service.get('service'))["serviceName"] = 123 response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 200
def test_should_index_a_document_with_extra_fields(self, service): service.get('document', service.get('service'))["randomField"] = "some random" response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 200
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(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 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_index_document_handles_connection_error(self, current_app, index, error_status_code, service): index.return_value = (NewConnectionError( '', self.EXAMPLE_CONNECTION_ERROR), error_status_code) response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 500 current_app.logger.error.assert_called_once_with( f'API response error: ": {self.EXAMPLE_CONNECTION_ERROR}" Unexpected status code: "{error_status_code}"' )
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 test_should_return_service_on_id(self, service): response = self.client.put(make_search_api_url(service), data=json.dumps(service), content_type='application/json') assert response.status_code == 200