Пример #1
0
 def testServeException(self):
     event = RecurringEventPage(slug="test-meeting",
                                title="Test Meeting",
                                repeat=Recurrence(dtstart=dt.date(
                                    1988, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[MO, WE, FR]),
                                time_from=dt.time(13),
                                time_to=dt.time(15, 30))
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     info = ExtraInfoPage(owner=self.user,
                          overrides=event,
                          except_date=dt.date(1988, 11, 11),
                          extra_title="System Demo",
                          extra_information="<h3>System Demo</h3>")
     event.add_child(instance=info)
     info.save_revision().publish()
     response = self.handler.serve(
         info,
         self._getRequest("/events/test-meeting/1998-11-11/extra-info/"
                          "?format=google"))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(
         response.url,
         "http://www.google.com/calendar/event?action=TEMPLATE&"
         "text=Test+Meeting&"
         "dates=19880101T130000%2F19880101T153000&"
         "ctz=Asia%2FTokyo&"
         "recur=RRULE%3AFREQ%3DWEEKLY%3BWKST%3DSU%3BBYDAY%3DMO%2CWE%2CFR")
Пример #2
0
    def testServeExtraInfo(self):
        info = ExtraInfoPage(owner = self.user,
                             overrides = self.event,
                             except_date = dt.date(2017,2,7),
                             extra_title = "System Demo",
                             extra_information = "<h3>System Demo</h3>")
        self.event.add_child(instance=info)
        info.save_revision().publish()
        response = self.handler.serve(self.calendar,
                                      self._getRequest("/events/"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Type'), "application/xml; charset=utf-8")
        soup = BeautifulSoup(response.content, "xml")
        channel = soup.channel
        self.assertEqual(channel.title.string, "Events")
        self.assertEqual(len(channel("item")), 2)
        item = channel("item")[1]
        self.assertEqual(item.title.string, "System Demo")
        self.assertEqual(item.link.string, "http://joy.test/events/workshop/2017-02-07-extra-info/")
        self.assertEqual(item.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(self.rendName))
        self.assertEqual(item.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    Tuesday 7th of February 2017
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;&lt;h3&gt;System Demo&lt;/h3&gt;&lt;/div&gt;
&lt;div class="rich-text"&gt;&lt;/div&gt;\n</description>""")
        self.assertEqual(item.guid.get("isPermaLink"), "true")
        self.assertEqual(item.guid.string, "http://joy.test/events/workshop/2017-02-07-extra-info/")
        self.assertEqual(item.pubDate.string, "Fri, 25 Mar 2016 00:00:00 +0000")
Пример #3
0
 def testExtraInfo(self):
     page = RecurringEventPage(
         owner=self.user,
         slug="code-for-boston",
         title="Code for Boston",
         repeat=Recurrence(dtstart=dt.date(2017, 1, 1),
                           freq=WEEKLY,
                           byweekday=[TU],
                           until=dt.date(2017, 12, 26)),
         time_from=dt.time(19),
         time_to=dt.time(21, 30),
         tz=pytz.timezone("US/Eastern"),
         location="4th Floor, 1 Broadway, Cambridge, MA")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     info = ExtraInfoPage(owner=self.user,
                          slug="2017-06-06-extra-info",
                          title="Extra Information for Tuesday 6th of June",
                          overrides=page,
                          except_date=dt.date(2017, 6, 6),
                          extra_title="Handling Time Zones with Python")
     page.add_child(instance=info)
     info.save_revision().publish()
     vev = VEventFactory().makeFromPage(page)
     self.assertIs(type(vev), RecurringVEvent)
     vev.set('UID', "this-is-not-a-unique-identifier")
     codeForBoston = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Code for Boston",
         b"DTSTART;TZID=US/Eastern:20170103T190000",
         b"DTEND;TZID=US/Eastern:20170103T213000",
         b"DTSTAMP:20170515T000000Z",
         b"UID:this-is-not-a-unique-identifier", b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;UNTIL=20171227T045959Z;BYDAY=TU;WKST=SU",
         b"CREATED:20170515T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170515T000000Z",
         b"LOCATION:4th Floor\\, 1 Broadway\\, Cambridge\\, MA",
         b"URL:http://joy.test/events/code-for-boston/", b"END:VEVENT", b""
     ])
     self.assertEqual(vev.to_ical(), codeForBoston)
     self.assertEqual(len(vev.vchildren), 1)
     vchild = vev.vchildren[0]
     vchild.set('UID', "this-is-not-a-unique-identifier")
     self.assertIs(type(vchild), ExtraInfoVEvent)
     talk = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Handling Time Zones with Python",
         b"DTSTART;TZID=US/Eastern:20170606T190000",
         b"DTEND;TZID=US/Eastern:20170606T213000",
         b"DTSTAMP:20170515T000000Z",
         b"UID:this-is-not-a-unique-identifier",
         b"RECURRENCE-ID;TZID=US/Eastern:20170606T190000", b"SEQUENCE:1",
         b"CREATED:20170515T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170515T000000Z",
         b"LOCATION:4th Floor\\, 1 Broadway\\, Cambridge\\, MA",
         b"URL:http://joy.test/events/code-for-boston/2017-06-06-extra-info/",
         b"END:VEVENT", b""
     ])
     self.assertEqual(vchild.to_ical(), talk)
Пример #4
0
class TestMultiday(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="schedule",
                                     title="Schedule")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = MultidayRecurringEventPage(
            slug="test-session",
            title="Test Session",
            repeat=Recurrence(dtstart=dt.date(2018, 1, 8),
                              freq=WEEKLY,
                              byweekday=[MO],
                              until=dt.date(2018, 4, 25)),
            num_days=3,
            time_from=dt.time(10),
            time_to=dt.time(12, 30))
        self.calendar.add_child(instance=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(2018, 2, 12),
                                  extra_title="System Demo",
                                  extra_information="<h3>System Demo</h3>")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testStatusFinished(self):
        self.assertEqual(self.info.status, "finished")
        self.assertEqual(self.info.status_text, "This event has finished.")

    @freeze_timetz("2018-02-13 14:00:00")
    def testStatusStarted(self):
        self.assertEqual(self.info.status, "started")
        self.assertEqual(self.info.status_text, "This event has started.")

    def testWhen(self):
        self.assertEqual(
            self.info.when, "Monday 12th of February 2018 for 3 days "
            "starting at 10am finishing at 12:30pm")

    def testAt(self):
        self.assertEqual(self.info.at.strip(), "10am")

    @freeze_timetz("2018-02-13 17:00:00")
    def testCurrentDt(self):
        self.assertEqual(self.info._current_datetime_from,
                         datetimetz(2018, 2, 12, 10, 0))

    @freeze_timetz("2018-02-13 14:00:00")
    def testFutureDt(self):
        self.assertIsNone(self.info._future_datetime_from)

    def testPastDt(self):
        self.assertEqual(self.info._past_datetime_from,
                         datetimetz(2018, 2, 12, 10, 0))
Пример #5
0
 def setUp(self):
     site = Site.objects.get(is_default_site=True)
     site.hostname = "joy.test"
     site.save()
     self.home = getPage("/home/")
     self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
     self.requestFactory = RequestFactory()
     self.calendar = CalendarPage(owner = self.user,
                                  slug  = "events",
                                  title = "Events")
     self.home.add_child(instance=self.calendar)
     self.calendar.save_revision().publish()
     event = SimpleEventPage(owner = self.user,
                             slug   = "mini-fair",
                             title  = "Mini-Fair",
                             date   = dt.date(2018,4,7),
                             uid = "*****@*****.**")
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     event = RecurringEventPage(owner = self.user,
                                slug  = "tango-thursdays",
                                title = "Tango Thursdays",
                                details = "Weekly tango lessons at the Dance Spot",
                                repeat  = Recurrence(dtstart=dt.date(2018,3,29),
                                                     freq=WEEKLY,
                                                     byweekday=[TH]),
                                time_from = dt.time(19,30),
                                time_to   = dt.time(22,0),
                                tz        = pytz.timezone("US/Eastern"),
                                website   = "http://torontodancespot.com/",
                                location  = "622 Bloor St. W., Toronto ON, M6G 1K7",
                                uid = "*****@*****.**")
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     cancellation = CancellationPage(owner = self.user,
                                     slug  = "2019-02-14-cancellation",
                                     title = "Cancellation for Thursday 14th of April",
                                     overrides = event,
                                     except_date = dt.date(2019, 2, 14))
     event.add_child(instance=cancellation)
     cancellation.save_revision().publish()
     info = ExtraInfoPage(owner = self.user,
                          slug  = "2018-04-05-extra-info",
                          title = "Extra-Info for Thursday 5th of April",
                          overrides = event,
                          except_date = dt.date(2018, 4, 5),
                          extra_title = "Performance",
                          extra_information = "Performance for the public")
     event.add_child(instance=info)
     info.save_revision().publish()
Пример #6
0
class TestPageFormDeutsche(TestCase):
    Form = ExtraInfoPage.get_edit_handler().get_form_class()

    def setUp(self):
        translation.activate('de')
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="ereignisse",
                                     title="Ereignisse")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="meeting",
                                        title="Testen Sie Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(1988, 1, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(13),
                                        time_to=dt.time(15, 30))
        self.calendar.add_child(instance=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1999, 1, 5),
                                  extra_title="Freitag",
                                  extra_information="Besonderer Freitag")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def tearDown(self):
        translation.deactivate()

    def testExceptionAlreadyExists(self):
        page = ExtraInfoPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'except_date': "1999-01-05",
                'extra_title': "Es ist Freitag",
                'extra_information': rich_text("Besonderer spezieller Freitag")
            },
            instance=page,
            parent_page=self.event)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors, {
                'except_date':
                ['Dieses Datum enthält bereits zusätzliche information']
            })
Пример #7
0
 def setUp(self):
     site = Site.objects.get(is_default_site=True)
     site.hostname = "joy.test"
     site.save()
     self.home = getPage("/home/")
     self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
     self.requestFactory = RequestFactory()
     self.calendar = CalendarPage(owner=self.user,
                                  slug="events",
                                  title="Events")
     self.home.add_child(instance=self.calendar)
     self.calendar.save_revision().publish()
     event = RecurringEventPage(
         owner=self.user,
         slug="fierce-tango-fridays",
         title="Fierce Tango Fridays",
         details="Weekly fierce tango lessons at the Dance Spot",
         repeat=Recurrence(dtstart=dt.date(2018, 3, 30),
                           until=dt.date(2018, 8, 31),
                           freq=WEEKLY,
                           byweekday=[FR]),
         time_from=dt.time(19, 30),
         time_to=dt.time(22, 0),
         tz=pytz.timezone("US/Eastern"),
         website="http://torontodancespot.com/",
         location="622 Bloor St. W., Toronto ON, M6G 1K7",
         uid="*****@*****.**")
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     GROUPS = PageViewRestriction.GROUPS
     self.group = Group.objects.create(name="Friday Class")
     info = ExtraInfoPage(owner=self.user,
                          slug="2018-08-31-extra-info",
                          title="Extra-Info for Friday 31st of August",
                          overrides=event,
                          except_date=dt.date(2018, 8, 31),
                          extra_title="Surprise",
                          extra_information="Surprise party")
     event.add_child(instance=info)
     info.save_revision().publish()
     restriction = PageViewRestriction.objects.create(
         restriction_type=GROUPS, page=info)
     restriction.groups.set([self.group])
     restriction.save()
Пример #8
0
class TestPageForm(TestCase):
    Form = ExtraInfoPage.get_edit_handler().get_form_class()

    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="test-meeting",
                                        title="Test Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(1988, 1, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(13),
                                        time_to=dt.time(15, 30))
        self.calendar.add_child(instance=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1999, 1, 5),
                                  extra_title="Fri-day",
                                  extra_information="Special Friday")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testExceptionAlreadyExists(self):
        page = ExtraInfoPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'except_date': "1999-01-05",
                'extra_title': "It's Friday",
                'extra_information': rich_text("Special Special Friday")
            },
            instance=page,
            parent_page=self.event)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors,
            {'except_date': ['That date already has extra information']})
Пример #9
0
class Test(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="test-meeting",
                                        title="Test Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(1988, 1, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(13),
                                        time_to=dt.time(15, 30))
        self.calendar.add_child(instance=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1988, 11, 11),
                                  extra_title="System Demo",
                                  extra_information="<h3>System Demo</h3>")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testGetEventsByDay(self):
        events = RecurringEventPage.events.byDay(dt.date(1988, 11, 1),
                                                 dt.date(1988, 11, 30))
        self.assertEqual(len(events), 30)
        evod = events[10]
        self.assertEqual(evod.date, dt.date(1988, 11, 11))
        self.assertEqual(len(evod.all_events), 1)
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)
        title, page, url = evod.days_events[0]
        self.assertEqual(title, "System Demo")
        self.assertIs(type(page), ExtraInfoPage)

    def testStatus(self):
        self.assertEqual(self.info.status, "finished")
        self.assertEqual(self.info.status_text, "This event has finished.")
        now = timezone.localtime()
        myday = now.date() + dt.timedelta(days=1)
        friday = myday + dt.timedelta(days=(4 - myday.weekday()) % 7)
        futureInfo = ExtraInfoPage(owner=self.user,
                                   overrides=self.event,
                                   except_date=friday,
                                   extra_title="It's Friday",
                                   extra_information="Special")
        self.event.add_child(instance=futureInfo)
        self.assertIsNone(futureInfo.status)
        self.assertEqual(futureInfo.status_text, "")

    @freeze_timetz("1988-11-11 14:00:00")
    def testStatusStarted(self):
        self.assertEqual(self.info.status, "started")
        self.assertEqual(self.info.status_text, "This event has started.")

    def testWhen(self):
        self.assertEqual(self.info.when,
                         "Friday 11th of November 1988 at 1pm to 3:30pm")

    def testAt(self):
        self.assertEqual(self.info.at.strip(), "1pm")

    def testCurrentDt(self):
        self.assertIsNone(self.info._current_datetime_from)

    def testFutureDt(self):
        self.assertIsNone(self.info._future_datetime_from)

    def testPastDt(self):
        self.assertEqual(self.info._past_datetime_from,
                         datetimetz(1988, 11, 11, 13, 0))

    def testNeverOccursOn(self):
        info = ExtraInfoPage(owner=self.user,
                             overrides=self.event,
                             except_date=dt.date(1988, 3, 1),
                             extra_title="Tuesday",
                             extra_information="Standard")
        self.event.add_child(instance=info)
        self.assertIsNone(info._current_datetime_from)
        self.assertIsNone(info._future_datetime_from)
        self.assertIsNone(info._past_datetime_from)

    def testGroup(self):
        self.assertIsNone(self.info.group)

    def testOverridesRepeat(self):
        self.assertEqual(self.info.overrides_repeat, self.event.repeat)