コード例 #1
0
 def test_get_es_search_without_es_model(self, es_data_client):
     view = ElasticAPIView()
     with pytest.raises(ImproperlyConfigured) as err:
         view.get_es_search()
         assert err.message == (
             "Cannot use %s on a view which does not have the 'es_model'" %
             view.__class__.__name__)
コード例 #2
0
    def test_get_es_excludes_fields(self):
        view = ElasticAPIView()
        assert view.get_es_excludes_fields() is None

        es_excludes_fields = ('first_name', 'last_name')
        view.es_excludes_fields = es_excludes_fields
        assert view.get_es_excludes_fields() == es_excludes_fields
コード例 #3
0
    def test_get_es_range_filter_fields(self):
        view = ElasticAPIView()
        assert view.get_es_range_filter_fields() == tuple()

        es_range_filter_fields = ('first_name', 'last_name')
        view.es_range_filter_fields = es_range_filter_fields
        assert view.get_es_range_filter_fields() == es_range_filter_fields
コード例 #4
0
 def test_get_es_client_without_es_client(self):
     view = ElasticAPIView()
     with pytest.raises(Exception) as err:
         view.get_es_client()
         assert err.message == (
             "'%s' should either include a `queryset` attribute, "
             "or override the `get_queryset()` method." %
             view.__class__.__name__)
コード例 #5
0
 def test_get_es_pagination_fields(self):
     view = ElasticAPIView()
     view.es_pagination_class = es_pagination.ElasticLimitOffsetPagination
     self.inspector.view = view
     for fields in (self.inspector.get_es_pagination_fields('/', 'GET'),
                    self.inspector.get_pagination_fields('/', 'GET')):
         field_names = [field.name for field in fields]
         assert sorted(field_names) == ['limit', 'offset']
コード例 #6
0
 def test_get_es_filter_fields(self):
     view = ElasticAPIView()
     view.es_filter_backends = (ElasticFieldsFilter, )
     view.es_filter_fields = (ESFieldFilter('score'),
                              ESFieldFilter('description'))
     self.inspector.view = view
     for fields in (self.inspector.get_es_filter_fields('/', 'GET'),
                    self.inspector.get_filter_fields('/', 'GET')):
         field_names = [field.name for field in fields]
         assert sorted(field_names) == ['description', 'score']
コード例 #7
0
    def create_view(self, es_ordering_fields):
        """Create and return test view class instance

        Args:
            es_ordering_fields (tuple): ordering fields
        Returns:
            ElasticAPIView: test view instance
        """
        view = ElasticAPIView()
        view.es_ordering_fields = es_ordering_fields
        return view
コード例 #8
0
    def create_view(self, es_search_fields):
        """Create and return test view class instance

        Args:
            es_search_fields ([ESFieldFilter]): search fields
        Returns:
            ElasticAPIView: test view instance
        """
        view = ElasticAPIView()
        view.es_model = DataDocType
        view.es_search_fields = es_search_fields
        return view
コード例 #9
0
    def create_view(self, es_geo_location_field, es_geo_location_field_name):
        """Create and return test view class instance

        Args:
            es_geo_location_field  ESFieldFilter
        Returns:
            ElasticAPIView: test view instance
        """
        view = ElasticAPIView()
        view.es_model = DataDocType
        view.es_geo_location_field = es_geo_location_field
        view.es_geo_location_field_name = es_geo_location_field_name
        return view
コード例 #10
0
    def create_view(self, es_client):
        """Create and return test view class instance

        Args:
            es_client (Elasticsearch): elasticsearch connection client
        Returns:
            ElasticAPIView: test view instance
        """
        view = ElasticAPIView()
        view.es_client = es_client
        view.es_model = DataDocType
        view.es_filter_backends = (ElasticSearchFilter, ElasticFieldsFilter,
                                   ElasticFieldsRangeFilter,
                                   ElasticOrderingFilter)
        return view
コード例 #11
0
 def test_get_link(self):
     view = ElasticAPIView()
     view.es_filter_backends = (ElasticFieldsFilter,
                                ElasticFieldsRangeFilter,
                                ElasticOrderingFilter, ElasticSearchFilter)
     view.es_filter_fields = (ESFieldFilter('score'),
                              ESFieldFilter('description'))
     view.es_range_filter_fields = (ESFieldFilter('date'), )
     view.es_pagination_class = es_pagination.ElasticLimitOffsetPagination
     self.inspector.view = view
     link = self.inspector.get_link('/', 'GET', 'localhost')
     field_names = [field.name for field in link.fields]
     assert sorted(field_names) == [
         'date', 'description', 'limit', 'offset', 'ordering', 'score',
         'search'
     ]
コード例 #12
0
 def test_get_es_client(self, es_data_client):
     view = ElasticAPIView()
     view.es_client = es_data_client
     assert view.get_es_client() == es_data_client
コード例 #13
0
 def test_get_es_client_with_wrong_es_client(self):
     view = ElasticAPIView()
     view.es_client = str
     with pytest.raises(ValueError):
         view.get_es_client()