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)
python类add_callback()的实例源码
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'], '/')
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)
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'], '/')
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)
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)
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'], '/')
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')
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)
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
})
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
})
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)
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')
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)
def test_get_customer_last_action_executed_with_empty_customer_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/customers/GetCustomerLastActionExecuted',
callback=get_customer_last_action_executed_callback,
content_type='application/json'
)
client = Client('username', 'password')
self.assertRaises(Exception, client.customers.get_customer_last_action_executed, None)
def test_get_customer_last_action_executed_with_wrong_customer_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/customers/GetCustomerLastActionExecuted',
callback=get_customer_last_action_executed_callback,
content_type='application/json'
)
client = Client('username', 'password')
data = client.customers.get_customer_last_action_executed('2872723')
self.assertFalse(data)
def test_get_customer_action_details_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/GetCustomerActionDetailsByDate',
callback=get_customer_action_details_by_date_callback,
content_type='application/json'
)
client = Client('username', 'password')
self.assertRaises(Exception, client.customers.get_customer_action_details_by_date, None)
def test_get_customer_action_details_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/customers/GetCustomerActionDetailsByDate',
callback=get_customer_action_details_by_date_callback,
content_type='application/json'
)
client = Client('username', 'password')
data = client.customers.get_customer_action_details_by_date('3014-12-10')
self.assertFalse(data)
def test_get_customer_action_details_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/GetCustomerActionDetailsByDate',
callback=get_customer_action_details_by_date_callback,
content_type='application/json'
)
client = Client('username', 'password')
self.assertRaises(Exception, client.customers.get_customer_action_details_by_date, None)
def test_get_customer_action_details_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/customers/GetCustomerActionDetailsByDate',
callback=get_customer_action_details_by_date_callback,
content_type='application/json'
)
client = Client('username', 'password')
data = client.customers.get_customer_action_details_by_date('3014-12-10')
self.assertFalse(data)