Example #1
0
func (s *EventSuite) TestFullEventMarshal(c *C) {
	now := time.Now().UTC()
	end := now.Add(time.Hour)
	oneDay := time.Hour * 24
	oneWeek := oneDay * 7
	event := NewEventWithEnd("1:2:3", now, end)
	uri, _ := url.Parse("http://taviti.com/some/attachment.ics")
	event.Attachment = values.NewUrl(*uri)
	event.Attendees = []*values.AttendeeContact{
		values.NewAttendeeContact("Jon Azoff", "*****@*****.**"),
		values.NewAttendeeContact("Matthew Davie", "*****@*****.**"),
	}
	event.Categories = values.NewCSV("vinyasa", "level 1")
	event.Comments = values.NewComments("Great class, 5 stars!", "I love this class!")
	event.ContactInfo = values.NewCSV("Send us an email!", "<*****@*****.**>")
	event.Created = event.DateStart
	event.Description = "An all-levels class combining strength and flexibility with breath"
	ex1 := values.NewDateTime(now.Add(oneWeek))
	ex2 := values.NewDateTime(now.Add(oneWeek * 2))
	event.ExceptionDateTimes = values.NewExceptionDateTimes(ex1, ex2)
	event.Geo = values.NewGeo(37.747643, -122.445400)
	event.LastModified = event.DateStart
	event.Location = values.NewLocation("Dolores Park")
	event.Organizer = values.NewOrganizerContact("Jon Azoff", "*****@*****.**")
	event.Priority = 1
	event.RecurrenceId = event.DateStart
	r1 := values.NewDateTime(now.Add(oneWeek + oneDay))
	r2 := values.NewDateTime(now.Add(oneWeek*2 + oneDay))
	event.RecurrenceDateTimes = values.NewRecurrenceDateTimes(r1, r2)
	event.AddRecurrenceRules(values.NewRecurrenceRule(values.WeekRecurrenceFrequency))
	uri, _ = url.Parse("*****@*****.**")
	event.RelatedTo = values.NewUrl(*uri)
	event.Resources = values.NewCSV("yoga mat", "towel")
	event.Sequence = 1
	event.Status = values.TentativeEventStatus
	event.Summary = "Jon's Super-Sweaty Vinyasa 1"
	event.TimeTransparency = values.OpaqueTimeTransparency
	uri, _ = url.Parse("http://student.taviti.com/san-francisco/jonathan-azoff/vinyasa-1")
	event.Url = values.NewUrl(*uri)
	enc, err := icalendar.Marshal(event)
	if err != nil {
		c.Fatal(err.Error())
	}
	tmpl := "BEGIN:VEVENT\r\nUID:1:2:3\r\nDTSTAMP:%sZ\r\nDTSTART:%sZ\r\nDTEND:%sZ\r\nCREATED:%sZ\r\n" +
		"DESCRIPTION:An all-levels class combining strength and flexibility with breath\r\n" +
		"GEO:37.747643 -122.445400\r\nLAST-MODIFIED:%sZ\r\nLOCATION:Dolores Park\r\n" +
		"ORGANIZER;CN=\"Jon Azoff\":MAILTO:[email protected]\r\nPRIORITY:1\r\nSEQUENCE:1\r\nSTATUS:TENTATIVE\r\n" +
		"SUMMARY:Jon's Super-Sweaty Vinyasa 1\r\nTRANSP:OPAQUE\r\n" +
		"URL;VALUE=URI:http://student.taviti.com/san-francisco/jonathan-azoff/vinyasa-1\r\n" +
		"RECURRENCE-ID:%sZ\r\nRRULE:FREQ=WEEKLY\r\nATTACH;VALUE=URI:http://taviti.com/some/attachment.ics\r\n" +
		"ATTENDEE;CN=\"Jon Azoff\":MAILTO:[email protected]\r\nATTENDEE;CN=\"Matthew Davie\":MAILTO:[email protected]\r\n" +
		"CATEGORIES:vinyasa,level 1\r\nCOMMENT:Great class, 5 stars!\r\nCOMMENT:I love this class!\r\n" +
		"CONTACT:Send us an email!,<*****@*****.**>\r\nEXDATE:%s,%s\r\nRDATE:%s,%s\r\n" +
		"RELATED-TO;VALUE=URI:[email protected]\r\nRESOURCES:yoga mat,towel\r\nEND:VEVENT"
	sdate := now.Format(values.DateTimeFormatString)
	edate := end.Format(values.DateTimeFormatString)
	c.Assert(enc, Equals, fmt.Sprintf(tmpl, sdate, sdate, edate, sdate, sdate, sdate, ex1, ex2, r1, r2))
}
Example #2
0
func (s *ClientSuite) TestRecurringEventQuery(c *C) {

	// create the master event object
	start := time.Now().Truncate(time.Hour).UTC()
	uid := fmt.Sprintf("test-recurring-event-%d", start.Unix())
	putEvent := components.NewEventWithDuration(uid, start, time.Hour)
	putEvent.Summary = "This is a test recurring event"
	rule := values.NewRecurrenceRule(values.DayRecurrenceFrequency)
	rule.Count = 14 // two weeks of events
	putEvent.AddRecurrenceRules(rule)

	// create an instance override at one week out
	nextWeek := start.AddDate(0, 0, 7)
	// start it an hour later, make it go for twice as long
	overrideEvent := components.NewEventWithDuration(uid, nextWeek.Add(time.Hour), 2*time.Hour)
	// mark it as an override of the recurrence at one week out
	overrideEvent.RecurrenceId = values.NewDateTime(nextWeek)
	overrideEvent.Summary = "This is a test override event"

	// generate an ICS filepath
	path := fmt.Sprintf("/%s.ics", uid)

	// save the events to the server
	if err := s.client.PutEvents(path, putEvent, overrideEvent); err != nil {
		c.Fatal(err.Error())
	}

	// create a query for all events between one week out + days in range
	daysInRange := 2
	nextWeekEnd := nextWeek.AddDate(0, 0, daysInRange)
	query, err := calentities.NewEventRangeQuery(nextWeek, nextWeekEnd)
	if err != nil {
		c.Fatal(err.Error())
	}

	// add in a filter for UID so that we don't get back unwanted results
	pf := calentities.NewPropertyMatcher(properties.UIDPropertyName, uid)
	query.Filter.ComponentFilter.ComponentFilter.PropertyFilter = pf

	// send the query to the server
	if events, err := s.client.QueryEvents("/", query); err != nil {
		c.Fatal(err.Error())
	} else {
		// since this is a daily recurring event, we should only get back one event for every day in our range
		c.Assert(events, HasLen, daysInRange)
		for i, event := range events {

			// all events should have the same UID
			c.Assert(event.UID, Equals, uid)

			// all events should have a consistant recurrence ID
			day := nextWeek.AddDate(0, 0, i)
			offset := values.NewDateTime(day)
			c.Assert(event.RecurrenceId, DeepEquals, offset)

			if i == 0 {
				// the first event is an override, it should start an hour later and be twice as long
				c.Assert(event.DateStart, DeepEquals, overrideEvent.DateStart)
				c.Assert(event.Duration, DeepEquals, overrideEvent.Duration)
				c.Assert(event.Summary, DeepEquals, overrideEvent.Summary)
			} else {
				// regular occurences should start at the same time as their recurrence ID
				c.Assert(event.DateStart, DeepEquals, event.RecurrenceId)
				c.Assert(event.Duration, DeepEquals, putEvent.Duration)
				c.Assert(event.Summary, DeepEquals, putEvent.Summary)
			}
		}
	}

}