def test_filter_sorted_by_related_obserables_count(self):
        """Tests entities sorted by number of related observables."""
        self.entity2.link_to(self.observable2, "a", "description_aaaa")
        self.entity2.link_to(self.observable3, "c", "description_ccc")
        self.entity2.link_to(self.observable4, "d", "description_ddd")

        self.entity3.link_to(self.observable2, "a", "description_aaaa")
        self.entity3.link_to(self.observable3, "c", "description_ccc")

        query = {"type": "campaign"}

        sorting = [["total_links", True]]
        time.sleep(1)
        entities, total = Entity.filter(
            query_args=query, offset=0, count=20, sorting=sorting, links_count=True
        )
        assert total == 2
        assert entities[0].name == "campaign2"
        assert entities[1].name == "campaign1"

        sorting = [["total_links", False]]
        entities, total = Entity.filter(
            query_args=query, offset=0, count=20, sorting=sorting, links_count=True
        )
        assert total == 2
        assert entities[0].name == "campaign1"
        assert entities[1].name == "campaign2"
Tests entities sorted by number of related observables.
tests/schemas/graph.py