def testFromSimpleCalendarPage(self): page = SimpleEventPage(owner=self.user, slug="bbq", title="BBQ", date=dt.date(2008, 7, 15), time_from=dt.time(17, 30), time_to=dt.time(19), tz=pytz.timezone("Pacific/Auckland")) self.calendar.add_child(instance=page) page.save_revision().publish() vcal = VCalendar.fromPage(self.calendar, self._getRequest("/events/")) export = vcal.to_ical() props = [ b"SUMMARY:BBQ", b"DTSTART;TZID=Pacific/Auckland:20080715T173000", b"DTEND;TZID=Pacific/Auckland:20080715T190000", b"DTSTAMP:20180512T040000Z", b"UID:", b"SEQUENCE:1", b"CREATED:20180512T040000Z", b"DESCRIPTION:", b"LAST-MODIFIED:20180512T040000Z", b"LOCATION:", b"URL:http://joy.test/events/bbq/", ] for prop in props: with self.subTest(prop=prop.split(b'\r\n', 1)[0]): self.assertIn(prop, export)
def testGroupsAuth(self): GROUPS = PageViewRestriction.GROUPS presidium = Group.objects.create(name = "Presidium") secretariat = Group.objects.create(name = "Secretariat") assembly = Group.objects.create(name = "Assembly") meeting = SimpleEventPage(owner = self.user, slug = "admin-cmte", title = "Administration Committee Meeting", date = dt.date(2015,6,20), time_from = dt.time(16,30)) self.calendar.add_child(instance=meeting) meeting.save_revision().publish() restriction = PageViewRestriction.objects.create(restriction_type = GROUPS, page = meeting) restriction.groups.set([presidium, secretariat]) restriction.save() self.assertEqual(list(SimpleEventPage.events.all()), [self.event, meeting]) request = RequestFactory().get("/test") request.user = self.user request.session = {} self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event]) request.user = User.objects.create_superuser('joe', '*****@*****.**', 's3cr3t') self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event, meeting]) request.user = User.objects.create_user('jill', '*****@*****.**', 's3cr3t') request.user.groups.set([secretariat, assembly]) self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event, meeting])
class Test(TestCase): def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.calendar = SpecificCalendarPage(owner=self.user, slug="events", title="Events") self.home.add_child(instance=self.calendar) self.calendar.save_revision().publish() self.page = SimpleEventPage(owner=self.user, slug="agfest", title="AgFest", date=dt.date(2015, 6, 5), time_from=dt.time(11), time_to=dt.time(17, 30)) self.calendar.add_child(instance=self.page) self.page.save_revision().publish() def testInit(self): event = ThisEvent(self.page, title="Mud mud mud") self.assertEqual(event.page, self.page) self.assertEqual(event.title, "Mud mud mud") self.assertEqual(event.url, "/events/agfest/") def testInit2Args(self): with self.assertRaises(TypeError): event = ThisEvent(self.page, "Mud mud mud") def testRepr(self): event = ThisEvent(self.page, url="/events/muddy/") self.assertEqual( repr(event), "ThisEvent (title='AgFest', " "page=<SimpleEventPage: AgFest>, " "url='/events/muddy/')") def testPageAttrs(self): event = ThisEvent(self.page) self.assertEqual(event.title, "AgFest") self.assertEqual(event.slug, "agfest") self.assertEqual(event.date, dt.date(2015, 6, 5)) def testTheseAttrs(self): event = ThisEvent(self.page) event.title = "Mud" event.url = "/events/muddy/" self.assertEqual(event.title, "Mud") self.assertEqual(self.page.title, "AgFest") self.assertEqual(event.url, "/events/muddy/") self.assertEqual(self.page.url, "/events/agfest/") def testNewAttrs(self): event = ThisEvent(self.page, foo="foo") event.bar = "bar" self.assertTrue(hasattr(event, "foo")) self.assertFalse(hasattr(self.page, "foo")) self.assertEqual(event.foo, "foo") self.assertTrue(hasattr(event, "bar")) self.assertFalse(hasattr(self.page, "bar")) self.assertEqual(event.bar, "bar")
def testFromPage(self): page = SimpleEventPage(owner=self.user, slug="baseball-game", title="Baseball Game", date=dt.date(2014, 7, 30), time_from=dt.time(13), time_to=dt.time(16), tz=pytz.timezone("America/Los_Angeles")) self.calendar.add_child(instance=page) page.save_revision().publish() gev = SimpleGEvent.fromPage(page) self.assertEqual(gev['dates'], "20140730T130000/20140730T160000") self.assertEqual(gev['ctz'], "America/Los_Angeles")
def testDayWithEvents(self): calendar = getPage("/home/events/") event1 = SimpleEventPage(owner=self.user, slug="memory", title="We remember", date=dt.date(2011, 6, 8), time_from=dt.time(9, 30), time_to=dt.time(10, 30)) calendar.add_child(instance=event1) event1.save_revision().publish() event2 = SimpleEventPage(owner=self.user, slug="action", title="Make things better", date=dt.date(2011, 6, 8), time_from=dt.time(11, 30), time_to=dt.time(16, 0)) calendar.add_child(instance=event2) event2.save_revision().publish() response = self.client.get("/events/2011/6/8/") select = response.soup.select self.assertEqual(response.status_code, 200) self.assertEqual(len(select(".joy-cal-list")), 1) events = select(".joy-ev-item") self.assertEqual(len(events), 2) title = events[0].select("a.joy-title__link")[0] self.assertEqual(title.string.strip(), "We remember") self.assertEqual(title['href'], "/events/memory/")
def setUp(self): GeneralCalendarPage.is_creatable = True self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t') self.request = RequestFactory().get("/test") self.request.user = self.user self.request.session = {} self.calendar = GeneralCalendarPage(owner=self.user, slug="calendar", title="My Calendar") home = getPage("/home/") home.add_child(instance=self.calendar) self.calendar.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="bbq", title="BBQ", uid="a94c3211-08e5-4e36-9448-86a869a47d89", date=dt.date(2011, 8, 20), time_from=dt.time(18, 30)) self.calendar.add_child(instance=event) event.save_revision().publish() self.group = GroupPage(slug="initech", title="Initech Corporation") home.add_child(instance=self.group) self.group.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="planning-meeting", title="Planning to Plan", uid="a96484da-e350-45c7-af03-97ca2bb173d6", date=dt.date(2011, 8, 20), time_from=dt.time(8, 0)) self.group.add_child(instance=event) event.save_revision().publish()
def setUp(self): SpecificCalendarPage.is_creatable = True self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t') self.request = RequestFactory().get("/test") self.request.user = self.user self.request.session = {} self.calendar1 = SpecificCalendarPage(owner=self.user, slug="calendar1", title="Red Team Calendar") home = getPage("/home/") home.add_child(instance=self.calendar1) self.calendar1.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="football", title="Football Game", uid="570ed9c4-4503-4b45-b15e-c99faed9c531", date=dt.date(2011, 6, 5), time_from=dt.time(9, 30), time_to=dt.time(11, 0)) self.calendar1.add_child(instance=event) event.save_revision().publish() self.calendar2 = SpecificCalendarPage(owner=self.user, slug="calendar2", title="Green Team Calendar") home.add_child(instance=self.calendar2) self.calendar2.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="tree-planting", title="Tree Planting", uid="eb50e787-12bf-477b-8493-c4414ac001ca", date=dt.date(2011, 6, 5), time_from=dt.time(9, 30)) self.calendar2.add_child(instance=event) event.save_revision().publish()
def testFromPage(self): page = SimpleEventPage(owner=self.user, slug="pet-show", title="Pet Show", date=dt.date(1987, 6, 5), time_from=dt.time(11), time_to=dt.time(17, 30), tz=pytz.timezone("Australia/Sydney")) self.calendar.add_child(instance=page) page.save_revision().publish() vev = SimpleVEvent.fromPage(page) tz = pytz.timezone("Australia/Sydney") self.assertEqual(vev['dtstart'].dt, tz.localize(dt.datetime(1987, 6, 5, 11, 0)))
def setUp(self): translation.activate('fr') self.user = User.objects.create_superuser('i', '*****@*****.**', 's3(r3t') calendar = CalendarPage(owner=self.user, slug="calendrier", title="Calendrier") Page.objects.get(slug='home').add_child(instance=calendar) calendar.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="plantation-d-arbres", title="Plantation d'arbres", date=dt.date(2011, 6, 5), time_from=dt.time(9, 30), time_to=dt.time(11, 0)) calendar.add_child(instance=event) event.save_revision().publish()
def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.calendar = SpecificCalendarPage(owner = self.user, slug = "events", title = "Events") self.home.add_child(instance=self.calendar) self.calendar.save_revision().publish() self.event = SimpleEventPage(owner = self.user, slug = "agfest", title = "AgFest", date = dt.date(2015,6,5), time_from = dt.time(11), time_to = dt.time(17,30)) self.calendar.add_child(instance=self.event) self.event.save_revision().publish()
def testSetImage(self): page = SimpleEventPage(owner = self.user, slug = "meetup", title = "Meet Up", image = self.img, date = dt.date(2016,10,21), time_from = dt.time(16)) self.calendar.add_child(instance=page) page.save_revision().publish() request = self._getRequest() thisEvent = ThisEvent(page.title, page, page.get_url(request)) entry = EventEntry.fromEvent(thisEvent, request) self.assertEqual(entry.enclosure(), { 'length': '773', 'url': 'http://joy.test/media/images/{}'.format(self.rendName), 'type': 'image/png'})
def setUp(self): self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t') calendar = CalendarPage(owner=self.user, slug="events", title="Events", default_view="L") Page.objects.get(slug='home').add_child(instance=calendar) calendar.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="tree-planting", title="Tree Planting", date=dt.date(2011, 6, 5), time_from=dt.time(9, 30), time_to=dt.time(11, 0)) calendar.add_child(instance=event) event.save_revision().publish()
def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.calendar = SpecificCalendarPage(owner = self.user, slug = "events", title = "Events") self.home.add_child(instance=self.calendar) self.calendar.save_revision().publish() self.event = SimpleEventPage(owner = self.user, slug = "pet-show", title = "Pet Show", date = dt.date(1987,6,5), time_from = dt.time(11), time_to = dt.time(17,30), tz = pytz.timezone("Australia/Sydney")) self.calendar.add_child(instance=self.event) self.event.save_revision().publish()
def _setUpNovaSubsite(self): main = getPage("/home/") home = Page(slug="nova", title="Nova Homepage") main.add_child(instance=home) home.save_revision().publish() activities = Page(slug="activities", title="Nova Activities") home.add_child(instance=activities) activities.save_revision().publish() Site.objects.create(hostname='nova.joy.test', root_page_id=home.id, is_default_site=False) events = CalendarPage(owner=self.user, slug="nova-events", title="Nova Events") home.add_child(instance=events) events.save_revision().publish() committee = RecurringEventPage(owner=self.user, slug="executive-meeting", title="Executive Committee Meeting", repeat=Recurrence(dtstart=dt.date( 1984, 8, 5), freq=WEEKLY, byweekday=[TH]), time_from=dt.time(13), time_to=dt.time(15)) events.add_child(instance=committee) committee.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="rubbish-blitz", title="Rubbish Blitz", date=dt.date(1984, 9, 13), time_from=dt.time(12, 30), time_to=dt.time(17)) events.add_child(instance=event) event.save_revision().publish() cancellation = CancellationPage( owner=self.user, slug="1984-09-13-cancellation", title="Cancellation for Thursday 13th of September", overrides=committee, except_date=dt.date(1984, 9, 13), cancellation_title="Meeting Cancelled", cancellation_details="The committee will be at " "the working bee") committee.add_child(instance=cancellation) cancellation.save_revision().publish()
def testServeSimple(self): page = SimpleEventPage(owner=self.user, slug="baseball-game", title="Baseball Game", date=dt.date(2014, 7, 30), time_from=dt.time(13), time_to=dt.time(16), tz=pytz.timezone("America/Los_Angeles")) self.calendar.add_child(instance=page) page.save_revision().publish() response = self.handler.serve( page, self._getRequest("/events/baseball-game/" "?format=google")) self.assertEqual(response.status_code, 302) self.assertEqual( response.url, "http://www.google.com/calendar/event?action=TEMPLATE&" "text=Baseball+Game&dates=20140730T130000%2F20140730T160000&" "ctz=America%2FLos_Angeles")
class TestExport(TestCase): def setUp(self): Site.objects.update(hostname="joy.test") self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3(R3t') 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() self.dicerun = SimpleEventPage(owner=self.user, slug="mercy-dice-run", title="Mercy Dice Run", date=dt.date(2020, 3, 16), location="Newtown") self.calendar.add_child(instance=self.dicerun) self.dicerun.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="workshop", title="Workshop", date=dt.date(2020, 3, 22)) self.calendar.add_child(instance=event) event.save_revision().publish() self.handler = RssHandler() def _getRequest(self, path="/"): request = self.requestFactory.get(path) request.user = self.user request.site = self.home.get_site() request.session = {} request._messages = FallbackStorage(request) request.POST = request.POST.copy() request.POST['action-publish'] = "action-publish" return request def testServeCalendar(self): 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")
def testFromSimpleEventPage(self): page = SimpleEventPage(owner = self.user, slug = "pet-show", title = "Pet Show", date = dt.date(1987,6,5), time_from = dt.time(11), time_to = dt.time(17,30), tz = pytz.timezone("Australia/Sydney")) self.calendar.add_child(instance=page) page.save_revision().publish() vcal = VCalendar.fromPage(page, self._getRequest("/events/pet-show/")) export = vcal.to_ical() aest = b"\r\n".join([ b"BEGIN:STANDARD", b"DTSTART;VALUE=DATE-TIME:19870315T020000", b"TZNAME:AEST", b"TZOFFSETFROM:+1100", b"TZOFFSETTO:+1000", b"END:STANDARD", ]) aedt = b"\r\n".join([ b"BEGIN:DAYLIGHT", b"DTSTART;VALUE=DATE-TIME:19871025T030000", b"TZNAME:AEDT", b"TZOFFSETFROM:+1000", b"TZOFFSETTO:+1100", b"END:DAYLIGHT", ]) props = [b"SUMMARY:Pet Show", b"DTSTART;TZID=Australia/Sydney:19870605T110000", b"DTEND;TZID=Australia/Sydney:19870605T173000", b"DTSTAMP:20180512T040000Z", b"UID:", b"SEQUENCE:1", b"CREATED:20180512T040000Z", b"DESCRIPTION:", b"LAST-MODIFIED:20180512T040000Z", b"LOCATION:", b"URL:http://joy.test/events/pet-show/", aest, aedt] for prop in props: with self.subTest(prop=prop.split(b'\r\n',1)[0]): self.assertIn(prop, export)
def testGroup(self): self.assertIsNone(self.event.group) group = GroupPage(slug = "runners", title = "Runners") self.home.add_child(instance=group) race = SimpleEventPage(owner = self.user, slug = "race", title = "Race", date = dt.date(2008, 6, 3)) group.add_child(instance=race) self.assertEqual(race.group, group)
def testPastDt(self): self.assertEqual(self.event._past_datetime_from, datetimetz(1987,6,5,11,0)) now = timezone.localtime() earlier = now - dt.timedelta(hours=1) if earlier.date() != now.date(): earlier = datetimetz(now.date(), dt.time.min) nowEvent = SimpleEventPage(owner = self.user, slug = "now", title = "Now Event", date = now.date(), time_from = earlier.time(), time_to = dt.time.max) self.calendar.add_child(instance=nowEvent) self.assertEqual(nowEvent._past_datetime_from, earlier) tomorrow = timezone.localdate() + dt.timedelta(days=1) futureEvent = SimpleEventPage(owner = self.user, slug = "tomorrow", title = "Tomorrow's Event", date = tomorrow) self.calendar.add_child(instance=futureEvent) self.assertIsNone(futureEvent._past_datetime_from)
def test_girotondo_month(self): child2 = Child.objects.create(first_name='ab', last_name='bc', father=self.user, care_group='P') Absence.objects.create(child_link=self.child, from_date=date(2019, 12, 17), created_by=self.user) Absence.objects.create(child_link=self.child, from_date=date(2019, 12, 18), created_by=self.user) self.home = self.home = Page.objects.get(slug='home') self.calendar = CalendarPage(owner=self.user, slug="events", title="Events") self.home.add_child(instance=self.calendar) self.calendar.save_revision().publish() self.event = SimpleEventPage(owner=self.user, slug="pet-show", title="Pet Show", category=self.closed, date=date(2019, 12, 23)) self.calendar.add_child(instance=self.event) self.event.save_revision().publish() giro_month = GirotondoMonth(2019, 12) giro_month.holidays.add(date(2019, 12, 24), 'Xmas') self.assertFalse(giro_month.is_girotondo_day(23)) self.assertFalse(giro_month.is_girotondo_day(24)) self.assertFalse(giro_month.is_girotondo_day(22)) self.assertFalse(giro_month.is_girotondo_day(21)) self.assertTrue(giro_month.is_girotondo_day(20)) self.assertEqual(giro_month.get_children_out(17, 'P'), [self.child.first_name + ' ' + self.child.last_name]) self.assertEqual(giro_month.get_children_in(17, 'P'), [child2.first_name + ' ' + child2.last_name]) self.assertEqual(giro_month.get_children_out(12, 'P'), [])
def testLoginAuth(self): LOGIN = PageViewRestriction.LOGIN bee = SimpleEventPage(owner = self.user, slug = "bee", title = "Working Bee", date = dt.date(2013,3,30), time_from = dt.time(10)) self.calendar.add_child(instance=bee) bee.save_revision().publish() PageViewRestriction.objects.create(restriction_type = LOGIN, page = bee) self.assertEqual(list(SimpleEventPage.events.all()), [self.event, bee]) self.assertFalse(bee.isAuthorized(None)) request = RequestFactory().get("/test") request.user = AnonymousUser() request.session = {} self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event]) request.user = self.user self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event, bee])
def testPasswordAuth(self): PASSWORD = PageViewRestriction.PASSWORD KEY = PageViewRestriction.passed_view_restrictions_session_key meeting = SimpleEventPage(owner = self.user, slug = "club-meet", title = "Club Meeting", date = dt.date(2009,10,21)) self.calendar.add_child(instance=meeting) meeting.save_revision().publish() restriction = PageViewRestriction.objects.create(restriction_type = PASSWORD, password = "******", page = meeting) self.assertEqual(list(SimpleEventPage.events.all()), [self.event, meeting]) request = RequestFactory().get("/test") request.user = self.user request.session = {} self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event]) request.session[KEY] = [restriction.id] self.assertEqual(list(SimpleEventPage.events.auth(request)), [self.event, meeting])
def testGetEventsAcrossDateline(self): showDay = SimpleEventPage(owner = self.user, slug = "tamakautoga-village-show-day", title = "Tamakautoga Village Show Day", date = dt.date(2016,7,30), tz = pytz.timezone("Pacific/Niue")) self.calendar.add_child(instance=showDay) evods = SimpleEventPage.events.byDay(dt.date(2016,7,31), dt.date(2016,7,31)) self.assertEqual(len(evods[0].days_events), 1) self.assertEqual(len(evods[0].continuing_events), 0) event = evods[0].days_events[0].page self.assertEqual(event.at, "") self.assertEqual(event.when, "Sunday 31st of July 2016")
def testStatus(self): self.assertEqual(self.event.status, "finished") self.assertEqual(self.event.status_text, "This event has finished.") now = timezone.localtime() earlier = now - dt.timedelta(hours=1) if earlier.date() != now.date(): earlier = datetimetz(now.date(), dt.time.min) nowEvent = SimpleEventPage(owner = self.user, slug = "now", title = "Now Event", date = now.date(), time_from = earlier.time(), time_to = dt.time.max) self.assertEqual(nowEvent.status, "started") self.assertEqual(nowEvent.status_text, "This event has started.") tomorrow = timezone.localdate() + dt.timedelta(days=1) futureEvent = SimpleEventPage(owner = self.user, slug = "tomorrow", title = "Tomorrow's Event", date = tomorrow) self.calendar.add_child(instance=futureEvent) self.assertIsNone(futureEvent.status) self.assertEqual(futureEvent.status_text, "")
def setUp(self): Site.objects.update(hostname="joy.test") self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3(R3t') 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() self.dicerun = SimpleEventPage(owner=self.user, slug="mercy-dice-run", title="Mercy Dice Run", date=dt.date(2020, 3, 16), location="Newtown") self.calendar.add_child(instance=self.dicerun) self.dicerun.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="workshop", title="Workshop", date=dt.date(2020, 3, 22)) self.calendar.add_child(instance=event) event.save_revision().publish() self.handler = ICalHandler()
class TestExport(TestCase): def setUp(self): Site.objects.update(hostname="joy.test") self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3(R3t') 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() self.dicerun = SimpleEventPage(owner=self.user, slug="mercy-dice-run", title="Mercy Dice Run", date=dt.date(2020, 3, 16), location="Newtown") self.calendar.add_child(instance=self.dicerun) self.dicerun.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="workshop", title="Workshop", date=dt.date(2020, 3, 22)) self.calendar.add_child(instance=event) event.save_revision().publish() self.handler = ICalHandler() def _getRequest(self, path="/"): request = self.requestFactory.get(path) request.user = self.user request.site = self.home.get_site() request.session = {} request._messages = FallbackStorage(request) request.POST = request.POST.copy() request.POST['action-publish'] = "action-publish" return request def testServeCalendar(self): response = self.handler.serve(self.calendar, self._getRequest("/events/")) self.assertEqual(response.status_code, 200) self.assertEqual(response.get('Content-Type'), "text/calendar") self.assertEqual(response.get('Content-Disposition'), "attachment; filename=events.ics") self.assertEqual(response.content.count(b"BEGIN:VEVENT"), 2) def testServeEvent(self): response = self.handler.serve( self.dicerun, self._getRequest("/events/mercy-dice-run/")) self.assertEqual(response.status_code, 200) self.assertEqual(response.get('Content-Type'), "text/calendar") self.assertEqual(response.get('Content-Disposition'), "attachment; filename=mercy-dice-run.ics") self.assertEqual(response.content.count(b"BEGIN:VEVENT"), 1) self.assertIn(b"SUMMARY:Mercy Dice Run", response.content) self.assertIn(b"DTSTART;TZID=Asia/Tokyo:20200316T000000", response.content) self.assertIn(b"DTEND;TZID=Asia/Tokyo:20200316T235959", response.content) self.assertIn(b"LOCATION:Newtown", response.content) self.assertIn(b"URL:http://joy.test/events/mercy-dice-run", response.content) def testServePage(self): response = self.handler.serve(self.home, self._getRequest("/")) self.assertIsNone(response)
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() GROUPS = PageViewRestriction.GROUPS self.friends = Group.objects.create(name="Friends") self.rendezvous = SimpleEventPage( owner=self.user, slug="rendezvous", title="Private Rendezvous", date=dt.date(2013, 1, 10), uid="80af64e7-84e6-40d9-8b4f-7edf92aab9f7") self.calendar.add_child(instance=self.rendezvous) self.rendezvous.save_revision().publish() restriction = PageViewRestriction.objects.create( restriction_type=GROUPS, page=self.rendezvous) restriction.groups.set([self.friends]) restriction.save()
def _setUpMainSite(self): Site.objects.filter(is_default_site=True).update(hostname="joy.test") home = getPage("/home/") events = CalendarPage(owner=self.user, slug="events", title="Events") home.add_child(instance=events) events.save_revision().publish() chess = GroupPage(slug="chess-club", title="Chess Club") home.add_child(instance=chess) chess.save_revision().publish() event = RecurringEventPage(owner=self.user, slug="lunchtime-matches", title="Lunchtime Chess Matches", repeat=Recurrence(dtstart=dt.date( 1984, 8, 5), freq=WEEKLY, byweekday=[MO, WE, FR]), time_from=dt.time(12), time_to=dt.time(13)) chess.add_child(instance=event) event.save_revision().publish() cancellation = CancellationPage( owner=self.user, slug="1984-10-01-cancellation", title="Cancellation for Monday 1st of October", overrides=event, except_date=dt.date(1984, 10, 1), cancellation_title="No Chess Club Today") event.add_child(instance=cancellation) cancellation.save_revision().publish() postponement = PostponementPage( owner=self.user, slug="1984-10-03-postponement", title="Postponement for Wednesday 3rd of October", overrides=event, except_date=dt.date(1984, 10, 3), cancellation_title="", postponement_title="Early Morning Matches", date=dt.date(1984, 10, 4), time_from=dt.time(7, 30), time_to=dt.time(8, 30)) event.add_child(instance=postponement) postponement.save_revision().publish() event = RecurringEventPage(owner=self.user, slug="flea-market", title="Flea Market", repeat=Recurrence(dtstart=dt.date( 1984, 7, 1), freq=YEARLY, byweekday=[SA(1), SA(3)], bymonth=range(2, 12)), time_from=dt.time(8), time_to=dt.time(13)) events.add_child(instance=event) event.save_revision().publish() event = RecurringEventPage(owner=self.user, slug="drama-practice", title="Drama Group", repeat=Recurrence(dtstart=dt.date( 1984, 8, 14), freq=WEEKLY, byweekday=[TH], interval=2), time_from=dt.time(17)) events.add_child(instance=event) event.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="public-lecture3", title="The Human Environment", date=dt.date(1984, 9, 14), time_from=dt.time(19), location="Lecture Hall C") events.add_child(instance=event) event.save_revision().publish()
class Test(TestCase): def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.request = RequestFactory().get("/test") self.request.user = self.user self.request.session = {} self.calendar = GeneralCalendarPage(owner = self.user, slug = "events", title = "Events") self.home.add_child(instance=self.calendar) self.group = GroupPage(slug = "initech", title = "Initech Corporation") self.home.add_child(instance=self.group) self.show = SimpleEventPage(owner = self.user, slug = "pet-show", title = "Pet Show", date = dt.date(2013,1,5), time_from = dt.time(11), time_to = dt.time(17,30), uid = "29daefed-fed1-4e47-9408-43ec9b06a06d") self.calendar.add_child(instance=self.show) GROUPS = PageViewRestriction.GROUPS self.friends = Group.objects.create(name = "Friends") self.rendezvous = SimpleEventPage(owner = self.user, slug = "rendezvous", title = "Private Rendezvous", date = dt.date(2013,1,10), uid = "80af64e7-84e6-40d9-8b4f-7edf92aab9f7") self.calendar.add_child(instance=self.rendezvous) self.rendezvous.save_revision().publish() restriction = PageViewRestriction.objects.create(restriction_type = GROUPS, page = self.rendezvous) restriction.groups.set([self.friends]) restriction.save() self.party = MultidayEventPage(owner = self.user, slug = "allnighter", title = "All Night", date_from = dt.date(2012,12,31), date_to = dt.date(2013,1,1), time_from = dt.time(23), time_to = dt.time(3), uid = "initiative+technology") self.calendar.add_child(instance=self.party) self.standup = RecurringEventPage(slug = "test-meeting", title = "Test Meeting", repeat = Recurrence(dtstart=dt.date(2013,1,1), until=dt.date(2013,5,31), freq=WEEKLY, byweekday=[MO,WE,FR]), time_from = dt.time(13,30), time_to = dt.time(16), uid = "initiative+technology") self.group.add_child(instance=self.standup) self.postponement = PostponementPage(owner = self.user, slug = "2013-01-09-postponement", title = "Postponement for Wednesday 16th of October", overrides = self.standup, except_date = dt.date(2013,1,16), cancellation_title = "Meeting Postponed", cancellation_details = "The meeting has been postponed until tomorrow", postponement_title = "A Meeting", date = dt.date(2013,1,17), time_from = dt.time(13), time_to = dt.time(16,30), details = "Yes a test meeting on a Thursday") self.standup.add_child(instance=self.postponement) cancelTuesday = CancellationPage(owner = self.user, slug = "2013-01-01-cancellation", title = "CancellationPage for Tuesday 1st of January", overrides = self.standup, except_date = dt.date(2013,1,1), cancellation_title = "Meeting Cancelled") self.standup.add_child(instance=cancelTuesday) def testGetAllEventsByDay(self): events = getAllEventsByDay(self.request, dt.date(2013,1,1), dt.date(2013,1,31), holidays=self.calendar.holidays) self.assertEqual(len(events), 31) evod1 = events[0] self.assertEqual(evod1.date, dt.date(2013,1,1)) self.assertEqual(len(evod1.all_events), 1) self.assertEqual(len(evod1.days_events), 0) self.assertEqual(len(evod1.continuing_events), 1) evod10 = events[9] self.assertEqual(evod10.date, dt.date(2013,1,10)) self.assertEqual(len(evod10.all_events), 0) def testAuthGetAllEventsByDay(self): self.request.user.groups.set([self.friends]) events = getAllEventsByDay(self.request, dt.date(2013,1,1), dt.date(2013,1,31)) self.assertEqual(len(events), 31) evod10 = events[9] self.assertEqual(evod10.date, dt.date(2013,1,10)) self.assertEqual(len(evod10.all_events), 1) self.assertEqual(len(evod10.days_events), 1) event = evod10.days_events[0] self.assertEqual(event.title, "Private Rendezvous") def testGetAllEventsByWeek(self): weeks = getAllEventsByWeek(self.request, 2013, 1) self.assertEqual(len(weeks), 5) self.assertIsNone(weeks[0][0]) self.assertIsNone(weeks[0][1]) self.assertIsNone(weeks[4][5]) self.assertIsNone(weeks[4][6]) evod = weeks[2][4] self.assertEqual(evod.date, dt.date(2013,1,17)) self.assertEqual(len(evod.days_events), 1) self.assertEqual(len(evod.continuing_events), 0) def testGetAllUpcomingEvents(self): today = timezone.localdate() futureEvent = MultidayEventPage(owner = self.user, slug = "tomorrow", title = "Tomorrow's Event", date_from = today + dt.timedelta(days=1), date_to = today + dt.timedelta(days=3), time_from = dt.time(17), time_to = dt.time(10,30)) self.calendar.add_child(instance=futureEvent) events = getAllUpcomingEvents(self.request, home=self.home, holidays=self.calendar.holidays) self.assertEqual(len(events), 1) title, event, url = events[0] self.assertEqual(title, "Tomorrow's Event") self.assertEqual(event.slug, "tomorrow") events0 = getAllUpcomingEvents(self.request) self.assertEqual(len(events0), 1) @override_settings(JOYOUS_UPCOMING_INCLUDES_STARTED = True) def testGetAllCurrentEvents(self): today = timezone.localdate() futureEvent = MultidayEventPage(owner = self.user, slug = "yesterday", title = "Yesterday's Event", date_from = today - dt.timedelta(days=1), date_to = today + dt.timedelta(days=3), time_from = dt.time(17), time_to = dt.time(10,30)) self.calendar.add_child(instance=futureEvent) events = getAllUpcomingEvents(self.request, home=self.home) self.assertEqual(len(events), 1) title, event, url = events[0] self.assertEqual(title, "Yesterday's Event") self.assertEqual(event.slug, "yesterday") events0 = getAllUpcomingEvents(self.request) self.assertEqual(len(events0), 1) def testGetAllPastEvents(self): events = getAllPastEvents(self.request) self.assertEqual(len(events), 5) self.assertEqual(events[0].title, "Test Meeting") self.assertEqual(events[1].title, "A Meeting") self.assertEqual(events[2].title, "Meeting Postponed") self.assertEqual(events[3].title, "Pet Show") self.assertEqual(events[4].title, "All Night") def testGetGroupUpcomingEvents(self): meeting = RecurringEventPage(owner = self.user, slug = "plan-plan", title = "Planning to Plan", repeat = Recurrence(dtstart=dt.date(2018,5,1), freq=WEEKLY, byweekday=[TU]), time_from = dt.time(18,30), time_to = dt.time(20), group_page = self.group) self.calendar.add_child(instance=meeting) memo = ExtraInfoPage(owner = self.user, slug = "plan-plan-extra-info", title = "Extra Information Planning to Plan", overrides = meeting, except_date = meeting.next_date, extra_title = "Gap Analysis", extra_information = "Analyse your gaps") meeting.add_child(instance=memo) events = getGroupUpcomingEvents(self.request, self.group) self.assertEqual(len(events), 2) self.assertEqual(events[0].title, "Gap Analysis") self.assertEqual(events[1].title, "Planning to Plan") def testGetGroupUpcomingEventsDupGroup(self): meeting = RecurringEventPage(owner = self.user, slug = "plan-plan", title = "Planning to Plan", repeat = Recurrence(dtstart=dt.date(2018,5,2), freq=WEEKLY, byweekday=[WE]), time_from = dt.time(18,30), time_to = dt.time(20), group_page = self.group) self.group.add_child(instance=meeting) events = getGroupUpcomingEvents(self.request, self.group) self.assertEqual(len(events), 1) self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[0].page.group, self.group) def testGetGroupUpcomingEvents2Groups(self): rival = GroupPage(slug = "initrode", title = "Initrode Corporation") self.home.add_child(instance=rival) meeting = RecurringEventPage(owner = self.user, slug = "plan-plan", title = "Planning to Plan", repeat = Recurrence(dtstart=dt.date(2018,5,2), freq=WEEKLY, byweekday=[WE]), time_from = dt.time(18,30), time_to = dt.time(20), group_page = rival) self.group.add_child(instance=meeting) events = getGroupUpcomingEvents(self.request, rival) self.assertEqual(len(events), 1) self.assertEqual(events[0].title, "Planning to Plan") # being a child of self.group trumps having group_page set self.assertEqual(events[0].page.group, self.group) events = getGroupUpcomingEvents(self.request, self.group) self.assertEqual(len(events), 1) self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[0].page.group, self.group) def testGetEventFromUid(self): event = getEventFromUid(self.request, "29daefed-fed1-4e47-9408-43ec9b06a06d") self.assertEqual(event.title, "Pet Show") def testMultiGetEventFromUid(self): with self.assertRaises(MultipleObjectsReturned): getEventFromUid(self.request, "initiative+technology") def testMissingGetEventFromUid(self): with self.assertRaises(ObjectDoesNotExist): getEventFromUid(self.request, "d12971fb-e694-4a04-aba2-fb1a4a7166b9") def testAuthGetEventFromUid(self): with self.assertRaises(PermissionDenied): event = getEventFromUid(self.request, "80af64e7-84e6-40d9-8b4f-7edf92aab9f7") self.request.user.groups.set([self.friends]) event = getEventFromUid(self.request, "80af64e7-84e6-40d9-8b4f-7edf92aab9f7") self.assertIsNotNone(event.title) self.assertEqual(event.title, "Private Rendezvous")
def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.request = RequestFactory().get("/test") self.request.user = self.user self.request.session = {} self.calendar = GeneralCalendarPage(owner = self.user, slug = "events", title = "Events") self.home.add_child(instance=self.calendar) self.group = GroupPage(slug = "initech", title = "Initech Corporation") self.home.add_child(instance=self.group) self.show = SimpleEventPage(owner = self.user, slug = "pet-show", title = "Pet Show", date = dt.date(2013,1,5), time_from = dt.time(11), time_to = dt.time(17,30), uid = "29daefed-fed1-4e47-9408-43ec9b06a06d") self.calendar.add_child(instance=self.show) GROUPS = PageViewRestriction.GROUPS self.friends = Group.objects.create(name = "Friends") self.rendezvous = SimpleEventPage(owner = self.user, slug = "rendezvous", title = "Private Rendezvous", date = dt.date(2013,1,10), uid = "80af64e7-84e6-40d9-8b4f-7edf92aab9f7") self.calendar.add_child(instance=self.rendezvous) self.rendezvous.save_revision().publish() restriction = PageViewRestriction.objects.create(restriction_type = GROUPS, page = self.rendezvous) restriction.groups.set([self.friends]) restriction.save() self.party = MultidayEventPage(owner = self.user, slug = "allnighter", title = "All Night", date_from = dt.date(2012,12,31), date_to = dt.date(2013,1,1), time_from = dt.time(23), time_to = dt.time(3), uid = "initiative+technology") self.calendar.add_child(instance=self.party) self.standup = RecurringEventPage(slug = "test-meeting", title = "Test Meeting", repeat = Recurrence(dtstart=dt.date(2013,1,1), until=dt.date(2013,5,31), freq=WEEKLY, byweekday=[MO,WE,FR]), time_from = dt.time(13,30), time_to = dt.time(16), uid = "initiative+technology") self.group.add_child(instance=self.standup) self.postponement = PostponementPage(owner = self.user, slug = "2013-01-09-postponement", title = "Postponement for Wednesday 16th of October", overrides = self.standup, except_date = dt.date(2013,1,16), cancellation_title = "Meeting Postponed", cancellation_details = "The meeting has been postponed until tomorrow", postponement_title = "A Meeting", date = dt.date(2013,1,17), time_from = dt.time(13), time_to = dt.time(16,30), details = "Yes a test meeting on a Thursday") self.standup.add_child(instance=self.postponement) cancelTuesday = CancellationPage(owner = self.user, slug = "2013-01-01-cancellation", title = "CancellationPage for Tuesday 1st of January", overrides = self.standup, except_date = dt.date(2013,1,1), cancellation_title = "Meeting Cancelled") self.standup.add_child(instance=cancelTuesday)