def test_age_filter(self):
     arg = {
         "gte": "age_35",
         "lt": "age_40",
     }
     self.assertEqual(self.serialize_as_dict(arg, type=self.AGE),
                      AgeFilter(**arg).as_json_dict())
Exemple #2
0
    def test_narrowcast_redelivery_recipient_text_message(self):
        responses.add(
            responses.POST,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast',
            json={},
            status=200,
        )

        self.tested.narrowcast(
            self.text_message,
            recipient=And(
                AudienceRecipient(group_id=5614991017776),
                Not(RedeliveryRecipient(request_id='request_id_test'))),
            filter=Filter(demographic=AgeFilter(gte="age_35", lt="age_40")),
            limit=Limit(max=10),
        )

        request = responses.calls[0].request
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast')
        self.assertEqual(request.method, 'POST')
        self.assertEqual(
            json.loads(request.body), {
                "messages": self.message,
                "recipient": {
                    "type":
                    "operator",
                    "and": [{
                        "type": "audience",
                        "audienceGroupId": 5614991017776
                    }, {
                        "type": "operator",
                        "not": {
                            "type": "redelivery",
                            "requestId": "request_id_test"
                        }
                    }]
                },
                "filter": {
                    "demographic": {
                        "type": "age",
                        "gte": "age_35",
                        "lt": "age_40"
                    }
                },
                "limit": {
                    "max": 10,
                    "upToRemainingQuota": False,
                },
                "notificationDisabled": False,
            })
Exemple #3
0
    def test_narrowcast_simple_text_message(self):
        responses.add(
            responses.POST,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast',
            json={},
            status=200,
            headers={'X-Line-Request-Id': 'request_id_test'},
        )

        self.tested.narrowcast(
            self.text_message,
            recipient=AudienceRecipient(group_id=5614991017776),
            filter=Filter(demographic=AgeFilter(gte="age_35", lt="age_40")),
            limit=Limit(max=10),
        )

        request = responses.calls[0].request
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast')
        self.assertEqual(request.method, 'POST')
        self.assertEqual(
            json.loads(request.body), {
                "messages": self.message,
                "recipient": {
                    'audienceGroupId': 5614991017776,
                    'type': 'audience'
                },
                "filter": {
                    "demographic": {
                        "type": "age",
                        "gte": "age_35",
                        "lt": "age_40"
                    }
                },
                "limit": {
                    "max": 10,
                    "upToRemainingQuota": False,
                },
                "notificationDisabled": False,
            })
    def test_narrowcast_text_message(self):
        responses.add(
            responses.POST,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast',
            json={},
            status=200,
            headers={'X-Line-Request-Id': 'request_id_test'},
        )

        response = self.tested.narrowcast(
            self.text_message,
            recipient=And(AudienceRecipient(group_id=5614991017776),
                          Not(AudienceRecipient(group_id=4389303728991))),
            filter=Filter(demographic=Or(
                And(GenderFilter(one_of=["male", "female"]),
                    AgeFilter(gte="age_20", lt="age_25"),
                    AppTypeFilter(one_of=["android", "ios"]),
                    AreaFilter(one_of=["jp_23", "jp_05"]),
                    SubscriptionPeriodFilter(gte="day_7", lt="day_30")),
                And(AgeFilter(gte="age_35", lt="age_40"),
                    Not(GenderFilter(one_of=["male"]))))),
            limit=Limit(max=100),
        )

        request = responses.calls[0].request
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/narrowcast')
        self.assertEqual(request.method, 'POST')
        self.assertEqual(
            json.loads(request.body), {
                "messages": self.message,
                "recipient": {
                    "type":
                    "operator",
                    "and": [{
                        'audienceGroupId': 5614991017776,
                        'type': 'audience'
                    }, {
                        "type": "operator",
                        "not": {
                            "type": "audience",
                            "audienceGroupId": 4389303728991
                        }
                    }]
                },
                "filter": {
                    "demographic": {
                        "type":
                        "operator",
                        "or": [{
                            "type":
                            "operator",
                            "and": [{
                                "type": "gender",
                                "oneOf": ["male", "female"]
                            }, {
                                "type": "age",
                                "gte": "age_20",
                                "lt": "age_25"
                            }, {
                                "type": "appType",
                                "oneOf": ["android", "ios"]
                            }, {
                                "type": "area",
                                "oneOf": ["jp_23", "jp_05"]
                            }, {
                                "type": "subscriptionPeriod",
                                "gte": "day_7",
                                "lt": "day_30"
                            }]
                        }, {
                            "type":
                            "operator",
                            "and": [{
                                "type": "age",
                                "gte": "age_35",
                                "lt": "age_40"
                            }, {
                                "type": "operator",
                                "not": {
                                    "type": "gender",
                                    "oneOf": ["male"]
                                }
                            }]
                        }]
                    }
                },
                "limit": {
                    "max": 100
                }
            })
        self.assertEqual('request_id_test', response.request_id)