def setUp(self): # Create ES mapping self.es_mapping = Elasticsearch5SearchBackend.mapping_class( models.Book) # Create ES document self.obj = models.Book.objects.get(id=4)
def test_urls(self): # This test backwards compatibility with old URLS setting backend = Elasticsearch5SearchBackend( params={ 'URLS': [ 'http://*****:*****@elasticsearch.mysite.com', 'https://elasticsearch.mysite.com/hello', ], }) self.assertEqual(len(backend.hosts), 4) self.assertEqual(backend.hosts[0]['host'], 'localhost') self.assertEqual(backend.hosts[0]['port'], 12345) self.assertEqual(backend.hosts[0]['use_ssl'], False) self.assertEqual(backend.hosts[1]['host'], '127.0.0.1') self.assertEqual(backend.hosts[1]['port'], 54321) self.assertEqual(backend.hosts[1]['use_ssl'], True) self.assertEqual(backend.hosts[2]['host'], 'elasticsearch.mysite.com') self.assertEqual(backend.hosts[2]['port'], 80) self.assertEqual(backend.hosts[2]['use_ssl'], False) self.assertEqual(backend.hosts[2]['http_auth'], ('username', 'password')) self.assertEqual(backend.hosts[3]['host'], 'elasticsearch.mysite.com') self.assertEqual(backend.hosts[3]['port'], 443) self.assertEqual(backend.hosts[3]['use_ssl'], True) self.assertEqual(backend.hosts[3]['url_prefix'], '/hello')
def get_results(self): backend = Elasticsearch5SearchBackend({}) query = mock.MagicMock() query.queryset = models.Book.objects.all() query.get_query.return_value = 'QUERY' query.get_sort.return_value = None return backend.results_class(backend, query)
def test_default_settings(self): backend = Elasticsearch5SearchBackend(params={}) self.assertEqual(len(backend.hosts), 1) self.assertEqual(backend.hosts[0]['host'], 'localhost') self.assertEqual(backend.hosts[0]['port'], 9200) self.assertEqual(backend.hosts[0]['use_ssl'], False)
def setUp(self): # Create ES mapping self.es_mapping = Elasticsearch5SearchBackend.mapping_class(models.SearchTestChild) # Create ES document self.obj = models.SearchTestChild(title="Hello", subtitle="World", page_id=1) self.obj.save() self.obj.tags.add("a tag")
def setUp(self): # Create ES mapping self.es_mapping = Elasticsearch5SearchBackend.mapping_class(models.SearchTest) # Create ES document self.obj = models.SearchTest(title="Hello") self.obj.save() self.obj.tags.add("a tag")
def test_hosts(self): # This tests that HOSTS goes to es_hosts backend = Elasticsearch5SearchBackend( params={ 'HOSTS': [{ 'host': '127.0.0.1', 'port': 9300, 'use_ssl': True, 'verify_certs': True, }] }) self.assertEqual(len(backend.hosts), 1) self.assertEqual(backend.hosts[0]['host'], '127.0.0.1') self.assertEqual(backend.hosts[0]['port'], 9300) self.assertEqual(backend.hosts[0]['use_ssl'], True)
def setUp(self): # Create ES mapping self.es_mapping = Elasticsearch5SearchBackend.mapping_class( models.Novel) self.obj = models.Novel.objects.get(id=4)