示例#1
0
 def test_delete_index(self):
     # a very naive test. When results are checked with status codes,
     # tests pass locally but fail on circle ci
     # We leave it without any assertions for coverage's sake.
     api = ElasticAPI()
     call_command('setup_index')
     api.get_index('test_index')
     call_command('remove_index')
     api.get_index('test_index')
示例#2
0
 def test_delete_index(self):
     # a very naive test. When results are checked with status codes,
     # tests pass locally but fail on circle ci
     # We leave it without any assertions for coverage's sake.
     api = ElasticAPI()
     call_command('setup_index')
     api.get_index('test_index')
     call_command('remove_index')
     api.get_index('test_index')
示例#3
0
class TestElasticSearchAPI(TestCase):

    def setUp(self):
        self.elastic_search_api = ElasticAPI()
        super(TestElasticSearchAPI, self).setUp()

    def test_setup_index(self):
        self.elastic_search_api.delete_index(index_name='test_index')
        result = self.elastic_search_api.setup_index(index_name='test_index')
        self.assertEquals(200, result.status_code)
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_get_non_existing_index(self):
        index_name = 'test_index'
        self.elastic_search_api.delete_index(index_name)
        self.elastic_search_api.get_index(index_name)

    def test_get_exsting_index(self):
        index_name = 'test_index'
        self.elastic_search_api.setup_index(index_name=index_name)
        self.elastic_search_api.get_index(index_name)
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_delete_index(self):
        index_name = 'test_index_3'
        response = self.elastic_search_api.setup_index(index_name=index_name)
        self.assertEquals(200, response.status_code)
        self.elastic_search_api.delete_index(index_name)

    def test_index_document(self):
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        self.elastic_search_api.setup_index(index_name='test_index')
        result = index_instance(
            'facilities', 'Facility', str(facility.id), 'test_index')
        self.assertTrue(result)

    def test_search_document_no_instance_type(self):
        index_name = 'test_index'
        response = self.elastic_search_api.setup_index(index_name=index_name)
        self.assertEquals(200, response.status_code)
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        result = index_instance(
            'facilities', 'Facility', str(facility.id), 'test_index')
        self.assertTrue(result)
        self.elastic_search_api.search_document(
            index_name=index_name, instance_type=Facility, query='tree')

    def test_remove_document(self):
        index_name = 'test_index'
        self.elastic_search_api.setup_index(index_name=index_name)
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        result = index_instance(
            'facilities', 'Facility', str(facility.id), 'test_index')
        self.assertTrue(result)
        self.elastic_search_api.remove_document(
            index_name, 'facility', str(facility.id))
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_index_settings(self):
        expected_map = get_mappings()
        for key, value in expected_map.items():
            for key_2, value_2 in expected_map.get(key).items():
                for key_3, value_3 in expected_map.get(key).get(key_2).items():
                        values = expected_map.get(key).get(key_2).get(key_3)
                        self.assertEquals(
                            'autocomplete',
                            values.get('index_analyzer'))
                        self.assertEquals(
                            'autocomplete',
                            values.get('search_analyzer'))
                        self.assertEquals(
                            'string',
                            values.get('type'))
                        self.assertEquals(
                            False,
                            values.get('coerce'))
                        self.assertEquals(
                            True,
                            values.get('store'))

    def test_is_on_true(self):
        self.assertTrue(self.elastic_search_api._is_on)

    def test_is_on_false(self):
        with patch('search.search_utils.requests.get') as mock_get:
            mock_get.side_effect = ConnectionError
            elastic_api = ElasticAPI()
            self.assertFalse(elastic_api._is_on)

    def tearDown(self):
        self.elastic_search_api.delete_index(index_name='test_index')
        super(TestElasticSearchAPI, self).tearDown()
示例#4
0
 def test_create_index(self):
     call_command('setup_index')
     api = ElasticAPI()
     api.get_index('test_index')
示例#5
0
class TestElasticSearchAPI(TestCase):
    def setUp(self):
        self.elastic_search_api = ElasticAPI()
        super(TestElasticSearchAPI, self).setUp()

    def test_setup_index(self):
        self.elastic_search_api.delete_index(index_name='test_index')
        result = self.elastic_search_api.setup_index(index_name='test_index')
        self.assertEquals(200, result.status_code)
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_get_non_existing_index(self):
        index_name = 'test_index'
        self.elastic_search_api.delete_index(index_name)
        self.elastic_search_api.get_index(index_name)

    def test_get_exsting_index(self):
        index_name = 'test_index'
        self.elastic_search_api.setup_index(index_name=index_name)
        self.elastic_search_api.get_index(index_name)
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_delete_index(self):
        index_name = 'test_index_3'
        response = self.elastic_search_api.setup_index(index_name=index_name)
        self.assertEquals(200, response.status_code)
        self.elastic_search_api.delete_index(index_name)

    def test_index_document(self):
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        self.elastic_search_api.setup_index(index_name='test_index')
        result = index_instance(facility, 'test_index')
        self.assertEquals(201, result.status_code)

    def test_search_document_no_instance_type(self):
        index_name = 'test_index'
        response = self.elastic_search_api.setup_index(index_name=index_name)
        self.assertEquals(200, response.status_code)
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        result = index_instance(facility, 'test_index')
        self.assertEquals(201, result.status_code)
        self.elastic_search_api.search_document(index_name=index_name,
                                                instance_type=Facility,
                                                query='tree')

    def test_remove_document(self):
        index_name = 'test_index'
        self.elastic_search_api.setup_index(index_name=index_name)
        facility = mommy.make(Facility, name='Fig tree medical clinic')
        result = index_instance(facility, 'test_index')
        self.assertEquals(201, result.status_code)
        self.elastic_search_api.remove_document(index_name, 'facility',
                                                str(facility.id))
        self.elastic_search_api.delete_index(index_name='test_index')

    def test_index_settings(self):
        expected_map = get_mappings()
        for key, value in expected_map.items():
            for key_2, value_2 in expected_map.get(key).items():
                for key_3, value_3 in expected_map.get(key).get(key_2).items():
                    values = expected_map.get(key).get(key_2).get(key_3)
                    self.assertEquals('autocomplete',
                                      values.get('index_analyzer'))
                    self.assertEquals('autocomplete',
                                      values.get('search_analyzer'))
                    self.assertEquals('string', values.get('type'))
                    self.assertEquals(False, values.get('coerce'))
                    self.assertEquals(True, values.get('store'))

    def tearDown(self):
        self.elastic_search_api.delete_index(index_name='test_index')
        super(TestElasticSearchAPI, self).tearDown()
示例#6
0
 def test_create_index(self):
     call_command('setup_index')
     api = ElasticAPI()
     api.get_index('test_index')