Skip to content

Commit

Permalink
Merge branch 'ryanbagwell-add-publish-unpublish-methods'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Greenfeld committed Jul 7, 2015
2 parents 74d70db + fff2c36 commit 9c6a4a6
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 27 deletions.
14 changes: 13 additions & 1 deletion eventbrite/apiv3_url_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
"serializer": "Event",
"url_regexp": "^events/(?P<event_id>\\d+)/$"
},
{
"data_type": "serialized",
"response_type": "single_response",
"serializer": "Event",
"url_regexp": "^events/(?P<event_id>\\d+)/publish/$"
},
{
"data_type": "serialized",
"response_type": "single_response",
"serializer": "Event",
"url_regexp": "^events/(?P<event_id>\\d+)/unpublish/$"
},
{
"data_type": "serialized",
"response_type": "paginated_response",
Expand Down Expand Up @@ -366,4 +378,4 @@
"serializer": "MobileDevice",
"url_regexp": "^devices/me/$"
}
]
]
11 changes: 11 additions & 0 deletions eventbrite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ def post_event(self, data):

return self.post("/events/", data=data)

def publish_event(self, event_id):

return self.post("/events/%s/publish/" % event_id)

def unpublish_event(self, event_id):

return self.post("/events/%s/unpublish/" % event_id)

def post_event_ticket_class(self, event_id, data):
return self.post("/events/{0}/ticket_classes/".format(event_id), data=data)

def event_search(self, **data):
# Resolves the search result response problem
return self.get("/events/search/", data=data)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_api_get(self):
payload = eventbrite.api("get", "/users/me/", {})

self.assertEqual(
sorted([u'id', u'first_name', u'last_name', u'emails', u'name']),
sorted([u'id', u'image_id', u'first_name', u'last_name', u'emails', u'name']),
sorted(payload.keys())
)

Expand Down
111 changes: 86 additions & 25 deletions tests/integration/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from datetime import datetime
from datetime import datetime, timedelta
from time import strftime
import os

from eventbrite import Eventbrite

from ..base import unittest

try:
OAUTH_TOKEN = os.environ[u'EVENTBRITE_OAUTH_TOKEN']
OAUTH_TOKEN = os.environ.get('EVENTBRITE_OAUTH_TOKEN', '')
if OAUTH_TOKEN:
skip_integration_tests = False
except KeyError:
else:
skip_integration_tests = True

try:
Expand All @@ -21,6 +22,8 @@
except KeyError:
skip_user_id_tests = True

EB_ISO_FORMAT = '%Y-%m-%dT%H:%M:%SZ'


class TestEvents(unittest.TestCase):

Expand All @@ -32,19 +35,94 @@ def setUp(self):
condition=skip_integration_tests,
reason='Needs an OAUTH_TOKEN')
def test_post_event(self):

event_name = 'client_test_{0}'.format(datetime.now())
event_data = self._get_event_data(event_name)
event = self.eventbrite.post_event(event_data)
self.assertEqual(event_name, event['name']['text'])
self.assertEqual(event_name, event['name']['html'])
# Just for access to see the event, not full authentication
self.assertEqual(event['password'], "test")

@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_search_events(self):
data = {
'location.latitude': '40.4313684',
'start_date.keyword': 'today',
'location.longitude': '-79.9805005',
'location.within': '10km'
}
events = self.eventbrite.event_search(**data)
self.assertLess(events['pagination'][u'object_count'], 1000)

@unittest.skipIf(
condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN')
def test_publish_unpublish_event(self):

""" First, creat a draft event """
event_data = self._get_event_data()
event = self.eventbrite.post_event(event_data)
self.assertTrue(event.ok,
msg=event.get('error_description', None))

""" Next, create a ticket class for the event, because an event
can't be published without one """
ticket_data = self._get_ticket_data()
response = self.eventbrite.post_event_ticket_class(event['id'],
data=ticket_data)

"""Finally, try to publish the event"""
response = self.eventbrite.publish_event(event['id'])
self.assertTrue(response.ok,
msg=response.get('error_description', None))

event_data = {
"""Now try to unpublish the event"""
response = self.eventbrite.unpublish_event(event['id'])
self.assertTrue(response.ok,
msg=response.get('error_description', None))

@unittest.skipIf(
condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN')
def test_create_ticket_class(self):

event_data = self._get_event_data()
event = self.eventbrite.post_event(event_data)

ticket_data = self._get_ticket_data()
response = self.eventbrite.post_event_ticket_class(event['id'],
data=ticket_data)
self.assertTrue(response.ok,
msg=response.get('error_description', None))

def _get_ticket_data(self):

return {
'ticket_class.name': 'client_test_ticket_{0}'.format(datetime.now()),
'ticket_class.description': 'Python API Client testing',
'ticket_class.quantity_total': 100,
'ticket_class.cost': {
"currency": 'USD',
'value': 200,
}
}

def _get_event_data(self, event_name='client_test_{0}'.format(datetime.now())):
""" Returns a dictionary representing a valid event """

# if not event_name:
# event_name = 'client_test_{0}'.format(datetime.now())

return {
'event.name': {
'html': event_name,
},
'event.start': {
'utc': '2015-03-07T20:00:00Z',
'utc': (datetime.now() + timedelta(days=1)).strftime(EB_ISO_FORMAT),
'timezone': 'America/Los_Angeles',
},
'event.end': {
'utc': '2015-03-07T23:00:00Z',
'utc': (datetime.now() + timedelta(days=1,hours=1)).strftime(EB_ISO_FORMAT),
'timezone': 'America/Los_Angeles',
},
'event.currency': 'USD',
Expand All @@ -55,24 +133,7 @@ def test_post_event(self):
'event.password': "test",
'event.capacity': 10,
}
event = self.eventbrite.post('/events/', data=event_data)
self.assertEqual(event_name, event['name']['text'])
self.assertEqual(event_name, event['name']['html'])
# Just for access to see the event, not full authentication
self.assertEqual(event['password'], "test")

@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_search_events(self):
data = {
'location.latitude': '40.4313684',
'start_date.keyword': 'today',
'location.longitude': '-79.9805005',
'location.within': '10km'
}
events = self.eventbrite.event_search(**data)
self.assertLess(events['pagination'][u'object_count'], 1000)

if __name__ == '__main__':
unittest.main()

0 comments on commit 9c6a4a6

Please sign in to comment.