Пример #1
0
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 = 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))
        """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': 'USD,4500'
        }

    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':
                (datetime.now() + timedelta(days=1)).strftime(EB_ISO_FORMAT),
                'timezone': 'America/Los_Angeles',
            },
            'event.end': {
                'utc': (datetime.now() +
                        timedelta(days=1, hours=1)).strftime(EB_ISO_FORMAT),
                'timezone':
                'America/Los_Angeles',
            },
            'event.currency': 'USD',
            'event.online_event': True,
            'event.listed': False,
            'event.category_id': '110',
            'event.format_id': '5',
            'event.password': "******",
            'event.capacity': 10,
        }
Пример #2
0
 event = eventbrite.post_event({
     'event.name': {
         'html': name
     },
     'event.start': {
         'utc':
         date.astimezone(pytz.utc).replace(
             minute=0).strftime('%Y-%m-%dT%H:%M:%SZ'),
         'timezone':
         tz.zone,
     },
     'event.end': {
         'utc': (date + datetime.timedelta(hours=3)).astimezone(
             pytz.utc).replace(
                 minute=0).strftime('%Y-%m-%dT%H:%M:%SZ'),
         'timezone':
         tz.zone,
     },
     'event.organizer_id':
     data['organizer'],
     'event.currency':
     'USD',
     'event.online_event':
     True,
     'event.listed':
     False,
     'event.password':
     data['password'],
     'event.capacity':
     data['capacity'],
 })
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 = 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))

        """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': 'USD,4500'
        }

    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': (datetime.now() + timedelta(days=1)).strftime(EB_ISO_FORMAT),
                'timezone': 'America/Los_Angeles',
            },
            'event.end': {
                'utc': (datetime.now() + timedelta(days=1,hours=1)).strftime(EB_ISO_FORMAT),
                'timezone': 'America/Los_Angeles',
            },
            'event.currency': 'USD',
            'event.online_event': True,
            'event.listed': False,
            'event.category_id': '110',
            'event.format_id': '5',
            'event.password': "******",
            'event.capacity': 10,
        }
Пример #4
0
def ticketing(request, id):
    """The post id is main article describing weekend. Looks up all event objects linked
    to the post. For each object, uses Eventbrite API to create an event page on Eventbrite,
    and creates all the usual tickets. Returns event id and adds it to event object.
    Makes all the Eventbrite events live, and publishes the main post and all event posts."""
    mainpost = Post.objects.get(id = id)
    events = Event.objects.filter(rpost = id)
    if request.method == 'POST': #We're going for it
        if request.POST.get('delay') == 'yes':
            delay = True
        else:
            delay = False
        from eventbrite import Eventbrite
        eventbrite = Eventbrite(settings.TOKEN)
        capacity = 38
        eventzone = "America/New_York"
        t1 = {'ticket_class.name': 'Children (under 12)', 'ticket_class.cost': 'USD,300', 'ticket_class.quantity_total': capacity} 
        t2 = {'ticket_class.name': 'Member', 'ticket_class.cost': 'USD,500', 'ticket_class.quantity_total': capacity} 
        t3 = {'ticket_class.name': 'Adult', 'ticket_class.cost': 'USD,500', 'ticket_class.quantity_total': capacity} 
        t4 = {'ticket_class.name': 'Senior (60+)', 'ticket_class.cost': 'USD,300', 'ticket_class.quantity_total': capacity} 
        t5 = {'ticket_class.name': 'Support new programs for the Planetarium!', 'ticket_class.donation': True} 
        t1free = {'ticket_class.name': 'Children (under 12)', 'ticket_class.free': True, 'ticket_class.quantity_total': capacity} 
        t2free = {'ticket_class.name': 'Member', 'ticket_class.free': True, 'ticket_class.quantity_total': capacity} 
        t3free = {'ticket_class.name': 'Adult', 'ticket_class.free': True, 'ticket_class.quantity_total': capacity} 
        t4free = {'ticket_class.name': 'Senior (60+)', 'ticket_class.free': True, 'ticket_class.quantity_total': capacity} 
        t5free = {'ticket_class.name': 'Support new programs for the Planetarium!', 'ticket_class.donation': True} 
        tickets = [t1, t2, t3, t4, t5]
        freetickets = [t1free, t2free, t3free, t4free, t5free]
        evresponse = {}
        tkresponse = []
        for e in events:
            if e.ebcode is None or len(e.ebcode) < 3:
                eventname = e.title
                pics = Illustration.objects.filter(event=e.id)
                if len(pics) > 0:
                   content = picparse(e.content, pics)
                else:
                   content = e.content
                eventdescription = content
                eventstart = loctime2ev(e.on)
                if e.end:
                    eventend = loctime2ev(e.end)
                else:
                    eventend = loctime2ev(e.on + timedelta(minutes = 60))
                #make a new event
                event = eventbrite.post_event({'event.name.html':eventname, 'event.description.html':eventdescription,
                                             'event.start.utc':eventstart, 'event.end.utc':eventend,
                                             'event.start.timezone':eventzone, 'event.end.timezone':eventzone,
                                             'event.currency': 'USD', 'event.capacity': capacity})
                evresponse['event'] = event
                #make tickets
                if e.free:
                    ticketlist = freetickets
                else:
                    ticketlist = tickets
                for ticket in ticketlist:
                    tkresponse.append(eventbrite.post_event_ticket_class(event.get('id'), ticket))
                evresponse['tickets'] = tkresponse
                e.ebcode = event.get('id') #For the ticketing box on our website
            if not delay and e.publish == False:
                e.publish = True
                e.save()
            #eventbrite.publish_event(event.get('id')) #make live on Eventbrite - does not work, API incomplete.
        if not delay and mainpost.publish == False:
            mainpost.publish = True
            mainpost.save()
    else: # Last chance to bail.
        pass        
    return render(request, 'ticketing.html', locals())