Skip to content

Commit

Permalink
Events can now be created. Fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Greenfeld committed Jan 31, 2015
1 parent e238e7d commit 5c93e1a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 62 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ History
3.0.2 (2014-01-30)
------------------

* Added feature allowing the use of Eventbrite API url at test servers. Should help expedite development of tricky post actions.
* Event creation now working.
* Added feature allowing the use of Eventbrite API url at test servers. Should expedite development of tricky post actions.


3.0.1 (2014-01-30)
Expand Down
15 changes: 12 additions & 3 deletions eventbrite/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
from platform import platform

import requests
Expand Down Expand Up @@ -58,11 +59,13 @@ def get(self, path, data=None, expansions=()):
@objectify
def post(self, path, data=None, expansions=()):
path = format_path(path, self.eventbrite_api_url)
return requests.post(path, headers=self.headers, data=data or {})
json_data = json.dumps(data or {})
return requests.post(path, headers=self.headers, data=json_data)

@objectify
def delete(self, path, data=None, expansions=()):
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 Expand Up @@ -148,7 +151,7 @@ def get_event_discounts(self, event_id):
"""
return self.get("/events/{0}/discounts/".format(event_id))

def create_event_discount(self, event_id,
def post_event_discount(self, event_id,
discount_code,
discount_amount_off=None,
discount_percent_off=None,
Expand All @@ -166,9 +169,10 @@ def create_event_discount(self, event_id,
discount_quantity_available integer optional Number of discount uses
discount_start_date datetime optional Allow use from this date
discount_end_date datetime optional Allow use until this date
TODO: Consider deprecating this method
"""
data = construct_namespaced_dict("discount", locals())
return data
return self.post("/events/{0}/discounts/".format(event_id), data=data)

def get_event_discount_by_id(self, event_id, discount_id):
Expand All @@ -177,6 +181,11 @@ def get_event_discount_by_id(self, event_id, discount_id):
"""
return self.get("/events/{0}/discounts/{1}/".format(event_id, discount_id))

def post_event(self, data):

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


def webhook_to_object(self, webhook):
"""
Converts JSON sent by an Eventbrite Webhook to the appropriate Eventbrite object.
Expand Down
22 changes: 1 addition & 21 deletions eventbrite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create(cls, response):
evbobject.reason = response.reason
evbobject.status_code = response.status_code
api_data_type = reverse(evbobject.resource_uri)
# TODO: figure out what to do with enpoint, which don't have defined serializer
# TODO: figure out what to do with endpoint, which doesn't have defined serializer
# TODO: solve issue with non-standard serializes not mapping directly to defined objects
evbobject.type = api_data_type.get("serializer", "")
# if it's paginated, it's a list, otherwise we don't know yet
Expand All @@ -37,26 +37,6 @@ def create(cls, response):
evbobject.pagination = data.get('pagination')
return evbobject

# @classmethod
# def _set_from_reverse(cls, evbobject):
# api_data_type = reverse(evbobject.resource_uri)
# # TODO: figure out what to do with enpoint, which don't have defined serializer
# # TODO: solve issue with non-standard serializes not mapping directly to defined objects
# evbobject.type = api_data_type.get("serializer", "")
# # if it's paginated, it's a list, otherwise we don't know yet
# if api_data_type.get("response_type") == "paginated_response":
# evbobject.is_list = evbobject.is_paginated = True
# else:
# evbobject.is_list = evbobject.is_paginated = False
# return evbobject

# def _set_from_data(self, data):
# self.pk = self.id = data.get('id')
# self.pagination = data.get('pagination')

# @property
# def is_paginated(self):
# return bool(self.pagination)

@property
def pretty(self):
Expand Down
37 changes: 0 additions & 37 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,3 @@ 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_post_event(self):

user = self.eventbrite.get_user()
event = {
'name': {
'html': 'client_test_{0}'.format(datetime.now()),
},
'organizer_id': user['id'],
'start': {
'utc': '2015-03-07T20:00:00Z',
'timezone': 'America/Los_Angeles',
},
'end': {
'utc': '2015-03-07T23:00:00Z',
'timezone': 'America/Los_Angeles',
},
'currency': 'USD',
'venue_id': '9053805',
'online_event': False,
'listed': False,
'category_id': '110',
'format_id': '5',
'password': "test",
'capacity': 10,
#'description': {
# 'html': 'html description',
#},
}
response = self.eventbrite.post('/events/', data=event)



if __name__ == '__main__':
unittest.main()
66 changes: 66 additions & 0 deletions tests/integration/test_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from datetime import timedelta, datetime
import os
import json

from eventbrite import Eventbrite
from eventbrite.utils import EVENTBRITE_API_URL

from ..base import unittest

try:
OAUTH_TOKEN = os.environ[u'EVENTBRITE_OAUTH_TOKEN']
skip_integration_tests = False
except KeyError:
skip_integration_tests = True

try:
USER_ID = os.environ[u'EVENTBRITE_USER_ID']
skip_user_id_tests = False
except KeyError:
skip_user_id_tests = True


class TestEvents(unittest.TestCase):

def setUp(self):
self.eventbrite = Eventbrite(OAUTH_TOKEN)

@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_post_event(self):

event_name = 'client_test_{0}'.format(datetime.now())

event_data = {
'event.name': {
'html': event_name,
},
'event.start': {
'utc': '2015-03-07T20:00:00Z',
'timezone': 'America/Los_Angeles',
},
'event.end': {
'utc': '2015-03-07T23:00:00Z',
'timezone': 'America/Los_Angeles',
},
'event.currency': 'USD',
'event.online_event': True,
'event.listed': False,
'event.category_id': '110',
'event.format_id': '5',
'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")


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

0 comments on commit 5c93e1a

Please sign in to comment.