예제 #1
0
    def setUp(self):
        self.req = ParsedRequest()
        with self.app.test_request_context(self.app.config.get("URL_PREFIX")):
            self.f = ContentFilterService(datasource="content_filters",
                                          backend=get_backend())
            self.s = SubscribersService(datasource="subscribers",
                                        backend=get_backend())

            self.articles = [
                {
                    "_id": "1",
                    "urgency": 1,
                    "headline": "story",
                    "state": "fetched"
                },
                {
                    "_id": "2",
                    "headline": "prtorque",
                    "state": "fetched"
                },
                {
                    "_id": "3",
                    "urgency": 3,
                    "headline": "creator",
                    "state": "fetched"
                },
                {
                    "_id": "4",
                    "urgency": 4,
                    "state": "fetched"
                },
                {
                    "_id": "5",
                    "urgency": 2,
                    "state": "fetched"
                },
                {
                    "_id": "6",
                    "state": "fetched"
                },
                {
                    "_id": "7",
                    "subject": [{
                        "scheme": "my_vocabulary",
                        "qcode": "MV:01"
                    }]
                },
                {
                    "_id": "8",
                    "extra": {
                        "custom_text": "my text"
                    }
                },
            ]
            self.app.data.insert("archive", self.articles)

            self.app.data.insert(
                "vocabularies",
                [
                    {
                        "_id":
                        "my_vocabulary",
                        "display_name":
                        "My Vocabulary",
                        "type":
                        "manageable",
                        "field_type":
                        None,
                        "schema": {
                            "name": {},
                            "qcode": {},
                            "parent": {}
                        },
                        "items": [{
                            "name": "option 1",
                            "qcode": "MV:01",
                            "is_active": True
                        }],
                    },
                    {
                        "_id": "custom_text",
                        "display_name": "Custom Text",
                        "type": "manageable",
                        "field_type": "text"
                    },
                ],
            )

            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 1,
                    "field": "headline",
                    "operator": "like",
                    "value": "tor",
                    "name": "test-1"
                }],
            )
            self.app.data.insert("filter_conditions", [{
                "_id": 2,
                "field": "urgency",
                "operator": "in",
                "value": "2",
                "name": "test-2"
            }])
            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 3,
                    "field": "headline",
                    "operator": "endswith",
                    "value": "tor",
                    "name": "test-3"
                }],
            )
            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 4,
                    "field": "urgency",
                    "operator": "in",
                    "value": "2,3,4",
                    "name": "test-4"
                }],
            )
            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 5,
                    "field": "headline",
                    "operator": "startswith",
                    "value": "sto",
                    "name": "test-5"
                }],
            )
            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 6,
                    "field": "my_vocabulary",
                    "operator": "in",
                    "value": "MV:01",
                    "name": "test-6"
                }],
            )
            self.app.data.insert(
                "filter_conditions",
                [{
                    "_id": 7,
                    "field": "custom_text",
                    "operator": "eq",
                    "value": "my text",
                    "name": "test-7"
                }],
            )

            self.app.data.insert(
                "content_filters",
                [{
                    "_id": 1,
                    "content_filter": [{
                        "expression": {
                            "fc": [1]
                        }
                    }],
                    "name": "soccer-only"
                }])

            self.app.data.insert(
                "content_filters",
                [{
                    "_id": 2,
                    "content_filter": [{
                        "expression": {
                            "fc": [4, 3]
                        }
                    }],
                    "name": "soccer-only2"
                }],
            )

            self.app.data.insert(
                "content_filters",
                [{
                    "_id": 3,
                    "content_filter": [{
                        "expression": {
                            "pf": [1],
                            "fc": [2]
                        }
                    }],
                    "name": "soccer-only3"
                }],
            )

            self.app.data.insert(
                "content_filters",
                [{
                    "_id":
                    4,
                    "content_filter": [{
                        "expression": {
                            "fc": [3]
                        }
                    }, {
                        "expression": {
                            "fc": [5]
                        }
                    }],
                    "name":
                    "soccer-only4",
                }],
            )

            self.app.data.insert(
                "content_filters",
                [{
                    "_id": 5,
                    "content_filter": [{
                        "expression": {
                            "fc": [6]
                        }
                    }],
                    "name": "my-vocabulary"
                }],
            )

            self.app.data.insert(
                "content_filters",
                [{
                    "_id": 6,
                    "content_filter": [{
                        "expression": {
                            "fc": [7]
                        }
                    }],
                    "name": "custom-text"
                }])

            self.app.data.insert("products", [{
                "_id": 1,
                "content_filter": {
                    "filter_id": 3,
                    "filter_type": "blocking"
                },
                "name": "p-1"
            }])

            self.app.data.insert("products", [{
                "_id": 2,
                "content_filter": {
                    "filter_id": 1,
                    "filter_type": "blocking"
                },
                "name": "p-2"
            }])

            self.app.data.insert("subscribers", [{
                "_id": 1,
                "products": [1],
                "name": "sub1"
            }])
            self.app.data.insert("subscribers", [{
                "_id": 2,
                "products": [2],
                "name": "sub2"
            }])

            self.app.data.insert(
                "routing_schemes",
                [{
                    "_id":
                    1,
                    "name":
                    "routing_scheme_1",
                    "rules": [{
                        "filter": 4,
                        "name": "routing_rule_4",
                        "schedule": {
                            "day_of_week": ["MON"],
                            "hour_of_day_from": "0000",
                            "hour_of_day_to": "2355",
                        },
                        "actions": {
                            "fetch": [],
                            "publish": [],
                            "exit": False
                        },
                    }],
                }],
            )
