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_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_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 cal_dbpath(tmpdir): name = 'testcal' vdirpath = str(tmpdir) + '/' + name dbpath = str(tmpdir) + '/subdir/' + 'khal.db' cal = Calendar(name, dbpath, vdirpath, **KWARGS) return cal, dbpath
def cal_vdir(tmpdir): cal = Calendar(cal1, ':memory:', str(tmpdir), color='dark blue', locale=locale) vdir = FilesystemStorage(str(tmpdir), '.ics') return cal, vdir
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): name = 'testcal' vdirpath = str(tmpdir) + '/' + name dbdir = str(tmpdir) + '/subdir/' dbpath = dbdir + 'khal.db' assert not os.path.isdir(dbdir) Calendar(name, dbpath, vdirpath, **KWARGS) assert os.path.isdir(dbdir)
def test_failed_create_db(self, tmpdir): name = 'testcal' vdirpath = str(tmpdir) + '/' + name dbdir = str(tmpdir) + '/subdir/' dbpath = dbdir + 'khal.db' os.chmod(str(tmpdir), 400) with pytest.raises(CouldNotCreateDbDir): Calendar(name, dbpath, vdirpath, **KWARGS)
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 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 cal_vdir(tmpdir): cal = Calendar(cal1, ':memory:', str(tmpdir), **KWARGS) vdir = FilesystemStorage(str(tmpdir), '.ics') return cal, vdir