def test_filter_no_data(self): api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') mommy.make(Facility, name='test facility') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') result = search_filter.filter(qs, 'test') # no documents have been indexed self.assertEquals(result.count(), 0) api.delete_index('test_index')
def test_filter_data(self): api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') test_facility = mommy.make(Facility, name='test facility') index_instance(test_facility, 'test_index') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') # some weird bug there is a delay in getting the search results for x in range(0, 100): search_filter.filter(qs, 'test') api.delete_index('test_index')
def test_filter_data(self): api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') test_facility = mommy.make(Facility, name='test facility') index_instance( 'facilities', 'Facility', str(test_facility.id), 'test_index') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') # some weird bug there is a delay in getting the search results for x in range(0, 100): search_filter.filter(qs, 'test') api.delete_index('test_index')
def test_filter_elastic_not_available(self): with patch.object(ElasticAPI, 'search_document') as mock_search: mock_search.return_value = None api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') mommy.make(Facility, name='test facility') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') result = search_filter.filter(qs, 'test') # no documents have been indexed self.assertEquals(result.count(), 0) api.delete_index('test_index')
def test_seach_facility_by_code(self): mommy.make(Facility, code=17780) api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') test_facility = mommy.make(Facility, name='test facility') index_instance('facilities', 'Facility', str(test_facility.id), 'test_index') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') # some weird bug there is a delay in getting the search results for x in range(0, 100): search_filter.filter(qs, 18990) search_filter.filter(qs, 17780) api.delete_index('test_index')
class CommonFieldsFilterset(django_filters.FilterSet): """Every model that descends from AbstractBase should have this The usage pattern for this is presently simplistic; mix it in, then add to the `fields` in the filter's `Meta` `'updated', 'created', updated_before', 'created_before', 'updated_after', 'created_after'' and any other applicable / extra fields. When you inherit this, DO NOT add a `fields` declaration. Let the implicit filter fields ( every model field gets one ) stay in place. """ updated_before = IsoDateTimeFilter(name='updated', lookup_type='lte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_before = IsoDateTimeFilter(name='created', lookup_type='lte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) updated_after = IsoDateTimeFilter(name='updated', lookup_type='gte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_after = IsoDateTimeFilter(name='created', lookup_type='gte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) updated_on = IsoDateTimeFilter(name='updated', lookup_type='exact', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_on = IsoDateTimeFilter(name='created', lookup_type='exact', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) is_deleted = django_filters.BooleanFilter(name='deleted', lookup_type='exact') is_active = django_filters.BooleanFilter(name='active', lookup_type='exact') search = SearchFilter(name='search') q = SearchFilter(name='search') search_auto = AutoCompleteSearchFilter(name='search') q_auto = AutoCompleteSearchFilter(name='search')
def test_filter_elastic_not_available(self): with patch.object( ElasticAPI, 'search_document') as mock_search: mock_search.return_value = None api = ElasticAPI() api.delete_index('test_index') api.setup_index('test_index') mommy.make(Facility, name='test facility') mommy.make(Facility) qs = Facility.objects.all() search_filter = SearchFilter(name='search') result = search_filter.filter(qs, 'test') # no documents have been indexed self.assertEquals(result.count(), 0) api.delete_index('test_index')