Skip to content
This repository was archived by the owner on Aug 29, 2019. It is now read-only.

Commit 85ff0bc

Browse files
author
Kelly O'Brien
committed
aweber_api.entry: Schedule broadcast function
1 parent 3b85b46 commit 85ff0bc

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

aweber_api/entry.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ def findSubscribers(self, **kwargs):
121121
collection._data['total_size'] = self._get_total_size(url)
122122
return collection
123123

124+
def schedule_broadcast(self, bc_id, scheduled_for):
125+
"""Invoke the API method to schedule the given broadcast.
126+
127+
* Note:
128+
This method only works on List Entry resources and
129+
requires access to subscriber information. please
130+
refer to the AWeber API Reference Documentation at
131+
https://labs.aweber.com/docs/reference/1.0#account
132+
for more details on how to call this method.
133+
134+
"""
135+
self._method_for('list')
136+
params = {'scheduled_for': scheduled_for}
137+
query_string = urlencode(params)
138+
url = '{0}/broadcasts/{1}/schedule'.format(self.url, bc_id)
139+
self.adapter.request('POST', url, params, response='headers')
140+
124141
def _get_total_size(self, uri, **kwargs):
125142
"""Get actual total size number from total_size_link."""
126143
total_size_uri = '{0}&ws.show=total_size'.format(uri)

tests/mock_adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161
'/accounts/1/lists/303449/subscribers/1': ({
6262
'status': '201',
6363
'location': '/accounts/1/lists/505454/subscribers/3'}, None),
64+
'/accounts/1/lists/303449/broadcasts/2/schedule': ({
65+
'status': '201',
66+
'location': '/accounts/1/lists/303449/broadcasts/2/schedule'},
67+
None
68+
),
69+
'/accounts/1/lists/303449/broadcasts/3/schedule': ({
70+
'status': '400',
71+
'location': '/accounts/1/lists/303449/broadcasts/3/schedule'},
72+
'error'
73+
),
74+
6475
},
6576
'PATCH' : {
6677
'/accounts/1/lists/303449/subscribers/1': ({'status': '209'}, None),

tests/test_aweber_entry.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def setUp(self):
4141
self.account = self.aweber.load_from_url('/accounts/1')
4242

4343

44+
class ListTestCase(TestCase):
45+
46+
def setUp(self):
47+
self.aweber = AWeberAPI('1', '2')
48+
self.aweber.adapter = MockAdapter()
49+
self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449')
50+
51+
4452
class TestAWeberAccountEntry(AccountTestCase):
4553

4654
def test_should_be_an_entry(self):
@@ -110,6 +118,45 @@ def test_should_support_find_method(self):
110118
'https://api.aweber.com/1.0/accounts/1/lists/303449/subscribers/1'
111119

112120

121+
class TestListScheduleBroadcast(ListTestCase):
122+
123+
def setUp(self):
124+
super(TestAccountScheduleBroadcast, self).setUp()
125+
self.aweber.adapter.requests = []
126+
subscribers = self.list_.schedule_broadcast(
127+
bc_id=2, scheduled_for='2014-09-06 18:55:00')
128+
self.request = self.aweber.adapter.requests[0]
129+
130+
def test_should_make_post_request(self):
131+
self.assertEqual(self.request['method'], 'POST')
132+
133+
def test_should_build_correct_url(self):
134+
self.assertEqual(self.request['url'],
135+
'/accounts/1/lists/303449/broadcasts/2/schedule'
136+
)
137+
138+
def test_should_pass_scheduled_for_date(self):
139+
self.assertEqual(self.request['data'],
140+
{'scheduled_for': '2014-09-06 18:55:00'}
141+
)
142+
143+
144+
class TestListScheduleBroadcastError(ListTestCase):
145+
146+
def setUp(self):
147+
super(TestAccountScheduleBroadcastError, self).setUp()
148+
self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449')
149+
self.aweber.adapter.requests = []
150+
151+
def test_should_raise_exception_when_failing(self):
152+
self.assertRaises(
153+
APIException,
154+
self.list_.schedule_broadcast,
155+
bc_id=3,
156+
scheduled_for='2014-09-06 18:55:00',
157+
)
158+
159+
113160
class SubscriberTestCase(TestCase):
114161

115162
def setUp(self):

0 commit comments

Comments
 (0)