Beispiel #1
0
 def setUp(self):
     self.user = user = User.objects.create(username='******')
     self.group = group = Group.objects.create(name='testgroup')
     self.user.groups.add(self.group)
     resource = Resource.objects.create(name='test1')
     current_time = now()
     start_time = current_time + datetime.timedelta(days=1)
     end_time = current_time + datetime.timedelta(days=1, hours=1)
     self.event = Event(user=user, resource=resource, start=start_time,
         end=end_time, group=group, price=0, added_by=user)
     self.qs = Event.objects.all()
Beispiel #2
0
class ChecksTestCase(test.TestCase):
    def check(self, check_function, modifier, param=None):
        extra = [] if param is None else [param]
        check_function(self.user, self.event, self.qs)
        modifier()
        self.assertRaises(ValidationError, check_function, self.user,
            self.event, self.qs)

    def setUp(self):
        self.user = user = User.objects.create(username='******')
        self.group = group = Group.objects.create(name='testgroup')
        self.user.groups.add(self.group)
        resource = Resource.objects.create(name='test1')
        current_time = now()
        start_time = current_time + datetime.timedelta(days=1)
        end_time = current_time + datetime.timedelta(days=1, hours=1)
        self.event = Event(user=user, resource=resource, start=start_time,
            end=end_time, group=group, price=0, added_by=user)
        self.qs = Event.objects.all()

    def test_future(self):
        self.check(max_entries_in_future, lambda: self.event.save())

    def test_duration_is_multiple_of(self):
        def modify_duration():
            self.event.end += datetime.timedelta(minutes=2)
        self.check(duration_is_multiple_of, modify_duration)

    def test_max_duration_per_event(self):
        def modify_duration():
            self.event.end += datetime.timedelta(minutes=2)
        self.check(max_duration_per_event, modify_duration)

    def test_max_time_till_event(self):
        self.assertRaises(ValidationError, max_time_till_event, self.user,
            self.event, self.qs)
        self.event.start = now()
        max_time_till_event(self.user, self.event, self.qs)

    def test_min_time_till_event(self):
        def modifier():
            self.event.start = now()
        self.check(min_time_till_event, modifier)

    def test_event_matches_weekday(self):
        event_matches_weekday(self.user, self.event, self.qs, '1234567')
        self.assertRaises(ValidationError, event_matches_weekday, self.user,
            self.event, self.qs, '')
        # Once we validate rule params in the admin this is no longer necessary.
        self.assertEqual(None, event_matches_weekday(self.user, self.event, self.qs))

    def test_before_after_time(self):
        # Once we validate rule params in the admin this is no longer necessary.
        self.assertEqual(None, event_before_time(self.user, self.event, self.qs))
        self.assertEqual(None, event_after_time(self.user, self.event, self.qs))

        self.event.start = now()
        self.event.end = now()

        minus1 = (now() - datetime.timedelta(hours=1)).strftime('%H:%M')
        plus1 = (now() + datetime.timedelta(hours=1)).strftime('%H:%M')

        self.assertRaises(ValidationError, event_before_time, self.user,
            self.event, self.qs, minus1)
        event_before_time(self.user, self.event, self.qs, plus1)

        self.assertRaises(ValidationError, event_after_time, self.user,
            self.event, self.qs, plus1)
        event_after_time(self.user, self.event, self.qs, minus1)

    def test_event_is_today(self):
        self.event.start = now()
        self.event.end = now()
        def modifier():
            self.event.start += datetime.timedelta(days=2)
            self.event.end += datetime.timedelta(days=2)
        self.check(is_today, modifier)

    def test_max_events_per(self):
        max_events_per(self.user, self.event, self.qs, '1/d')
        self.event.save()
        self.assertRaises(ValidationError, max_events_per, self.user,
            self.event, self.qs, '1/d')

        self.assertRaisesMessage(ValidationError, 'Improperly Configured.',
            max_events_per, self.user, self.event, self.qs, '1-d')

        self.assertRaisesMessage(ValidationError, 'Improperly Configured.',
            max_events_per, self.user, self.event, self.qs, '1/i')

        self.assertRaisesMessage(ValidationError, 'Improperly Configured.',
            max_events_per, self.user, self.event, self.qs, 'x/d')

    def test_user_is_groupmember(self):
        user_is_groupmember(self.user, self.event, self.qs, 'testgroup')
        self.assertRaises(ValidationError, user_is_groupmember, self.user,
            self.event, self.qs, 'bla')