def test_aggregateable_get_aggregates_simple(): management.call_command("sync_es") _ = mommy.make(Channel, _quantity=3) results = Video.get_aggregates() assert len(results) == 1 assert "channel__name__raw" in results assert len(results["channel__name__raw"]) == 3
def test_aggregateable_get_aggregates_with_filters(): management.call_command("sync_es") onion = mommy.make(Channel, name="The Onion") avc = mommy.make(Channel, name="The A.V. Club") _ = mommy.make(Video, channel=onion, name="Another Test Video") _ = mommy.make(Video, channel=onion, _quantity=5) _ = mommy.make(Video, channel=avc, _quantity=5) results = Video.get_aggregates(filters={"channel__name__raw": "barf"}) assert results == {}
def test_aggregateable_get_aggregates_complete(): management.call_command("sync_es") onion = mommy.make(Channel, name="The Onion") avc = mommy.make(Channel, name="The A.V. Club") for index in range(10): _ = mommy.make(Video, channel=onion, name="Looped Video {}".format(index)) _ = mommy.make(Video, channel=onion, _quantity=5) for index in range(10): _ = mommy.make(Video, channel=avc, name="Looped Video {}".format(index+100)) results = Video.get_aggregates( query="looped", filters={"channel__name__raw": onion.name} ) assert len(results) == 0
def test_aggregateable_get_aggregates_with_query(): management.call_command("sync_es") onion = mommy.make(Channel, name="The Onion") avc = mommy.make(Channel, name="The A.V. Club") _ = mommy.make(Video, channel=onion, name="Another Test Video") _ = mommy.make(Video, channel=onion, _quantity=5) _ = mommy.make(Video, channel=avc, _quantity=5) Video.search_objects.refresh() results = Video.get_aggregates(query="test video") assert results == { "channel__name__raw": { "The Onion": 1 } }