예제 #2
0
    def setUp(self):
        self.req = ParsedRequest()
        with self.app.test_request_context(self.app.config.get('URL_PREFIX')):
            self.f = ContentFilterService(datasource='content_filters',
                                          backend=get_backend())
            self.s = SubscribersService(datasource='subscribers',
                                        backend=get_backend())

            self.articles = [{
                '_id': '1',
                'urgency': 1,
                'headline': 'story',
                'state': 'fetched'
            }, {
                '_id': '2',
                'headline': 'prtorque',
                'state': 'fetched'
            }, {
                '_id': '3',
                'urgency': 3,
                'headline': 'creator',
                'state': 'fetched'
            }, {
                '_id': '4',
                'urgency': 4,
                'state': 'fetched'
            }, {
                '_id': '5',
                'urgency': 2,
                'state': 'fetched'
            }, {
                '_id': '6',
                'state': 'fetched'
            }]
            self.app.data.insert('archive', self.articles)

            self.app.data.insert('filter_conditions', [{
                '_id': 1,
                'field': 'headline',
                'operator': 'like',
                'value': 'tor',
                'name': 'test-1'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 2,
                'field': 'urgency',
                'operator': 'in',
                'value': '2',
                'name': 'test-2'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 3,
                'field': 'headline',
                'operator': 'endswith',
                'value': 'tor',
                'name': 'test-3'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 4,
                'field': 'urgency',
                'operator': 'in',
                'value': '2,3,4',
                'name': 'test-4'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 5,
                'field': 'headline',
                'operator': 'startswith',
                'value': 'sto',
                'name': 'test-5'
            }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 1,
                    "content_filter": [{
                        "expression": {
                            "fc": [1]
                        }
                    }],
                    "name": "soccer-only"
                }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 2,
                    "content_filter": [{
                        "expression": {
                            "fc": [4, 3]
                        }
                    }],
                    "name": "soccer-only2"
                }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 3,
                    "content_filter": [{
                        "expression": {
                            "pf": [1],
                            "fc": [2]
                        }
                    }],
                    "name": "soccer-only3"
                }])

            self.app.data.insert('content_filters', [{
                "_id":
                4,
                "content_filter": [{
                    "expression": {
                        "fc": [3]
                    }
                }, {
                    "expression": {
                        "fc": [5]
                    }
                }],
                "name":
                "soccer-only4"
            }])

            self.app.data.insert('products', [{
                "_id": 1,
                "content_filter": {
                    "filter_id": 3,
                    "filter_type": "blocking"
                },
                "name": "p-1"
            }])

            self.app.data.insert('products', [{
                "_id": 2,
                "content_filter": {
                    "filter_id": 1,
                    "filter_type": "blocking"
                },
                "name": "p-2"
            }])

            self.app.data.insert('subscribers', [{
                "_id": 1,
                "products": [1],
                "name": "sub1"
            }])
            self.app.data.insert('subscribers', [{
                "_id": 2,
                "products": [2],
                "name": "sub2"
            }])

            self.app.data.insert('routing_schemes', [{
                "_id":
                1,
                "name":
                "routing_scheme_1",
                "rules": [{
                    "filter": 4,
                    "name": "routing_rule_4",
                    "schedule": {
                        "day_of_week": ["MON"],
                        "hour_of_day_from": "0000",
                        "hour_of_day_to": "2355",
                    },
                    "actions": {
                        "fetch": [],
                        "publish": [],
                        "exit": False
                    }
                }]
            }])
