diff --git a/eventbrite/apiv3_url_mapping.json b/eventbrite/apiv3_url_mapping.json index 7cee173..bfd1af4 100644 --- a/eventbrite/apiv3_url_mapping.json +++ b/eventbrite/apiv3_url_mapping.json @@ -17,6 +17,18 @@ "serializer": "Event", "url_regexp": "^events/(?P\\d+)/$" }, + { + "data_type": "serialized", + "response_type": "single_response", + "serializer": "Event", + "url_regexp": "^events/(?P\\d+)/publish/$" + }, + { + "data_type": "serialized", + "response_type": "single_response", + "serializer": "Event", + "url_regexp": "^events/(?P\\d+)/unpublish/$" + }, { "data_type": "serialized", "response_type": "paginated_response", @@ -366,4 +378,4 @@ "serializer": "MobileDevice", "url_regexp": "^devices/me/$" } -] \ No newline at end of file +] diff --git a/eventbrite/client.py b/eventbrite/client.py index dc8614d..2ce28f1 100755 --- a/eventbrite/client.py +++ b/eventbrite/client.py @@ -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) diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index 5c8cdc8..1db601a 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -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()) ) diff --git a/tests/integration/test_events.py b/tests/integration/test_events.py index 416855e..3207749 100644 --- a/tests/integration/test_events.py +++ b/tests/integration/test_events.py @@ -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: @@ -21,6 +22,8 @@ except KeyError: skip_user_id_tests = True +EB_ISO_FORMAT = '%Y-%m-%dT%H:%M:%SZ' + class TestEvents(unittest.TestCase): @@ -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', @@ -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()