def test_exportOneAddressbook(self): """ Run the export with a single uid and --contacts """ yield populateAddressBooksFrom( { "user01": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), "2.vcf": adbk1Root.child("2.vcf").getContent(), "3.vcf": adbk1Root.child("3.vcf").getContent(), } }, "user02": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), }, } }, self.store) outputDir = FilePath(self.mktemp()) outputDir.makedirs() main([ 'calendarserver_export', '--directory', outputDir.path, '--uid', 'user01', '--contacts' ], reactor=self) yield self.waitToStop self.assertEquals( set(["user01_addressbook.vcf"]), set([child.basename() for child in outputDir.children()]))
def test_exportAllContacts(self): """ Run the export with --all --contacts to get a directory of addressbooks from all addressbook homes in the database. """ yield populateAddressBooksFrom( { "user01": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), "2.vcf": adbk1Root.child("2.vcf").getContent(), "3.vcf": adbk1Root.child("3.vcf").getContent(), } }, "user02": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), }, } }, self.store) outputDir = FilePath(self.mktemp()) outputDir.makedirs() main([ 'calendarserver_export', '--directory', outputDir.path, '--all', '--contacts' ], reactor=self) yield self.waitToStop self.assertEquals( set(["user01_addressbook.vcf", "user02_addressbook.vcf"]), set([child.basename() for child in outputDir.children()]))
def setUp(self): """ Set up two stores to migrate between. """ # Add some files to the file store. self.filesPath = CachingFilePath(self.mktemp()) self.filesPath.createDirectory() fileStore = self.fileStore = CommonDataStore( self.filesPath, {"push": StubNotifierFactory()}, TestStoreDirectoryService(), True, True ) self.sqlStore = yield theStoreBuilder.buildStore( self, StubNotifierFactory() ) self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore) requirements = CommonTests.requirements extras = deriveValue(self, "extraRequirements", lambda t: {}) requirements = self.mergeRequirements(requirements, extras) yield populateCalendarsFrom(requirements, fileStore) md5s = CommonTests.md5s yield resetCalendarMD5s(md5s, fileStore) self.filesPath.child("calendars").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data") requirements = ABCommonTests.requirements yield populateAddressBooksFrom(requirements, fileStore) md5s = ABCommonTests.md5s yield resetAddressBookMD5s(md5s, fileStore) self.filesPath.child("addressbooks").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data")
def setUp(self): """ Set up two stores to migrate between. """ # Add some files to the file store. self.filesPath = CachingFilePath(self.mktemp()) self.filesPath.createDirectory() fileStore = self.fileStore = CommonDataStore( self.filesPath, {"push": StubNotifierFactory()}, TestStoreDirectoryService(), True, True ) self.sqlStore = yield theStoreBuilder.buildStore( self, StubNotifierFactory() ) self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore) requirements = CommonTests.requirements extras = deriveValue(self, "extraRequirements", lambda t: {}) requirements = self.mergeRequirements(requirements, extras) yield populateCalendarsFrom(requirements, fileStore) md5s = CommonTests.md5s yield resetCalendarMD5s(md5s, fileStore) self.filesPath.child("calendars").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data") requirements = ABCommonTests.requirements yield populateAddressBooksFrom(requirements, fileStore) md5s = ABCommonTests.md5s yield resetAddressBookMD5s(md5s, fileStore) self.filesPath.child("addressbooks").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data") # Add some properties we want to check get migrated over txn = self.fileStore.newTransaction() home = yield txn.calendarHomeWithUID("home_defaults") cal = yield home.calendarWithName("calendar_1") props = cal.properties() props[PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet)] = caldavxml.SupportedCalendarComponentSet( caldavxml.CalendarComponent(name="VEVENT"), caldavxml.CalendarComponent(name="VTODO"), ) props[PropertyName.fromElement(element.ResourceType)] = element.ResourceType( element.Collection(), caldavxml.Calendar(), ) props[PropertyName.fromElement(customxml.GETCTag)] = customxml.GETCTag.fromString("foobar") inbox = yield home.calendarWithName("inbox") props = inbox.properties() props[PropertyName.fromElement(customxml.CalendarAvailability)] = customxml.CalendarAvailability.fromString(str(self.av1)) props[PropertyName.fromElement(caldavxml.ScheduleDefaultCalendarURL)] = caldavxml.ScheduleDefaultCalendarURL( element.HRef.fromString("/calendars/__uids__/home_defaults/calendar_1"), ) yield txn.commit()
def setUp(self): """ Set up two stores to migrate between. """ # Add some files to the file store. self.filesPath = CachingFilePath(self.mktemp()) self.filesPath.createDirectory() fileStore = self.fileStore = CommonDataStore( self.filesPath, StubNotifierFactory(), True, True ) self.sqlStore = yield theStoreBuilder.buildStore( self, StubNotifierFactory() ) subStarted = self.subStarted = Deferred() class StubService(Service, object): def startService(self): super(StubService, self).startService() if not subStarted.called: subStarted.callback(None) from twisted.python import log def justOnce(evt): if evt.get('isError') and not hasattr(subStarted, 'result'): subStarted.errback( evt.get('failure', RuntimeError("error starting up (see log)")) ) log.addObserver(justOnce) def cleanObserver(): try: log.removeObserver(justOnce) except ValueError: pass # x not in list, I don't care. self.addCleanup(cleanObserver) self.stubService = StubService() self.topService = MultiService() self.upgrader = self.createUpgradeService() self.upgrader.setServiceParent(self.topService) requirements = CommonTests.requirements extras = deriveValue(self, "extraRequirements", lambda t: {}) requirements = self.mergeRequirements(requirements, extras) yield populateCalendarsFrom(requirements, fileStore) md5s = CommonTests.md5s yield resetCalendarMD5s(md5s, fileStore) self.filesPath.child("calendars").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data") requirements = ABCommonTests.requirements yield populateAddressBooksFrom(requirements, fileStore) md5s = ABCommonTests.md5s yield resetAddressBookMD5s(md5s, fileStore) self.filesPath.child("addressbooks").child( "__uids__").child("ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data")
def setUp(self): """ Set up two stores to migrate between. """ yield super(HomeMigrationTests, self).setUp() yield self.buildStoreAndDirectory(extraUids=( u"home1", u"home2", u"home3", u"home_defaults", u"home_no_splits", u"home_splits", u"home_splits_shared", )) self.sqlStore = self.store # Add some files to the file store. self.filesPath = CachingFilePath(self.mktemp()) self.filesPath.createDirectory() fileStore = self.fileStore = CommonDataStore( self.filesPath, {"push": StubNotifierFactory()}, self.directory, True, True) self.upgrader = UpgradeToDatabaseStep(self.fileStore, self.sqlStore) requirements = CommonTests.requirements extras = deriveValue(self, "extraRequirements", lambda t: {}) requirements = self.mergeRequirements(requirements, extras) yield populateCalendarsFrom(requirements, fileStore) md5s = CommonTests.md5s yield resetCalendarMD5s(md5s, fileStore) self.filesPath.child("calendars").child("__uids__").child("ho").child( "me").child("home1").child(".some-extra-data").setContent( "some extra data") requirements = ABCommonTests.requirements yield populateAddressBooksFrom(requirements, fileStore) md5s = ABCommonTests.md5s yield resetAddressBookMD5s(md5s, fileStore) self.filesPath.child("addressbooks").child("__uids__").child( "ho").child("me").child("home1").child( ".some-extra-data").setContent("some extra data") # Add some properties we want to check get migrated over txn = self.fileStore.newTransaction() home = yield txn.calendarHomeWithUID("home_defaults") cal = yield home.calendarWithName("calendar_1") props = cal.properties() props[PropertyName.fromElement( caldavxml.SupportedCalendarComponentSet )] = caldavxml.SupportedCalendarComponentSet( caldavxml.CalendarComponent(name="VEVENT"), caldavxml.CalendarComponent(name="VTODO"), ) props[PropertyName.fromElement( element.ResourceType)] = element.ResourceType( element.Collection(), caldavxml.Calendar(), ) props[PropertyName.fromElement( customxml.GETCTag)] = customxml.GETCTag.fromString("foobar") inbox = yield home.calendarWithName("inbox") props = inbox.properties() props[PropertyName.fromElement( customxml.CalendarAvailability )] = customxml.CalendarAvailability.fromString(str(self.av1)) props[PropertyName.fromElement( caldavxml.ScheduleDefaultCalendarURL )] = caldavxml.ScheduleDefaultCalendarURL( element.HRef.fromString( "/calendars/__uids__/home_defaults/calendar_1"), ) yield txn.commit()
def populate(self): yield populateCalendarsFrom(self.requirements, self.storeUnderTest()) yield populateAddressBooksFrom(self.requirements, self.storeUnderTest())
def populate(self): yield populateAddressBooksFrom(self.requirements, self.storeUnderTest()) self.notifierFactory.reset()
def test_exportMixAndMatch(self): """ Run the export with some calendars and some addressbooks """ yield populateAddressBooksFrom( { "user01": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), "2.vcf": adbk1Root.child("2.vcf").getContent(), "3.vcf": adbk1Root.child("3.vcf").getContent(), } }, "user02": { "addressbook": { "1.vcf": adbk1Root.child("1.vcf").getContent(), }, } }, self.store) yield populateCalendarsFrom( { "user01": { "calendar1": { "valentines-day.ics": (valentines, {}), "new-years-day.ics": (newYears, {}) } }, "user02": { "calendar1": { "valentines-day.ics": (valentines, {}) }, "calendar2": { "new-years-day.ics": (newYears, {}) } } }, self.store) outputDir = FilePath(self.mktemp()) outputDir.makedirs() main([ 'calendarserver_export', '--directory', outputDir.path, '--uid', 'user01', '--contacts', '--uid', 'user01', '--calendars', '--uid', 'user02', '--collection=calendar1', '--uid', 'user02', '--contacts', ], reactor=self) yield self.waitToStop self.assertEquals( set([ "user01_addressbook.vcf", "user01_calendar1.ics", "user02_calendar1.ics", "user02_addressbook.vcf" ]), set([child.basename() for child in outputDir.children()]))