예제 #3
0
    def setUp(self):
        self.req = ParsedRequest()
        with self.app.test_request_context(self.app.config.get('URL_PREFIX')):
            self.f = ContentFilterService(datasource='content_filters',
                                          backend=get_backend())
            self.s = SubscribersService(datasource='subscribers',
                                        backend=get_backend())

            self.articles = [{
                '_id': '1',
                'urgency': 1,
                'headline': 'story',
                'state': 'fetched'
            }, {
                '_id': '2',
                'headline': 'prtorque',
                'state': 'fetched'
            }, {
                '_id': '3',
                'urgency': 3,
                'headline': 'creator',
                'state': 'fetched'
            }, {
                '_id': '4',
                'urgency': 4,
                'state': 'fetched'
            }, {
                '_id': '5',
                'urgency': 2,
                'state': 'fetched'
            }, {
                '_id': '6',
                'state': 'fetched'
            }, {
                '_id':
                '7',
                'subject': [{
                    'scheme': 'my_vocabulary',
                    'qcode': 'MV:01'
                }]
            }, {
                '_id': '8',
                'extra': {
                    'custom_text': 'my text'
                }
            }]
            self.app.data.insert('archive', self.articles)

            self.app.data.insert('vocabularies', [{
                '_id':
                'my_vocabulary',
                'display_name':
                'My Vocabulary',
                'type':
                'manageable',
                'field_type':
                None,
                'schema': {
                    'name': {},
                    'qcode': {},
                    'parent': {}
                },
                'items': [{
                    'name': 'option 1',
                    'qcode': 'MV:01',
                    'is_active': True
                }]
            }, {
                '_id': 'custom_text',
                'display_name': 'Custom Text',
                'type': 'manageable',
                'field_type': 'text'
            }])

            self.app.data.insert('filter_conditions', [{
                '_id': 1,
                'field': 'headline',
                'operator': 'like',
                'value': 'tor',
                'name': 'test-1'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 2,
                'field': 'urgency',
                'operator': 'in',
                'value': '2',
                'name': 'test-2'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 3,
                'field': 'headline',
                'operator': 'endswith',
                'value': 'tor',
                'name': 'test-3'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 4,
                'field': 'urgency',
                'operator': 'in',
                'value': '2,3,4',
                'name': 'test-4'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 5,
                'field': 'headline',
                'operator': 'startswith',
                'value': 'sto',
                'name': 'test-5'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 6,
                'field': 'my_vocabulary',
                'operator': 'in',
                'value': 'MV:01',
                'name': 'test-6'
            }])
            self.app.data.insert('filter_conditions', [{
                '_id': 7,
                'field': 'custom_text',
                'operator': 'eq',
                'value': 'my text',
                'name': 'test-7'
            }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 1,
                    "content_filter": [{
                        "expression": {
                            "fc": [1]
                        }
                    }],
                    "name": "soccer-only"
                }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 2,
                    "content_filter": [{
                        "expression": {
                            "fc": [4, 3]
                        }
                    }],
                    "name": "soccer-only2"
                }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 3,
                    "content_filter": [{
                        "expression": {
                            "pf": [1],
                            "fc": [2]
                        }
                    }],
                    "name": "soccer-only3"
                }])

            self.app.data.insert('content_filters', [{
                "_id":
                4,
                "content_filter": [{
                    "expression": {
                        "fc": [3]
                    }
                }, {
                    "expression": {
                        "fc": [5]
                    }
                }],
                "name":
                "soccer-only4"
            }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 5,
                    "content_filter": [{
                        "expression": {
                            "fc": [6]
                        }
                    }],
                    "name": "my-vocabulary"
                }])

            self.app.data.insert(
                'content_filters',
                [{
                    "_id": 6,
                    "content_filter": [{
                        "expression": {
                            "fc": [7]
                        }
                    }],
                    "name": "custom-text"
                }])

            self.app.data.insert('products', [{
                "_id": 1,
                "content_filter": {
                    "filter_id": 3,
                    "filter_type": "blocking"
                },
                "name": "p-1"
            }])

            self.app.data.insert('products', [{
                "_id": 2,
                "content_filter": {
                    "filter_id": 1,
                    "filter_type": "blocking"
                },
                "name": "p-2"
            }])

            self.app.data.insert('subscribers', [{
                "_id": 1,
                "products": [1],
                "name": "sub1"
            }])
            self.app.data.insert('subscribers', [{
                "_id": 2,
                "products": [2],
                "name": "sub2"
            }])

            self.app.data.insert('routing_schemes', [{
                "_id":
                1,
                "name":
                "routing_scheme_1",
                "rules": [{
                    "filter": 4,
                    "name": "routing_rule_4",
                    "schedule": {
                        "day_of_week": ["MON"],
                        "hour_of_day_from": "0000",
                        "hour_of_day_to": "2355",
                    },
                    "actions": {
                        "fetch": [],
                        "publish": [],
                        "exit": False
                    }
                }]
            }])