Skip to content

Commit 9554154

Browse files
deemsrichleland
authored andcommitted
Transmissions delete method
1 parent c00bb1f commit 9554154

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ Patches and suggestions
1919
- `@gnarvaja <https://github.com/gnarvaja>`_
2020
- `@pegler <https://github.com/pegler>`_
2121
- `@puttu <https://github.com/puttu>`_
22+
- Dmitry Tyukin `@deems <https://github.com/deems>`_
2223
- ADD YOURSELF HERE (and link to your github page)

sparkpost/transmissions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,17 @@ def list(self):
259259
"""
260260
results = self.request('GET', self.uri)
261261
return results
262+
263+
def delete(self, transmission_id):
264+
"""
265+
Delete a transmission by ID
266+
267+
:param str transmission_id: ID of the transmission you want to delete
268+
269+
:returns: {} if transmission is deleted
270+
:raises: :exc:`SparkPostAPIException` if transmission is not found
271+
or Canceled
272+
"""
273+
uri = "%s/%s" % (self.uri, transmission_id)
274+
results = self.request('DELETE', uri)
275+
return results

test/test_transmissions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,34 @@ def test_success_list():
271271
sp = SparkPost('fake-key')
272272
response = sp.transmission.list()
273273
assert response == []
274+
275+
276+
@responses.activate
277+
def test_success_delete():
278+
responses.add(
279+
responses.DELETE,
280+
'https://api.sparkpost.com/api/v1/transmissions/foobar',
281+
status=200,
282+
content_type='application/json',
283+
body='{}'
284+
)
285+
sp = SparkPost('fake-key')
286+
results = sp.transmission.delete('foobar')
287+
assert results == {}
288+
289+
290+
@responses.activate
291+
def test_fail_delete():
292+
responses.add(
293+
responses.DELETE,
294+
'https://api.sparkpost.com/api/v1/transmissions/foobar',
295+
status=404,
296+
content_type='application/json',
297+
body="""
298+
{"errors": [{"message": "resource not found",
299+
"description": "Resource not found:transmission id foobar""}]}
300+
"""
301+
)
302+
with pytest.raises(SparkPostAPIException):
303+
sp = SparkPost('fake-key')
304+
sp.transmission.delete('foobar')

0 commit comments

Comments
 (0)