def test_tag_filtering(self):
        """Tests that the tag filtering works as intended."""
        task = ExportTask.find(name="RandomExport")

        # We expect all tagged hostnames to be returned
        results = task.get_tagged_data(
            acts_on=["hostname"],
            include_tags=[],
            exclude_tags=[],
            ignore_tags=[],
            fresh_tags=True,
        )
        self.assertCountEqual(
            [r.value for r in results],
            ["asd1.com", "asd2.com", "asd3.com", "asd4.com"],
        )

        # We expect all hostnames that aren't tagged "c2"
        results = task.get_tagged_data(
            acts_on=["hostname"],
            include_tags=[],
            exclude_tags=["c2"],
            ignore_tags=[],
            fresh_tags=True,
        )
        self.assertEqual(results[0].value, "asd4.com")
        self.assertEqual(len(results), 1)

        # We expect all hostnames that are tagged "c2" but NOT "exclude"
        results = task.get_tagged_data(
            acts_on=["hostname"],
            include_tags=["c2"],
            exclude_tags=["exclude"],
            ignore_tags=[],
            fresh_tags=True,
        )
        self.assertEqual({r.value for r in results}, {"asd1.com", "asd2.com"})
        self.assertEqual(len(results), 2)

        # We expect all tagged hostnames, excpet if the only tag is "legit"
        results = task.get_tagged_data(
            acts_on=["hostname"],
            include_tags=[],
            exclude_tags=[],
            ignore_tags=["legit"],
            fresh_tags=True,
        )
        self.assertEqual(
            {r.value for r in results}, {"asd1.com", "asd2.com", "asd3.com"}
        )
        self.assertEqual(len(results), 3)
Tests that the tag filtering works as intended.
tests/core_tests/tasks.py