Skip to content

Commit

Permalink
Merge ef2ca57 into 97f19af
Browse files Browse the repository at this point in the history
  • Loading branch information
jdennes committed May 16, 2013
2 parents 97f19af + ef2ca57 commit 07ca128
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion createsend/createsend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
import platform
import urllib
import urllib2
import httplib
Expand Down Expand Up @@ -118,7 +120,7 @@ def stub_request(self, expected_url, filename, status=None, body=None):
def make_request(self, method, path, params={}, body="", username=None,
password=None, base_uri=None, content_type=None):
headers = {
'User-Agent': 'createsend-python-%s' % __version__,
'User-Agent': CreateSend.user_agent,
'Content-Type': 'application/json; charset=utf-8',
'Accept-Encoding' : 'gzip, deflate' }
if content_type:
Expand Down Expand Up @@ -204,6 +206,13 @@ class CreateSend(CreateSendBase):
base_uri = "https://api.createsend.com/api/v3"
oauth_uri = "https://api.createsend.com/oauth"
oauth_token_uri = "%s/token" % oauth_uri
default_user_agent = 'createsend-python-%s-%d.%d.%d-%s' % (
__version__, sys.version_info[0], sys.version_info[1],
sys.version_info[2], platform.platform())
# You can use `CreateSend.user_agent = "my user agent"` to override the
# default user agent string (CreateSend.default_user_agent) used when
# making API calls.
user_agent = default_user_agent

def __init__(self, auth=None):
super(CreateSend, self).__init__(auth)
Expand Down
14 changes: 14 additions & 0 deletions test/test_createsend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ class CreateSendTestCase(object):
"""CreateSend tests to be run in the context of both using an API key
and using OAuth."""

def test_that_default_user_agent_is_set(self):
self.cs.stub_request("clients.json", "clients.json")
cl = self.cs.clients()
self.assertEquals(self.cs.headers['User-Agent'], CreateSend.default_user_agent)
self.assertEquals(2, len(cl))

def test_that_custom_user_agent_can_be_set(self):
CreateSend.user_agent = "custom user agent"
self.cs.stub_request("clients.json", "clients.json")
cl = self.cs.clients()
self.assertEquals(self.cs.headers['User-Agent'], "custom user agent")
self.assertEquals(2, len(cl))
CreateSend.user_agent = CreateSend.default_user_agent

def test_apikey(self):
site_url = "http://iamadesigner.createsend.com"
username = "myusername"
Expand Down

0 comments on commit 07ca128

Please sign in to comment.