Beispiel #1
0
    def test_status(self):
        now = timezone.now()
        event = Event.objects.get(
            title='PyCon SK 2016')  # PyCon SK 2016 is in the past
        tt = TicketType(title='Test Ticket', price=12, event=event)

        # Dates are not set or are in future ticket type is not available
        self.assertEquals(tt.status,
                          TicketType.STATUSES[TicketType.NOT_AVAILABLE])
        tt.date_from = now + day
        self.assertEquals(tt.status,
                          TicketType.STATUSES[TicketType.NOT_AVAILABLE])
        tt.date_to = now + 3 * day
        self.assertEquals(tt.status,
                          TicketType.STATUSES[TicketType.NOT_AVAILABLE])

        # ticket type is within the date range so it is TicketType.active
        tt.date_from = now - day
        self.assertEquals(tt.status, TicketType.STATUSES[TicketType.ACTIVE])

        tt.usage = 0
        self.assertEquals(tt.status, TicketType.STATUSES[TicketType.SOLDOUT])

        # passed ticket types we consider as TicketType.expired
        tt.date_from = now - 3 * day
        tt.date_to = now - day
        self.assertEquals(tt.status, TicketType.STATUSES[TicketType.EXPIRED])
Beispiel #2
0
    def test_status(self):
        now = timezone.now()
        event = Event.objects.get(title='PyCon SK 2016')  # PyCon SK 2016 is in the past
        tt = TicketType(title='Test Ticket', price=12, event=event)

        # Dates are not set or are in future ticket type is not available
        self.assertEquals(tt.status, STATUSES[NOT_AVAILABLE])
        tt.date_from = now + datetime.timedelta(days=1)
        self.assertEquals(tt.status, STATUSES[NOT_AVAILABLE])
        tt.date_to = now + datetime.timedelta(days=3)
        self.assertEquals(tt.status, STATUSES[NOT_AVAILABLE])

        # ticket type is within the date range so it is active
        tt.date_from = now - datetime.timedelta(days=1)
        self.assertEquals(tt.status, STATUSES[ACTIVE])

        # passed ticket types we consider as expired
        tt.date_from = now - datetime.timedelta(days=3)
        tt.date_to = now - datetime.timedelta(days=1)
        self.assertEquals(tt.status, STATUSES[EXPIRED])
    def test_clean_dates(self):
        """
        Cleaning models dates follow different type of rules, also depending on event
        """
        now = timezone.now()
        event = Event.objects.get(
            title='PyCon SK 2016')  # PyCon SK 2016 is in the past
        tt = TicketType(title='Test Ticket', price=12, event=event)

        # Past event and no dates raises error
        self.assertRaises(ValidationError, tt.clean)

        # Past event and dates after it raises error
        tt.date_from = now
        tt.date_to = now + datetime.timedelta(days=3)
        self.assertRaises(ValidationError, tt.clean)
        tt.date_from = parse_datetime('2016-01-11T09:00:00Z')
        self.assertRaises(ValidationError, tt.clean)

        # End date can not be before start date
        tt.date_to = tt.date_from - datetime.timedelta(days=3)
        self.assertRaises(ValidationError, tt.clean)

        # Correct data in the past before event, SAVE.
        tt.date_to = tt.date_from + datetime.timedelta(days=13)
        tt.clean()
        tt.save()

        # PyCon SK 2054 is in the future
        future_event = Event.objects.create(
            title='PyCon SK 2054',
            description='test',
            event_type=MEETUP,
            status=PUBLISHED,
            location=event.location,
            date_from=parse_datetime('2054-03-11T09:00:00Z'),
            date_to=parse_datetime('2054-03-13T18:00:00Z'))
        ftt = TicketType(title='Test Future Ticket',
                         price=120,
                         event=future_event)

        # Future event pre-populate the dates
        ftt.clean()
        self.assertAlmostEquals((ftt.date_from - now).seconds, 0)
        self.assertEquals(ftt.date_to, ftt.event.date_to)
        ftt.save()
Beispiel #4
0
    def test_clean_dates(self):
        """
        Cleaning models dates follow different type of rules, also depending on event
        """
        event = Event.objects.get(
            title='PyCon SK 2016')  # PyCon SK 2016 is in the past
        tt = TicketType(title='Test Ticket', price=12, event=event)

        # Past event and no dates raises error
        self.assertRaises(ValidationError, tt.clean)

        # Past event and dates after it raises error
        tt.date_from = now
        tt.date_to = now + 3 * day
        self.assertRaises(ValidationError, tt.clean)
        tt.date_from = parse_datetime('2016-01-11T09:00:00Z')
        self.assertRaises(ValidationError, tt.clean)

        # End date can not be before start date
        tt.date_to = tt.date_from - 3 * day
        self.assertRaises(ValidationError, tt.clean)

        # Correct data in the past before event, SAVE.
        tt.date_to = tt.date_from + 9 * day
        tt.clean()
        tt.save()

        # PyCon SK 2054 is in the future
        future_event = Event.objects.create(title='PyCon SK 2054',
                                            description='test',
                                            event_type=Event.MEETUP,
                                            status=Event.PUBLISHED,
                                            location=event.location,
                                            cfp_end=distant_future - 7 * day,
                                            date_from=distant_future,
                                            date_to=distant_future + 7 * day)
        ftt = TicketType(title='Test Future Ticket',
                         price=120,
                         event=future_event)

        # Future event pre-populate the dates
        ftt.clean()
        self.assertEquals(abs(ftt.date_from - timezone.now()).seconds, 0)
        self.assertEquals(abs(ftt.date_to - ftt.event.date_to).seconds, 0)
        ftt.save()