本文整理汇总了Python中aweber_api.AWeberAPI类的典型用法代码示例。如果您正苦于以下问题:Python AWeberAPI类的具体用法?Python AWeberAPI怎么用?Python AWeberAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AWeberAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAWeberCollection
class TestAWeberCollection(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
self.lists = self.aweber.load_from_url('/accounts/1/lists')
self.aweber.adapter.requests = []
def test_should_be_a_collection(self):
self.assertTrue(type(self.lists), AWeberCollection)
def test_should_have_24_lists(self):
self.assertTrue(len(self.lists), 24)
def test_should_be_able_get_each_via_offset(self):
for i in range(0, 23):
list = self.lists[i]
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
def test_should_be_able_to_iterate_on_collection(self):
list_number = 0
for list in self.lists:
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
list_number += 1
self.assertEqual(list_number, 24)
def test_should_support_get_by_id(self):
list = self.lists.get_by_id(303449)
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
self.assertEqual(list.id, 303449)
def test_should_support_find_method(self):
base_url = '/accounts/1/lists/303449/subscribers'
subscriber_collection = self.aweber.load_from_url(base_url)
self.aweber.adapter.requests = []
subscribers = subscriber_collection.find(email='[email protected]')
request = self.aweber.adapter.requests[0]
assert subscribers != False
assert isinstance(subscribers, AWeberCollection)
assert len(subscribers) == 1
assert subscribers[0].self_link == \
'https://api.aweber.com/1.0/accounts/1/lists/303449/subscribers/50205517'
assert request['url'] == \
'{0}?ws.op=find&email=joe%40example.com'.format(base_url)
def test_find_should_handle_errors(self):
base_url = '/accounts/1/lists/303449/subscribers'
subscriber_collection = self.aweber.load_from_url(base_url)
self.assertRaises(APIException, subscriber_collection.find, name='joe')
def test_should_create_entries_with_correct_url(self):
base_url = '/accounts/1'
account = self.aweber.load_from_url(base_url)
subscribers = account.findSubscribers(email='[email protected]')
for subscriber in subscribers:
assert subscriber.url == subscriber.self_link.replace(API_BASE, '')
示例2: TestGettingParentEntry
class TestGettingParentEntry(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
self.list = self.aweber.load_from_url('/accounts/1/lists/303449')
self.account = self.aweber.load_from_url('/accounts/1')
self.custom_field = self.aweber.load_from_url('/accounts/1/lists/303449/custom_fields/1')
def test_should_be_able_get_parent_entry(self):
entry = self.list.get_parent_entry()
def test_list_parent_should_be_account(self):
entry = self.list.get_parent_entry()
self.assertEqual(type(entry), AWeberEntry)
self.assertEqual(entry.type, 'account')
def test_custom_field_parent_should_be_list(self):
entry = self.custom_field.get_parent_entry()
self.assertEqual(type(entry), AWeberEntry)
self.assertEqual(entry.type, 'list')
def test_account_parent_should_be_none(self):
entry = self.account.get_parent_entry()
self.assertEqual(entry, None)
示例3: TestMovingSubscribers
class TestMovingSubscribers(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
subscriber_url = '/accounts/1/lists/303449/subscribers/1'
new_list_url = '/accounts/1/lists/505454'
self.subscriber = self.aweber.load_from_url(subscriber_url)
self.subscriber._diff['name'] = 'Joe Schmoe'
self.list = self.aweber.load_from_url(new_list_url)
self.move_subscriber()
def move_subscriber(self, **kwargs):
self.aweber.adapter.requests = []
self.resp = self.subscriber.move(self.list, **kwargs)
self.move_req = self.aweber.adapter.requests[0]
self.get_req = self.aweber.adapter.requests[1]
def test_returned_true(self):
self.assertTrue(self.resp)
def test_should_have_requested_move_with_post(self):
self.assertEqual(self.move_req['method'], 'POST')
def test_should_have_requested_move_on_subscriber(self):
self.assertEqual(self.move_req['url'] , self.subscriber.url)
def test_should_have_requested_move_with_correct_parameters(self):
expected_params = {'ws.op': 'move', 'list_link': self.list.self_link}
self.assertEqual(self.move_req['data'], expected_params)
def test_should_make_two_requests(self):
self.assertEqual(len(self.aweber.adapter.requests), 2)
def test_should_refresh_subscriber_resource(self):
self.assertEqual(self.get_req['method'], 'GET')
self.assertEqual(self.get_req['url'] ,
'/accounts/1/lists/505454/subscribers/3')
def test_should_reset_diff(self):
self.assertEqual(self.subscriber._diff, {})
def test_should_accept_last_followup_message_number_sent(self):
self.move_subscriber(last_followup_message_number_sent=999)
expected_params = {'ws.op': 'move', 'list_link': self.list.self_link,
'last_followup_message_number_sent': 999}
self.assertEqual(self.move_req['data'], expected_params)
示例4: SubscriberTestCase
class SubscriberTestCase(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
sub_url = '/accounts/1/lists/303449/subscribers/1'
self.subscriber = self.aweber.load_from_url(sub_url)
示例5: TestAWeberCollection
class TestAWeberCollection(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
self.lists = self.aweber.load_from_url('/accounts/1/lists')
def test_should_be_a_collection(self):
self.assertTrue(type(self.lists), AWeberCollection)
def test_should_have_24_lists(self):
self.assertTrue(len(self.lists), 24)
def test_should_be_able_get_each_via_offset(self):
for i in range(0, 23):
list = self.lists[i]
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
def test_should_be_able_to_iterate_on_collection(self):
list_number = 0
for list in self.lists:
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
list_number += 1
self.assertEqual(list_number, 24)
def test_should_support_get_by_id(self):
list = self.lists.get_by_id(303449)
self.assertEqual(type(list), AWeberEntry)
self.assertEqual(list.type, 'list')
self.assertEqual(list.id, 303449)
示例6: setUp
def setUp(self):
self.aweber = AWeberAPI("1", "2")
self.aweber.adapter = MockAdapter()
sub_url = "/accounts/1/lists/303449/subscribers/2"
self.subscriber = self.aweber.load_from_url(sub_url)
self.subscriber.name = "Gary Oldman"
self.subscriber.custom_fields["New Custom Field"] = "Cookies"
示例7: TestCreateMethod
class TestCreateMethod(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
url = '/accounts/1/lists/303449/any_collection'
self.any_collection = self.aweber.load_from_url(url)
self.aweber.adapter.requests = []
self.resp = self.any_collection.create(
a_string='Bob', a_dict={'Color': 'blue'}, a_list=['apple'])
self.create_req = self.aweber.adapter.requests[0]
self.get_req = self.aweber.adapter.requests[1]
def test_should_make_request_with_correct_parameters(self):
expected_params = {'ws.op': 'create', 'a_string': 'Bob',
'a_dict': json.dumps({'Color': 'blue'}),
'a_list': json.dumps(['apple'])}
self.assertEqual(self.create_req['data'], expected_params)
def test_should_make_two_requests(self):
self.assertEqual(len(self.aweber.adapter.requests), 2)
def test_should_have_requested_create_on_cf(self):
self.assertEqual(self.create_req['url'] , self.any_collection.url)
def test_should_have_requested_create_with_post(self):
self.assertEqual(self.create_req['method'], 'POST')
def test_should_refresh_created_resource(self):
self.assertEqual(self.get_req['method'], 'GET')
self.assertEqual(self.get_req['url'] ,
'/accounts/1/lists/303449/any_collection/1')
示例8: setUp
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
sub_url = '/accounts/1/lists/303449/subscribers/2'
self.subscriber = self.aweber.load_from_url(sub_url)
self.aweber.adapter.requests = []
self.response = self.subscriber.delete()
self.req = self.aweber.adapter.requests[0]
示例9: TestMovingSubscribers
class TestMovingSubscribers(TestCase):
def setUp(self):
self.aweber = AWeberAPI("1", "2")
self.aweber.adapter = MockAdapter()
subscriber_url = "/accounts/1/lists/303449/subscribers/1"
new_list_url = "/accounts/1/lists/505454"
self.subscriber = self.aweber.load_from_url(subscriber_url)
self.subscriber._diff["name"] = "Joe Schmoe"
self.list = self.aweber.load_from_url(new_list_url)
self.move_subscriber()
def move_subscriber(self, **kwargs):
self.aweber.adapter.requests = []
self.resp = self.subscriber.move(self.list, **kwargs)
self.move_req = self.aweber.adapter.requests[0]
self.get_req = self.aweber.adapter.requests[1]
def test_returned_true(self):
self.assertTrue(self.resp)
def test_should_have_requested_move_with_post(self):
self.assertEqual(self.move_req["method"], "POST")
def test_should_have_requested_move_on_subscriber(self):
self.assertEqual(self.move_req["url"], self.subscriber.url)
def test_should_have_requested_move_with_correct_parameters(self):
expected_params = {"ws.op": "move", "list_link": self.list.self_link}
self.assertEqual(self.move_req["data"], expected_params)
def test_should_make_two_requests(self):
self.assertEqual(len(self.aweber.adapter.requests), 2)
def test_should_refresh_subscriber_resource(self):
self.assertEqual(self.get_req["method"], "GET")
self.assertEqual(self.get_req["url"], "/accounts/1/lists/505454/subscribers/3")
def test_should_reset_diff(self):
self.assertEqual(self.subscriber._diff, {})
def test_should_accept_last_followup_message_number_sent(self):
self.move_subscriber(last_followup_message_number_sent=999)
expected_params = {"ws.op": "move", "list_link": self.list.self_link, "last_followup_message_number_sent": 999}
self.assertEqual(self.move_req["data"], expected_params)
示例10: TestFailedSubscriberDelete
class TestFailedSubscriberDelete(TestCase):
def setUp(self):
self.aweber = AWeberAPI("1", "2")
self.aweber.adapter = MockAdapter()
sub_url = "/accounts/1/lists/303449/subscribers/2"
self.subscriber = self.aweber.load_from_url(sub_url)
def test_should_raise_exception_when_failing(self):
self.assertRaises(APIException, self.subscriber.delete)
示例11: set_list_names
def set_list_names(widgets):
"""Writes list names to registry record.
:param widgets: object to read data from it
:type widgets: Widgets object
"""
consumer_key = widgets['consumer_key'].value
consumer_secret = widgets['consumer_secret'].value
access_token = widgets['access_token'].value
access_secret = widgets['access_secret'].value
aweber = AWeberAPI(consumer_key, consumer_secret)
account = aweber.get_account(access_token, access_secret)
api.portal.set_registry_record(
'niteoweb.aweber.available_lists_record',
[l.name for l in account.lists],
)
示例12: connect_to_AWeber_account
def connect_to_AWeber_account(self):
app_id = '7XXXXXX8'
authorization_url = 'https://auth.aweber.com/1.0/oauth/authorize_app/%s' % app_id
print 'Go to this url in your browser: %s' % authorization_url
authorization_code = raw_input('Type code here: ')
auth = AWeberAPI.parse_authorization_code(authorization_code)
consumer_key, consumer_secret, access_key, access_secret = auth
print auth
return auth
示例13: setUp
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
cf_url = '/accounts/1/lists/303449/custom_fields'
self.cf = self.aweber.load_from_url(cf_url)
self.aweber.adapter.requests = []
self.resp = self.cf.create(name='Wedding Song')
self.create_req = self.aweber.adapter.requests[0]
self.get_req = self.aweber.adapter.requests[1]
示例14: TestSavingInvalidSubscriberData
class TestSavingInvalidSubscriberData(TestCase):
def setUp(self):
self.aweber = AWeberAPI("1", "2")
self.aweber.adapter = MockAdapter()
sub_url = "/accounts/1/lists/303449/subscribers/2"
self.subscriber = self.aweber.load_from_url(sub_url)
self.subscriber.name = "Gary Oldman"
self.subscriber.custom_fields["New Custom Field"] = "Cookies"
def test_save_failed(self):
self.assertRaises(APIException, self.subscriber.save)
示例15: TestWhenCreatingCustomFieldsFails
class TestWhenCreatingCustomFieldsFails(TestCase):
def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
cf_url = '/accounts/1/lists/505454/custom_fields'
self.cf = self.aweber.load_from_url(cf_url)
self.aweber.adapter.requests = []
def test_should_raise_exception(self):
self.assertRaises(APIException, self.cf.create, name='Duplicate Name')