Skip to content

Commit

Permalink
Merge pull request #140 from SparkPost/issue133
Browse files Browse the repository at this point in the history
allow sending params in transmission list endpoint
  • Loading branch information
rajumsys committed Mar 7, 2017
2 parents 266b3a7 + 6989132 commit f3d2ec6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: analysis all build clean docs docs-install docs-open install release release-test test venv
.PHONY: analysis all build clean docs docs-install docs-open install release release-test test venv

all: clean venv install

Expand Down
13 changes: 10 additions & 3 deletions sparkpost/transmissions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import copy
import json
import warnings
from email.utils import parseaddr

from .base import Resource
Expand Down Expand Up @@ -270,15 +271,21 @@ def get(self, transmission_id):
results = self._fetch_get(transmission_id)
return results['transmission']

def list(self):
def list(self, **kwargs):
"""
Get a list of your transmissions
:param campaign_id: ID of the campaign used by the transmissions
:param template_id: ID of the template used by the transmissions
:returns: list of transmissions
:raises: :exc:`SparkPostAPIException` if API call fails
"""
results = self.request('GET', self.uri)
return results
warn_msg = 'This endpoint is deprecated. For details, '
'check https://sparkpo.st/5qcj4.'

warnings.warn(warn_msg, DeprecationWarning)
return self.request('GET', self.uri, params=kwargs)

def delete(self, transmission_id):
"""
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest==2.8.7
pytest-cov==1.8.1
requests==2.5.1
responses==0.3.0
mock==2.0.0
22 changes: 21 additions & 1 deletion test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import json
import os
import tempfile
import warnings

import pytest
import responses
import six
from mock import patch

from sparkpost import SparkPost
from sparkpost import Transmissions
Expand Down Expand Up @@ -303,7 +305,8 @@ def test_fail_get():


@responses.activate
def test_success_list():
@patch.object(warnings, 'warn')
def test_success_list(mock_warn):
responses.add(
responses.GET,
'https://api.sparkpost.com/api/v1/transmissions',
Expand All @@ -313,6 +316,23 @@ def test_success_list():
)
sp = SparkPost('fake-key')
response = sp.transmission.list()
assert mock_warn.called
assert response == []


@responses.activate
def test_success_list_with_params():
responses.add(
responses.GET,
'https://api.sparkpost.com/api/v1/transmissions?template_id=abcd',
status=200,
content_type='application/json',
body='{"results": []}',
match_querystring=True

)
sp = SparkPost('fake-key')
response = sp.transmission.list(template_id='abcd')
assert response == []


Expand Down

0 comments on commit f3d2ec6

Please sign in to comment.