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 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): 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 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 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 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 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 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 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_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)