python类add_callback()的实例源码

systesthelper.py 文件源码 项目:drift 作者: dgnorth 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _setup_mocking(self):
        def _mock_callback(request):
            method = request.method.lower()
            url = request.path_url
            handler = getattr(self.app, method)
            r = handler(
                url,
                data=request.body,
                headers=dict(request.headers)
            )
            return (r.status_code, r.headers, r.data)

        pattern = re.compile("{}/(.*)".format(self.host))
        methods = [
            responses.GET,
            responses.POST,
            responses.PUT,
            responses.DELETE,
            responses.PATCH,
        ]
        for method in methods:
            responses.add_callback(
                method, pattern,
                callback=_mock_callback
            )
test_models.py 文件源码 项目:wagtail-filepreviews 作者: filepreviews 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setup_mock():
    def request_callback(request):
        payload = json.loads(request.body.decode('utf8'))
        body = {
            'id': '1',
            'status': 'pending',
            'thumbnails': None,
            'url': 'https://api.filepreviews.io/v2/previews/1/',
            'preview': None,
            'original_file': None,
            'user_data': payload['data']
        }

        headers = {
            'content-type': 'application/json',
            'location': body['url']
        }

        return (201, headers, json.dumps(body))

    responses.add_callback(
        responses.POST, 'https://api.filepreviews.io/v2/previews/',
        callback=request_callback,
        content_type='application/json',
    )
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_target_group_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupName',
            callback=get_target_group_name_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.groups.get_target_group_name(42)
        self.assertEqual(data, 'Ireland VIPs Played Last 30 Days')
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_get_target_group_name_with_empty_target_group_id(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupName',
            callback=get_target_group_name_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.groups.get_target_group_name, None)
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_target_group_name_with_wrong_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupName',
            callback=get_target_group_name_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.groups.get_target_group_name(24)
        self.assertFalse(data)
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_get_target_group_id(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupID',
            callback=get_target_group_id_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.groups.get_target_group_id('UK 20VIPs')
        self.assertEqual(data, 26)
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_get_target_group_id_with_empty_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupID',
            callback=get_target_group_id_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.groups.get_target_group_id, None)
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_get_target_groups_by_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupsByDate',
            callback=get_target_groups_by_date_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.groups.get_target_groups_by_date('2015-05-31')
        self.assertEqual(data, [9, 24, 31, 36])
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_target_groups_by_date_with_empty_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupsByDate',
            callback=get_target_groups_by_date_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.groups.get_target_groups_by_date, None)
test_groups.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_get_target_groups_by_date_with_wrong_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/groups/GetTargetGroupsByDate',
            callback=get_target_groups_by_date_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.groups.get_target_groups_by_date('3015-05-31')
        self.assertFalse(data)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_value_segment_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentName',
            callback=get_value_segment_name_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segment_name(1)
        self.assertEqual(data, 'Diamond')
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_value_segment_name_with_wrong_segment_id(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentName',
            callback=get_value_segment_name_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segment_name(2)
        self.assertFalse(data)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_get_value_segment_id(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentID',
            callback=get_value_segment_id_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segment_id('Diamond')
        self.assertEqual(data, 1)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_value_segment_id_with_empty_segment_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentID',
            callback=get_value_segment_id_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.segments.get_value_segment_id, None)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_get_value_segment_id_with_wrong_segment_name(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentID',
            callback=get_value_segment_id_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segment_id('Gold')
        self.assertFalse(data)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_get_value_segments(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegments',
            callback=get_value_segments_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segments()
        self.assertEqual(data, {
            1: 'Diamond',
            2: 'Gold',
            3: 'Silver',
            4: 'Bronze'
        })
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_get_customers_by_value_segment_with_wrong_delimiter(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetCustomersByValueSegment',
            callback=get_customers_by_value_segment_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.segments.get_customers_by_value_segment, 3, '2015-05-10',
                          ['Alias', 'Country'], '/')
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_get_customers_by_value_segment_with_empty_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetCustomersByValueSegment',
            callback=get_customers_by_value_segment_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.segments.get_customers_by_value_segment, 3, None)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_customers_by_value_segment_with_wrong_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetCustomersByValueSegment',
            callback=get_customers_by_value_segment_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_customers_by_value_segment(3, '3015-05-10')
        self.assertFalse(data)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_get_value_segment_changers_with_empty_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentChangers',
            callback=get_value_segment_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.segments.get_value_segment_changers, '2015-09-01', None)
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_get_value_segment_changers_with_wrong_delimiter(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentChangers',
            callback=get_value_segment_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.segments.get_value_segment_changers, '2015-09-01', '2015-09-30',
                          ['Country', 'Alias'], '/')
test_segments.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_get_value_segment_changers_with_wrong_start_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/segments/GetValueSegmentChangers',
            callback=get_value_segment_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.segments.get_value_segment_changers('3015-09-01', '3015-09-30')
        self.assertFalse(data)
test_general.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_last_update_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/general/GetLastDataUpdate',
            callback=get_last_data_update_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.general.get_last_data_update()
        self.assertEqual(data, '2015-08-13')
test_general.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_register_event_listener(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/RegisterEventListener',
            callback=register_event_listener_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.general.register_event_listener(General.EVENT_TYPE_CAMPAIGN_PROCESSED,
                                                      'http://www.exampleurl.com/eventlistener6')
        self.assertTrue(data)
test_general.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def test_register_event_listener_with_empty_url(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/RegisterEventListener',
            callback=register_event_listener_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.general.register_event_listener,
                          General.EVENT_TYPE_CAMPAIGN_PROCESSED, None)
test_general.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_unregister_event_listener(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/UnregisterEventListener',
            callback=unregister_event_listener_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.general.unregister_event_listener(General.EVENT_TYPE_CAMPAIGN_PROCESSED)
        self.assertTrue(data)
test_general.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_unregister_event_listener_with_empty_event_type(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/UnregisterEventListener',
            callback=unregister_event_listener_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.general.unregister_event_listener, None)
test_customers.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_customers_by_action_with_empty_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/customers/GetCustomersByAction',
            callback=get_customers_by_action_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customers_by_action, 1, 2, None)
test_customers.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_get_customers_by_action_with_wrong_date(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/customers/GetCustomersByAction',
            callback=get_customers_by_action_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customers_by_action(1, 2, '3015-06-24')
        self.assertFalse(data)
test_customers.py 文件源码 项目:optimove 作者: nicolasramy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_get_customers_by_action_with_wrong_delimiter(self):
        responses.add_callback(
            responses.POST,
            'https://api.optimove.net/v3.0/general/login',
            callback=login_callback,
            content_type='application/json'
        )

        responses.add_callback(
            responses.GET,
            'https://api.optimove.net/v3.0/customers/GetCustomersByAction',
            callback=get_customers_by_action_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customers_by_action, 1, 2, '2015-06-24',
                          ['Alias', 'Country'], '/')


问题


面经


文章

微信
公众号

扫码关注公众号