def test_clone_with_different_class(self): """ Verify that clone does not copy aggregation_key and distinct_result_count when using different class.""" queryset = DistinctCountsSearchQuerySet() facet_field = 'pacing_type' agg_filter = ESDSLQ('match_all') agg = TermsFacet(field=facet_field) queryset.aggs.bucket('_filter_' + facet_field, 'filter', filter=agg_filter).bucket(facet_field, agg.get_aggregation()) queryset.aggregation_key = 'aggregation_key' queryset._distinct_result_count = 123 clone = queryset._clone(klass=Search) assert isinstance(clone, Search) assert queryset.to_dict() == clone.to_dict() assert not hasattr(clone, 'aggregation_key') assert not hasattr(clone, '_distinct_result_count')
def test_clone(self): """ Verify that clone copies all fields, including the aggregation_key and distinct_hit_count.""" queryset = DistinctCountsSearchQuerySet() facet_field = 'pacing_type' agg_filter = ESDSLQ('match_all') agg = TermsFacet(field=facet_field) queryset.aggs.bucket('_filter_' + facet_field, 'filter', filter=agg_filter).bucket(facet_field, agg.get_aggregation()) queryset.aggregation_key = 'aggregation_key' queryset._distinct_result_count = 123 clone = queryset._clone() assert queryset.to_dict() == clone.to_dict() assert queryset.aggregation_key == clone.aggregation_key assert queryset._distinct_result_count == clone._distinct_result_count
def test_validate_raises_when_configured_with_facet_with_unsupported_options( self): """ Verify that validate raises when Query configured with facet with unsupported options.""" # The add date facet action on DistinctCountsSearchQuerySet raises when unsupported options are passed, # so configure a field facet with those options on a normal FacetedSearch or Search and then clone # it to a DistinctCountsSearchQuery. queryset = DistinctCountsSearchQuerySet( index=CourseRunDocument._index._name) facet_field = 'pacing_type' agg_filter = ESDSLQ('match_all') agg = TermsFacet(field=facet_field, order='term') queryset.aggs.bucket('_filter_' + facet_field, 'filter', filter=agg_filter).bucket(facet_field, agg.get_aggregation()) queryset = queryset._clone(klass=DistinctCountsSearchQuerySet) queryset.aggregation_key = 'aggregation_key' with pytest.raises(RuntimeError) as err: queryset.validate() assert 'only supports a limited set of field facet options' in str( err.value)