コード例 #1
0
class OccurenceTest(TestCase):
    def setUp(self):
        self.cal1 = Calendar(name='cal1', color='dddddd')
        self.cal1.save()
        self.events = (Event(name='e0'),
                       Event(name='e1'),
                       Event(name='e2'),
                       Event(name='e3'),
                       Event(name='e4'),
                       Event(name='e5'),
                       Event(name='e6'))

        # event that starts before and ends after on April 1
        self.events[0].start = dt(2014, 3, 30, 15)
        self.events[0].end = dt(2014, 4, 4, 12)
        # event that starts and ends on April 1
        self.events[1].start = dt(2014, 4, 1, 10)
        self.events[1].end = dt(2014, 4, 1, 17)
        # event that starts before and ends on April 1
        self.events[2].start = dt(2014, 3, 30, 10)
        self.events[2].end = dt(2014, 4, 1, 12)
        # event that starts on and ends after April 1
        self.events[3].start = dt(2014, 4, 1, 10)
        self.events[3].end = dt(2014, 4, 3, 12)
        # event that starts and ends after April 1
        self.events[4].start = dt(2014, 3, 20, 10)
        self.events[4].end = dt(2014, 3, 25, 14)
        # event that starts and ends after April 1
        self.events[5].start = dt(2014, 4, 3, 10)
        self.events[5].end = dt(2014, 4, 3, 14)
        # daily event with one occurence on April 1
        self.events[6].start = dt(2014, 3, 25, 10)
        self.events[6].end = dt(2014, 3, 25, 14)
        self.events[6].recurrence = Recurrence(frequency='DAILY', count=10)

        for e in self.events:
            e.calendar = self.cal1
            e.save()
            e.create_and_save_occurences()

    def tearDown(self):
        for e in self.events:
            del e

    def test_get_occurences_for_day(self):
        occurences = Occurence.get_occurences_for_day(datetime.date(2014, 4, 1))
        self.assertEqual(list(occurences),
                         [self.events[2].occurence_set.all()[0],
                          self.events[0].occurence_set.all()[0],
                          self.events[1].occurence_set.all()[0],
                          self.events[3].occurence_set.all()[0],
                          self.events[6].occurence_set.all()[7]])
