Пример #1
0
    def test_with_rules_and_enrichments(self):
        add_data_files(self.rules_source, _RULE_FILE_LOCATIONS)
        assert len(self.rules_source.get_all()) == len(_RULE_FILE_LOCATIONS)
        add_data_files(self.enrichment_loader_source, _ENRICHMENT_LOADER_LOCATIONS)
        assert len(self.enrichment_loader_source.get_all()) == len(_ENRICHMENT_LOADER_LOCATIONS)

        cookie_ids = _generate_cookie_ids(TestIntegration._NUMBER_OF_COOKIES)
        cookie_ids.append(NAME_ENRICHMENT_LOADER_MATCH_COOKIE)
        cookie_ids.append(NAME_RULE_MATCH_COOKIE)
        expected_number_of_times_processed = len(cookie_ids) * 2 + 1
        block_until_processed(self.cookie_jar, cookie_ids, expected_number_of_times_processed)

        self.assertEqual(self.cookie_jar.mark_as_complete.call_count, expected_number_of_times_processed)
        self.cookie_jar.mark_as_failed.assert_not_called()

        rule_checker = RuleChecker(self, self.rules_source.get_all())
        rule_checker.assert_call_counts(
            ALL_MATCH_RULE_ID, expected_number_of_times_processed, expected_number_of_times_processed)
        rule_checker.assert_call_counts(
            NO_MATCH_RULE_ID, expected_number_of_times_processed, 0)
        rule_checker.assert_call_counts(
            NAME_MATCH_RULE_ID, expected_number_of_times_processed, len(_ENRICHMENT_LOADER_LOCATIONS) - 1)
        rule_checker.assert_call_counts(
            HASH_ENRICHED_MATCH_RULE_ID, expected_number_of_times_processed, len(cookie_ids))

        enrichment_loader_checker = EnrichmentLoaderChecker(self, self.enrichment_loader_source.get_all())
        enrichment_loader_checker.assert_call_counts(
            NO_LOADER_ENRICHMENT_LOADER_ID, expected_number_of_times_processed, 0)
        enrichment_loader_checker.assert_call_counts(
            HASH_ENRICHMENT_LOADER_ID, expected_number_of_times_processed - 1, len(cookie_ids))
        enrichment_loader_checker.assert_call_counts(
            NAME_MATCH_LOADER_ENRICHMENT_LOADER_ID, expected_number_of_times_processed, 1)