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)
python类GET的实例源码
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)
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)
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'
})
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'], '/')
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)
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)
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)
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'], '/')
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)
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')
def test_get_customers_by_action(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, '2015-06-24')
self.assertEqual(data, ['231342', '943157'])
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)
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'], '/')
def test_get_customer_actions_by_target_group_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/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, None)
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_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')
data = client.customers.get_customer_one_time_actions_by_date('3015-06-24')
self.assertFalse(data)