コード例 #2
0
    def handle_noargs(self, **options):
        self.stdout.write('Checking for existing data ...')
        try:
            cal = Calendar.objects.get(name='Example Calendar', color='ff0000')
            self.stdout.write('It looks like you already have loaded this sample data, quitting.')
            sys.exit(1)
        except Calendar.DoesNotExist:
            self.stdout.write('No sample data found in db.')
            self.stdout.write('Install it...')

        self.stdout.write('Create User ...')
        user1 = User.objects.create_user('user1',
                                         '*****@*****.**',
                                         'userpassword')
        user1.save()

        self.stdout.write('Create Example Calendar ...')
        cal = Calendar(name='Example Calendar', color='dddddd')
        cal.save()

        self.stdout.write('The Example Calendar is created.')

        event = Event(recurrence=None,
                      name='Example Single Event',
                      calendar=cal
                      )
        event.start = dt(2014, 5, 1, 17)
        event.end = dt(2014, 5, 1, 19)
        event.save()
        event.create_and_save_occurences()

        rec = Recurrence(frequency='DAILY',
#            start=datetime.datetime(2014, 3, 30, 13),
            count=10)
        rec.save()

        event = Event(recurrence=rec,
                      name='Example Daily Event',
                      calendar=cal)
        event.start = dt(2014, 5, 1, 13)
        event.end = dt(2014, 5, 1, 18)
        event.save()
        event.create_and_save_occurences()




        """
コード例 #3
0
    def setUp(self):
        self.cal1 = Calendar(name='cal1', color='dddddd')
        self.cal1.save()
        self.events = (Event(name='e0'),
                       Event(name='e1'),
                       Event(name='e2'),
                       Event(name='e3'),
                       Event(name='e4'),
                       Event(name='e5'),
                       Event(name='e6'))

        # event that starts before and ends after on April 1
        self.events[0].start = dt(2014, 3, 30, 15)
        self.events[0].end = dt(2014, 4, 4, 12)
        # event that starts and ends on April 1
        self.events[1].start = dt(2014, 4, 1, 10)
        self.events[1].end = dt(2014, 4, 1, 17)
        # event that starts before and ends on April 1
        self.events[2].start = dt(2014, 3, 30, 10)
        self.events[2].end = dt(2014, 4, 1, 12)
        # event that starts on and ends after April 1
        self.events[3].start = dt(2014, 4, 1, 10)
        self.events[3].end = dt(2014, 4, 3, 12)
        # event that starts and ends after April 1
        self.events[4].start = dt(2014, 3, 20, 10)
        self.events[4].end = dt(2014, 3, 25, 14)
        # event that starts and ends after April 1
        self.events[5].start = dt(2014, 4, 3, 10)
        self.events[5].end = dt(2014, 4, 3, 14)
        # daily event with one occurence on April 1
        self.events[6].start = dt(2014, 3, 25, 10)
        self.events[6].end = dt(2014, 3, 25, 14)
        self.events[6].recurrence = Recurrence(frequency='DAILY', count=10)

        for e in self.events:
            e.calendar = self.cal1
            e.save()
            e.create_and_save_occurences()
コード例 #4
0
 def setUp(self):
     self.u1 = User.objects.create(username='******')
     self.u1.set_password('password1')
     self.u1.save()
     self.cal1 = Calendar(name='cal1', color='dddddd')
     self.cal1.save()
コード例 #5
0
 def _generate_default_calendar(self):
     calendar = Calendar(name='calendar', color='dddddd')
     calendar.save()
     return calendar
コード例 #6
0
class GroupCalendarViewTests(TestCase):
    def _generate_default_calendar(self):
        calendar = Calendar(name='calendar', color='dddddd')
        calendar.save()
        return calendar

    def _generate_default_event(self):
        event = Event(name='event', calendar=self.cal1)
        event.start = dt(2014, 4, 1, 12)
        event.end = dt(2014, 4, 1, 15)
        event.save()
        event.create_and_save_occurences()
        return event

    def setUp(self):
        self.u1 = User.objects.create(username='******')
        self.u1.set_password('password1')
        self.u1.save()
        self.cal1 = Calendar(name='cal1', color='dddddd')
        self.cal1.save()

    def tearDown(self):
        del self.cal1

    def test_calendar_list(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:calendar_list'))
        self.assertContains(response, 'Add calendar')

    def test_calendar_add(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:calendar_add'))
        self.assertContains(response, 'form')
        # TODO: continue

    def test_calendar_detail(self):
        self.client.login(username=self.u1.username, password='******')
        calendar = self._generate_default_calendar()
        response = self.client.get(reverse('groupcalendar:calendar_detail',
            args={calendar.id}), follow=True)
        self.assertContains(response, calendar.name)
        # TODO: continue

    def test_calendar_update(self):
        self.client.login(username=self.u1.username, password='******')
        calendar = self._generate_default_calendar()
        response = self.client.get(reverse('groupcalendar:calendar_update',
            args={calendar.id}), follow=True)
        self.assertContains(response, 'form')
        # TODO: continue

    def test_calendar_delete(self):
        self.client.login(username=self.u1.username, password='******')
        calendar = self._generate_default_calendar()
        self.assertEqual(1, len(Calendar.objects.filter(id=calendar.id)))
        response = self.client.get(reverse('groupcalendar:calendar_delete',
            args={calendar.id}), follow=True)
        post_response = self.client.post(reverse('groupcalendar:calendar_delete',
            args=(calendar.id,)), follow=True)
        self.assertRedirects(post_response, reverse('groupcalendar:calendar_list'), status_code=302)
        self.assertEqual(0, len(Calendar.objects.filter(id=calendar.id)))
        # TODO: test that calendar that have associated events are not deleted



    def test_event_add(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:event_add'))
        self.assertContains(response, 'form')
        # TODO: continue

    def test_event_detail(self):
        self.client.login(username=self.u1.username, password='******')
        event = self._generate_default_event()
        response = self.client.get(reverse('groupcalendar:event_detail',
            args={event.id}), follow=True)
        self.assertContains(response, event.name)
        # TODO: continue

    def test_event_update(self):
        self.client.login(username=self.u1.username, password='******')
        event = self._generate_default_event()
        response = self.client.get(reverse('groupcalendar:calendar_update',
            args={event.id}), follow=True)
        self.assertContains(response, 'form')
        # TODO: continue

    def test_event_delete(self):
        self.client.login(username=self.u1.username, password='******')
        event = self._generate_default_event()
        self.assertEqual(1, len(Event.objects.filter(id=event.id)))
        response = self.client.get(reverse('groupcalendar:calendar_delete',
            args={event.id}), follow=True)
        post_response = self.client.post(reverse('groupcalendar:calendar_delete',
            args=(event.id,)), follow=True)
        self.assertRedirects(post_response, reverse('groupcalendar:calendar_list'), status_code=302)
        self.assertEqual(0, len(Event.objects.filter(id=event.id)))

    def test_home_view(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:home'))
        self.assertContains(response, 'Daily')
        self.assertContains(response, 'Weekly')
        self.assertContains(response, 'Monthly')

    def test_month_view(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:month'))
        self.assertContains(response, 'Monthly view')

    def test_week_view(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:week'))
        self.assertContains(response, 'Weekly view')

    def test_day_view(self):
        self.client.login(username=self.u1.username, password='******')
        response = self.client.get(reverse('groupcalendar:day'))
        self.assertContains(response, 'Daily view')