# -*- coding: utf-8 -*- =begin Copyright (C) 2012-2014 Takashi SUGA You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive. =end module MiniTest class GoogleCalendar < MiniTest::TestCase config = ::When.config ACCOUNT, PASSWORD = config['@'] if config.key?('@') PUBLIC_FEED = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" PRIVATE_FEED = "http://www.google.com/calendar/feeds/%s%%40gmail.com/private/full" YEAR = "1949" RULE0 = <'2013-01-01', 'start-max'=>'2014-01-01', 'orderby'=>'starttime', 'sortorder'=>'a' # a:asend, d:desend }).each do |event| vevent = event.to_vevent assert_equal(holidays.shift, [vevent.summary, vevent.dtstart.to_s, vevent.dtend.to_s]) # puts event.xml end assert_equal(0, holidays.size) end def test__to_gcalevent gcal = get_cal(PRIVATE_FEED % ACCOUNT) period = {'start-min'=>'2001-01-01', 'start-max'=>'2001-01-31'} gcal.events(period).each do |event| event.destroy end event = When.Resource("examples/JapanHolidays.ics::Ganjitsu").to_gcalevent(gcal) event.save! holidays = [RULE0] gcal.events(period).each do |event| assert_equal(holidays.shift, event.recurrence) end assert_equal(0, holidays.size) end def test__enum_for holidays = HOLIDAYS2.dup gcal = get_cal(PUBLIC_FEED % ['japanese', 'ja']) gcal.enum_for({'start-min'=>'2013-01-01', 'start-max'=>'2014-01-01'}).each do |date| sample = holidays.shift assert_equal(sample[1] + '...' + sample[2], date.to_s) end assert_equal(0, holidays.size) end =begin def test__private_events_1 weekly_events = WEEKLY_EVENTS.dup gcal = get_cal(PRIVATE_FEED % ACCOUNT) period = {'start-min'=>'2014-07-01', 'start-max'=>'2014-08-01'} assert_equal(["canceled","confirmed"], gcal.events(period).map {|event| event.event_status}) gcal.enum_for(period).each do |date| assert_equal(weekly_events.shift, date.to_s) end assert_equal(0, weekly_events.size) end def test__private_events_2 gcal = get_cal(PRIVATE_FEED % ACCOUNT) period = {'start-min'=>YEAR + '-03-01', 'start-max'=>YEAR + '-03-31'} gcal.events(period).each do |event| event.destroy end new_event = gcal.create_event new_event.title = "MiniTest Event" new_event.desc = "MiniTest Event Description" new_event.where = "America/New_York" #new_event.st = Time.mktime(YEAR.to_i, 3, 21, 12, 0, 0) #new_event.en = Time.mktime(YEAR.to_i, 3, 22, 13, 0, 0) new_event.recurrence = RULE1 new_event.save! gcal.events(period).each do |event| assert_equal([new_event.title, new_event.desc, new_event.where, RECURRENCE], [event.title, event.desc, event.where, event.recurrence]) end new_event.destroy end =end else puts "Tests for GoogleCalendar have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}." end end end