Python responses 模块,POST 实例源码

我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用responses.POST

项目:pymarsys    作者:transcovo    | 项目源码 | 文件源码
def test_get_history(self):
        responses.add(
            responses.POST,
            urljoin(
                EMARSYS_URI,
                '{}/{}/'.format(CONTACT_ENDPOINT, 'getcontacthistory')
            ),
            json=EMARSYS_CONTACTS_GET_CONTACT_HISTORY_RESPONSE,
            status=200,
            content_type='application/json'
        )
        connection = SyncConnection(TEST_USERNAME, TEST_SECRET)
        contacts = Contact(connection)

        response = contacts.get_history(
            [723005829]
        )
        assert response == EMARSYS_CONTACTS_GET_CONTACT_HISTORY_RESPONSE
项目:travieso    作者:wizeline    | 项目源码 | 文件源码
def test_notify_gihub(faker):
    repo = {'owner_name': faker.domain_word(), 'name': faker.domain_word()}
    commit = uuid4().hex
    state = random.choice(['success', 'failure', 'error', 'pending']),
    job_task = faker.domain_word()
    job_id = random.randint(1, 10000)

    request_json = {
        'state': state,
        'target_url': 'https://travis-ci/{0}/{1}/jobs/{2}'.format(repo['owner_name'], repo['name'], job_id),
        'description': get_description_from_task(job_task),
        'context': job_task
    }

    responses.add(
        responses.POST,
        'https://api.github.com/repos/{0}/{1}/statuses/{2}'.format(repo['owner_name'], repo['name'], commit),
        json=request_json)

    notify_github(repo, commit, state, job_task, job_id)

    assert len(responses.calls) == 1
项目:dractor    作者:VerizonDigital    | 项目源码 | 文件源码
def test_do_post(init_kwargs):
    """Exercise the private _do_post() method"""

    # create instance of client under test
    client = WSMANClient(**init_kwargs)
    assert client

    # setup responses
    expected_url = "https://{host}:{port}/wsman".format(
        host=init_kwargs['host'],
        port=init_kwargs.get('port', 443))
    fake_response_text = b"fake response from wsman"
    responses.add(
        responses.POST,
        expected_url,
        body=fake_response_text,
        status=200,
        content_type='application/xml')
    payload = "fake"
    reply = client._do_post(payload)
    assert reply == fake_response_text
项目:helper_scripts    作者:pythonanywhere    | 项目源码 | 文件源码
def test_does_two_posts_to_static_files_endpoint(self, api_token, api_responses):
        expected_url = API_ENDPOINT.format(username=getpass.getuser()) + 'mydomain.com/static_files/'
        api_responses.add(responses.POST, expected_url, status=201)
        api_responses.add(responses.POST, expected_url, status=201)

        Webapp('mydomain.com').add_default_static_files_mappings('/project/path')

        post1 = api_responses.calls[0]
        assert post1.request.url == expected_url
        assert post1.request.headers['content-type'] == 'application/json'
        assert post1.request.headers['Authorization'] == f'Token {api_token}'
        assert json.loads(post1.request.body.decode('utf8')) == {
            'url': '/static/', 'path': '/project/path/static'
        }
        post2 = api_responses.calls[1]
        assert post2.request.url == expected_url
        assert post2.request.headers['content-type'] == 'application/json'
        assert post2.request.headers['Authorization'] == f'Token {api_token}'
        assert json.loads(post2.request.body.decode('utf8')) == {
            'url': '/media/', 'path': '/project/path/media'
        }
项目:drift    作者:dgnorth    | 项目源码 | 文件源码
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
            )
项目:wagtail-filepreviews    作者:filepreviews    | 项目源码 | 文件源码
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',
    )
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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])
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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'
        })
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
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'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_actions_by_target_group_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/GetCustomerActionsByTargetGroup',
            callback=get_customer_actions_by_target_group_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customer_actions_by_target_group(2, '3015-12-24')
        self.assertFalse(data)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_actions_by_target_group_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/GetCustomerActionsByTargetGroup',
            callback=get_customer_actions_by_target_group_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_actions_by_target_group, 2, '2015-12-24',
                          True, ['Alias', 'Country'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_one_time_actions_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/customers/GetCustomerOneTimeActionsByDate',
            callback=get_customer_one_time_actions_by_date_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_one_time_actions_by_date, None)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_one_time_actions_by_date_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/GetCustomerOneTimeActionsByDate',
            callback=get_customer_one_time_actions_by_date_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_one_time_actions_by_date, '2015-06-24',
                          True, ['Alias', 'Country'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_target_group_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/customers/GetTargetGroupChangers',
            callback=get_target_group_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_target_group_changers, '2015-09-01', None)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_target_group_changers_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/GetTargetGroupChangers',
            callback=get_target_group_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_target_group_changers('3015-09-01', '3015-09-30')
        self.assertFalse(data)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_target_group_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/customers/GetTargetGroupChangers',
            callback=get_target_group_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_target_group_changers, '2015-09-01', '2015-09-30',
                          ['Alias', 'Country'], '/')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_attribute_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/customers/GetCustomerAttributeChangers',
            callback=get_customer_attribute_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_attribute_changers, '2015-01-30', None,
                          'OptimailUnsubscribed')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_attribute_changers_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/GetCustomerAttributeChangers',
            callback=get_customer_attribute_changers_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customer_attribute_changers('3015-01-30', '3015-01-31', 'OptimailUnsubscribed')
        self.assertFalse(data)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_future_values(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/GetCustomerFutureValues',
            callback=get_customer_future_values_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customer_future_values(attribute='Country', attribute_value='Australia')
        self.assertEqual(data, {
            '631942': 342.65,
            '257938': 102.33
        })
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_future_values_alt(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/GetCustomerFutureValues',
            callback=get_customer_future_values_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customer_future_values(6)
        self.assertEqual(data, {
            '631942': 342.65,
            '257938': 102.33
        })
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_future_values_without_params(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/GetCustomerFutureValues',
            callback=get_customer_future_values_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_future_values)
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_future_values_with_wrong_params_combination(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/GetCustomerFutureValues',
            callback=get_customer_future_values_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        self.assertRaises(Exception, client.customers.get_customer_future_values, 6, 'Country')
项目:optimove    作者:nicolasramy    | 项目源码 | 文件源码
def test_get_customer_future_values_with_wrong_customer_attribute(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/GetCustomerFutureValues',
            callback=get_customer_future_values_callback,
            content_type='application/json'
        )

        client = Client('username', 'password')
        data = client.customers.get_customer_future_values(attribute='Language', attribute_value='Australia')
        self.assertFalse(data)