Skip to content

Commit

Permalink
Added expansions system and tests per #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Greenfeld committed May 11, 2015
1 parent 26a74e9 commit 7b30d21
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
7 changes: 6 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
History
-------

3.1.0 (2014-04-24)
------------------

* Added control over expansion of response. Documentation at http://www.eventbrite.com/developer/v3/reference/expansions/

This comment has been minimized.

Copy link
@ibarrajo

ibarrajo Aug 11, 2017

This link is now broken.


3.0.5 (2014-04-24)
------------------

* Removed 'content-type' header from all GET requests
* Removed 'content-type' header from all GET requests. Thank you @xxv for identifying the problem and contributing code.

3.0.4 (2014-03-12)
------------------
Expand Down
2 changes: 1 addition & 1 deletion eventbrite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__author__ = 'Daniel Greenfeld'
__email__ = '[email protected]'
__version__ = '3.0.5'
__version__ = '3.1.0'


from .client import Eventbrite
Expand Down
22 changes: 18 additions & 4 deletions eventbrite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def headers(self):
}
return headers

def api(self, method, path, data, expansions=()):
def api(self, method, path, data, expand=()):
method = method.strip().lower()
if method not in self.allowed_methods:
msg = "The '{0}' method is not accepted by the Eventbrite " \
Expand All @@ -54,23 +54,37 @@ def api(self, method, path, data, expansions=()):
return method(path, data)

@objectify
def get(self, path, data=None, expansions=()):
def get(self, path, data=None, expand=()):
# Resolves the search result response problem
headers = self.headers
if headers.has_key('content-type'):
headers.pop('content-type')
# Get the function path
path = format_path(path, self.eventbrite_api_url)

if data is None:
data = {}

# Manage expansions
if data.get('expand'):
# Do nothing because expand is already passed in
pass
elif expand:
# Manage expansions
data['expand'] = ','.join(expand)
else:
# Anything else is None
data['expand'] = 'none'
return requests.get(path, headers=headers, params=data or {})

@objectify
def post(self, path, data=None, expansions=()):
def post(self, path, data=None):
path = format_path(path, self.eventbrite_api_url)
json_data = json.dumps(data or {})
return requests.post(path, headers=self.headers, data=json_data)

@objectify
def delete(self, path, data=None, expansions=()):
def delete(self, path, data=None):
path = format_path(path, self.eventbrite_api_url)
json_data = json.dumps(data or {})
return requests.delete(path, headers=self.headers, data=data or {})
Expand Down
6 changes: 5 additions & 1 deletion eventbrite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class EventbriteObject(dict):
def create(cls, response):
data = response.json()
evbobject = cls(data)
evbobject.resource_uri = response.url
try:
# Strip out URL parameters for resource_uri
evbobject.resource_uri = response.url[:response.url.index('?')]
except ValueError:
evbobject.resource_uri = response.url
evbobject.ok = response.ok
evbobject.elapsed = response.elapsed
evbobject.headers = response.headers
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except ImportError:
from distutils.core import setup

__version__ = '3.0.5'
__version__ = '3.1.0'

if sys.argv[-1] == 'tag':
os.system("git tag -a %s -m 'version %s'" % (__version__, __version__))
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_get_user(self):
# check that the ID's match
self.assertEqual(evbobject.get('id'), USER_ID)


@unittest.skipIf(condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN')
def test_webhook_no_internet(self):
webhook = {
Expand All @@ -106,3 +107,15 @@ def test_webhook_no_internet(self):
}
evbobject = self.eventbrite.webhook_to_object(webhook)
self.assertTrue('id' in evbobject)


@unittest.skipIf(condition=skip_user_id_tests, reason='Needs a USER_ID')
@unittest.skipIf(condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN')
def test_get_event_expansions(self):
# Get event with no expansions
evbobject = self.eventbrite.get_event('11260994939')
self.assertFalse('ticket_classes' in evbobject)

# Now get event with ticket_classes expansion
evbobject = self.eventbrite.get_event('11260994939', expand='ticket_classes')
self.assertTrue('ticket_classes' in evbobject)
5 changes: 1 addition & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
from platform import platform

from eventbrite import __version__
from eventbrite.exceptions import InvalidResourcePath
from eventbrite.client import Eventbrite

from .base import unittest, mock


def test_headers():
eventbrite = Eventbrite('12345')
Expand All @@ -20,4 +17,4 @@ def test_headers():
system=platform(),
)
}
assert eventbrite.headers == expected_headers
assert eventbrite.headers == expected_headers

0 comments on commit 7b30d21

Please sign in to comment.