def test_default_calendar(self, tmpdir): calendars = { 'foobar': { 'name': 'foobar', 'path': str(tmpdir), 'readonly': True }, 'home': { 'name': 'home', 'path': str(tmpdir) }, "Dad's Calendar": { 'name': "Dad's calendar", 'path': str(tmpdir), 'readonly': True }, } coll = CalendarCollection( calendars=calendars, locale=LOCALE_BERLIN, dbpath=':memory:', ) assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = "Dad's calendar" assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = 'unknownstuff' assert coll.default_calendar_name is None coll.default_calendar_name = 'home' assert coll.default_calendar_name == 'home' assert coll.writable_names == ['home']
def test_default_calendar(self, tmpdir): calendars = { 'foobar': { 'name': 'foobar', 'path': str(tmpdir), 'readonly': True }, 'home': { 'name': 'home', 'path': str(tmpdir) }, 'work': { 'name': 'work', 'path': str(tmpdir), 'readonly': True }, } coll = CalendarCollection(calendars=calendars, locale=aux.locale, dbpath=':memory:') assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = 'work' assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = 'unknownstuff' assert coll.default_calendar_name is None coll.default_calendar_name = 'home' assert coll.default_calendar_name == 'home' assert coll.writable_names == ['home']
def coll_vdirs(tmpdir): coll = CalendarCollection() vdirs = dict() for name in example_cals: path = str(tmpdir) + '/' + name os.makedirs(path, mode=0o770) coll.append(Calendar(name, ':memory:', path, **KWARGS)) vdirs[name] = FilesystemStorage(path, '.ics') return coll, vdirs
def coll_vdirs(tmpdir): coll = CalendarCollection(locale=locale) vdirs = dict() for name in example_cals: path = str(tmpdir) + '/' + name os.makedirs(path, mode=0o770) coll.append( Calendar(name, ':memory:', path, color='dark blue', locale=locale)) vdirs[name] = FilesystemStorage(path, '.ics') coll.default_calendar_name = cal1 return coll, vdirs
def coll_vdirs(tmpdir): calendars, vdirs = dict(), dict() for name in example_cals: path = str(tmpdir) + '/' + name os.makedirs(path, mode=0o770) calendars[name] = {'name': name, 'path': path, 'color': 'dark blue', 'readonly': False, 'unicode_symbols': True} vdirs[name] = FilesystemStorage(path, '.ics') coll = CalendarCollection(calendars=calendars, dbpath=':memory:', locale=locale) coll.default_calendar_name = cal1 return coll, vdirs
def coll_vdirs(tmpdir): calendars, vdirs = dict(), dict() for name in example_cals: path = str(tmpdir) + '/' + name os.makedirs(path, mode=0o770) readonly = True if name == 'a_calendar' else False calendars[name] = {'name': name, 'path': path, 'color': 'dark blue', 'readonly': readonly, 'unicode_symbols': True} vdirs[name] = Vdir(path, '.ics') coll = CalendarCollection(calendars=calendars, dbpath=':memory:', locale=LOCALE_BERLIN) coll.default_calendar_name = cal1 return coll, vdirs
def test_insert_calendar_readonly(self, tmpdir): coll = CalendarCollection() coll.append( Calendar('foobar', ':memory:', str(tmpdir), readonly=True, **KWARGS)) coll.append(Calendar('home', ':memory:', str(tmpdir), **KWARGS)) coll.append( Calendar('work', ':memory:', str(tmpdir), readonly=True, **KWARGS)) event = Event(event_dt, calendar='home', **KWARGS) with pytest.raises(khal.khalendar.exceptions.ReadOnlyCalendarError): coll.new(event, cal1)
def test_failed_create_db(self, tmpdir): dbdir = str(tmpdir) + '/subdir/' dbpath = dbdir + 'khal.db' os.chmod(str(tmpdir), 400) calendars = {cal1: {'name': cal1, 'path': str(tmpdir)}} with pytest.raises(CouldNotCreateDbDir): CalendarCollection(calendars, dbpath=dbpath, locale=utils.locale)
def test_create_db(self, tmpdir): vdirpath = str(tmpdir) + '/' + cal1 os.makedirs(vdirpath, mode=0o770) dbdir = str(tmpdir) + '/subdir/' dbpath = dbdir + 'khal.db' assert not os.path.isdir(dbdir) calendars = {cal1: {'name': cal1, 'path': vdirpath}} CalendarCollection(calendars, dbpath=dbpath, locale=LOCALE_BERLIN) assert os.path.isdir(dbdir)
def test_default_calendar_not_readonly(self, tmpdir): coll = CalendarCollection() coll.append( Calendar('foobar', ':memory:', str(tmpdir), readonly=True, **KWARGS)) coll.append(Calendar('home', ':memory:', str(tmpdir), **KWARGS)) coll.append( Calendar('work', ':memory:', str(tmpdir), readonly=True, **KWARGS)) assert coll.default_calendar_name == 'home'
def test_modify_readonly_calendar(self, tmpdir): coll = CalendarCollection(locale=locale) coll.append( Calendar('foobar', ':memory:', str(tmpdir), readonly=True, locale=locale)) coll.append(Calendar('home', ':memory:', str(tmpdir), locale=locale)) coll.append( Calendar('work', ':memory:', str(tmpdir), readonly=True, locale=locale)) event = Event.fromString(event_dt, calendar='home', locale=locale) with pytest.raises(khal.khalendar.exceptions.ReadOnlyCalendarError): coll.new(event, cal1) with pytest.raises(khal.khalendar.exceptions.ReadOnlyCalendarError): # params don't really matter here coll.delete('href', 'eteg', cal1)
def test_default_calendar(self, tmpdir): coll = CalendarCollection(locale=locale) coll.append( Calendar('foobar', ':memory:', str(tmpdir), readonly=True, locale=locale)) coll.append(Calendar('home', ':memory:', str(tmpdir), locale=locale)) coll.append( Calendar('work', ':memory:', str(tmpdir), readonly=True, locale=locale)) assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = 'work' assert coll.default_calendar_name is None with pytest.raises(ValueError): coll.default_calendar_name = 'unknownstuff' assert coll.default_calendar_name is None coll.default_calendar_name = 'home' assert coll.default_calendar_name == 'home' assert coll.writable_names == ['home']
def get_events_between( collection: CalendarCollection, locale: dict, start: dt.datetime, end: dt.datetime, agenda_format: str, notstarted: bool, env: dict, width, seen, original_start: dt.datetime, ) -> List[str]: """returns a list of events scheduled between start and end. Start and end are strings or datetimes (of some kind). :param collection: :param start: the start datetime :param end: the end datetime :param agenda_format: a format string that can be used in python string formatting :param env: a collection of "static" values like calendar names and color :param nostarted: True if each event should start after start (instead of be active between start and end) :param original_start: start datetime to compare against of notstarted is set :returns: a list to be printed as the agenda for the given days """ assert not (notstarted and not original_start) event_list = [] if env is None: env = {} assert start assert end start_local = locale['local_timezone'].localize(start) end_local = locale['local_timezone'].localize(end) start = start_local.replace(tzinfo=None) end = end_local.replace(tzinfo=None) events = sorted(collection.get_localized(start_local, end_local)) events_float = sorted(collection.get_floating(start, end)) events = sorted(events + events_float) for event in events: # yes the logic could be simplified, but I believe it's easier # to understand what's going on here this way if notstarted: if event.allday and event.start < original_start.date(): continue elif not event.allday and event.start_local < original_start: continue if seen is not None and event.uid in seen: continue try: event_string = event.format(agenda_format, relative_to=(start, end), env=env) except KeyError as error: raise FatalError(error) if width: event_list += utils.color_wrap(event_string, width) else: event_list.append(event_string) if seen is not None: seen.add(event.uid) return event_list