예제 #1
0
    def test_slug(self):
        title_length = Event._meta.get_field('title').max_length
        slug_length = Event._meta.get_field('slug').max_length
        self.assertGreaterEqual(slug_length, title_length)

        title = random_string(title_length)
        slug = slugify(title)
        date_to = timezone.now()
        date_from = date_to + datetime.timedelta(seconds=1)
        location = models.Location.objects.order_by('?').first()
        event1 = Event(title=title,
                       slug=slug,
                       event_type=MEETUP,
                       date_from=date_from,
                       date_to=date_to,
                       location=location)
        event1.save()
        self.assertEqual(Event.objects.get(slug=slug).title, title)

        event2 = Event(title=random_string(128, unicode=True),
                       slug=slug,
                       event_type=MEETUP,
                       date_from=date_from,
                       date_to=date_to,
                       location=location)
        self.assertRaises(IntegrityError, event2.save)  # slug must be unique
예제 #2
0
 def test_cfp(self):
     event = Event(title='Test event',
                   date_from=now,
                   date_to=now + 2 * day,
                   cfp_allowed=True)
     self.assertRaises(ValidationError, event.clean)
     event1 = Event(title='Test event',
                    date_from=now,
                    date_to=now + 2 * day,
                    cfp_allowed=True,
                    cfp_end=now)
     self.assertRaises(ValidationError, event1.clean)
     event2 = Event(title='Test normal event',
                    date_from=now + 2 * day,
                    date_to=now + 3 * day,
                    cfp_end=now + day)
     self.assertIsNone(event2.clean())
예제 #3
0
 def test_cfp(self):
     now = datetime.datetime.now()
     tomorrow = now + datetime.timedelta(days=1)
     in_two_days = now + datetime.timedelta(days=2)
     later = in_two_days + datetime.timedelta(hours=1)
     event = Event(title='Test event',
                   date_from=now,
                   date_to=in_two_days,
                   cfp_allowed=True)
     self.assertRaises(ValidationError, event.clean)
     event1 = Event(title='Test event',
                    date_from=now,
                    date_to=in_two_days,
                    cfp_allowed=True,
                    cfp_end=now)
     self.assertRaises(ValidationError, event1.clean)
     event2 = Event(title='Test normal event',
                    date_from=in_two_days,
                    date_to=later,
                    cfp_end=tomorrow)
     self.assertIsNone(event2.clean())