コード例 #1
0
    def test_rule_for_slugline_startswith_WC15(self):
        rule_filter = {
            'slugline': '^WC15 '
        }

        validator = RoutingRuleValidator()
        self.assertFalse(validator.is_valid_rule(self.items[0], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[1], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[2], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[3], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[4], rule_filter))
コード例 #2
0
    def test_rule_for_body_williams_exact(self):
        rule_filter = {
            'headline': '\\bwilliams\\b'
        }

        validator = RoutingRuleValidator()
        self.assertTrue(validator.is_valid_rule(self.items[0], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[1], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[2], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[3], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[4], rule_filter))
コード例 #3
0
    def test_rule_for_subject_sport_and_body_australia(self):
        rule_filter = {
            'subject': [{'qcode': '15000000'}],
            'body': 'Australia'
        }

        validator = RoutingRuleValidator()
        self.assertFalse(validator.is_valid_rule(self.items[0], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[1], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[2], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[3], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[4], rule_filter))
コード例 #4
0
    def test_rule_for_anpa_category_e_or_s_and_genre_sidebar(self):
        rule_filter = {
            'category': [{'qcode': 'e'}, {'qcode': 's'}],
            'genre': ['sidebar']
        }

        validator = RoutingRuleValidator()
        self.assertFalse(validator.is_valid_rule(self.items[0], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[1], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[2], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[3], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[4], rule_filter))
コード例 #5
0
    def test_rule_for_slugline_startswith_WC15_genre_sidebar_or_factbox(self):
        rule_filter = {
            'slugline': '^WC15 ',
            'genre': ['sidebar', 'factbox']
        }

        validator = RoutingRuleValidator()
        self.assertFalse(validator.is_valid_rule(self.items[0], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[1], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[2], rule_filter))
        self.assertFalse(validator.is_valid_rule(self.items[3], rule_filter))
        self.assertTrue(validator.is_valid_rule(self.items[4], rule_filter))
コード例 #6
0
    def apply_routing_scheme(self, ingest_item, provider, routing_scheme):
        """
        applies routing scheme and applies appropriate action (fetch, publish) to the item
        :param item: ingest item to which routing scheme needs to applied.
        :param provider: provider for which the routing scheme is applied.
        :param routing_scheme: routing scheme.
        """
        rules = routing_scheme.get('rules', [])
        if not rules:
            logger.warning(
                "Routing Scheme % for provider % has no rules configured." %
                (provider.get('name'), routing_scheme.get('name')))

        for rule in self.__get_scheduled_routing_rules(rules):
            if RoutingRuleValidator().is_valid_rule(ingest_item,
                                                    rule.get('filter', {})):
                self.__fetch(ingest_item,
                             rule.get('actions', {}).get('fetch', []))
                self.__publish(ingest_item,
                               rule.get('actions', {}).get('publish', []))
                if rule.get('actions', {}).get('exit', False):
                    break
            else:
                logger.info(
                    "Routing rule %s of Routing Scheme %s for Provider %s did not match for item %s"
                    % (rule.get('name'), routing_scheme.get('name'),
                       provider.get('name'), ingest_item.get('_id')))