def setUp(self): """ Create a L{UIDsFolder}. """ self.svc = ShellService(store=(yield buildStore(self, None)), directory=DirectoryStubber(self).service(), options=None, reactor=None, config=None) self.folder = UIDsFolder(self.svc, ())
def setUp(self): """ Set up two stores to migrate between. """ yield super(CommonSQLStoreTests, self).setUp() self._sqlStore = yield buildStore(self, self.notifierFactory) self._sqlStore.directoryService().addRecord(buildDirectoryRecord(denormalizedUID)) self._sqlStore.directoryService().addRecord(buildDirectoryRecord(normalizedUID)) self._sqlStore.directoryService().addRecord(buildDirectoryRecord("uid"))
def setUp(self): self.notifierFactory = StubNotifierFactory() self.store = yield buildStore(self, self.notifierFactory) self.addCleanup(self.maybeCommitLast) self._txn = self.store.newTransaction() self.propertyStore = self.propertyStore1 = yield PropertyStore.load( "user01", None, self._txn, 1 ) self.propertyStore2 = yield PropertyStore.load("user01", "user02", self._txn, 1)
def setUp(self): self.notifierFactory = StubNotifierFactory() self.store = yield buildStore(self, self.notifierFactory) self.addCleanup(self.maybeCommitLast) self._txn = self.store.newTransaction() self.propertyStore = \ self.propertyStore1 = yield PropertyStore.load("user01", None, None, self._txn, 1) self.propertyStore2 = yield PropertyStore.load("user01", "user02", None, self._txn, 1) self.propertyStore3 = yield PropertyStore.load("user01", None, "user03", self._txn, 1) self.propertyStore4 = yield PropertyStore.load("user01", "user02", "user04", self._txn, 1)
def setUp(self): self.store = yield buildStore(self, None) self.directory = self.store.directoryService() self.sender = MailSender( "*****@*****.**", 7, DummySMTPSender(), language="en") def _getSender(ignored): return self.sender self.patch(IMIPInvitationWork, "getMailSender", _getSender)
def setUp(self): self.store = yield buildStore(self, None) self.directory = self.store.directoryService() self.sender = MailSender("*****@*****.**", 7, DummySMTPSender(), language="en") def _getSender(ignored): return self.sender self.patch(IMIPInvitationWork, "getMailSender", _getSender) self.wp = None self.store.queuer.callWithNewProposals(self._proposalCallback)
def setUp(self): self.store = yield buildStore(self, None) self.directory = self.store.directoryService() self.sender = MailSender( "*****@*****.**", 7, DummySMTPSender(), language="en") def _getSender(ignored): return self.sender self.patch(IMIPInvitationWork, "getMailSender", _getSender) self.wp = None self.store.queuer.callWithNewProposals(self._proposalCallback)
def setUp(self): """ Set up a store and fix the imported C{utilityMain} function (normally from L{calendarserver.tools.cmdline.utilityMain}) to point to a temporary method of this class. Also, patch the imported C{reactor}, since the SUT needs to call C{reactor.stop()} in order to work with L{utilityMain}. """ self.mainCalled = False self.patch(export, "utilityMain", self.fakeUtilityMain) self.store = yield buildStore(self, None) self.waitToStop = Deferred()
def setUp(self): self.calendarStore = yield buildStore(self, StubNotifierFactory()) yield super(SharingTests, self).setUp() def patched(c): """ The decorated method is patched on L{CalDAVResource} for the duration of the test. """ self.patch(CalDAVResource, c.__name__, c) return c @patched def sendInviteNotification(resourceSelf, record, request): """ For testing purposes, sending an invite notification succeeds without doing anything. """ return succeed(True) @patched def removeInviteNotification(resourceSelf, record, request): """ For testing purposes, removing an invite notification succeeds without doing anything. """ return succeed(True) @patched def principalForCalendarUserAddress(resourceSelf, cuaddr): if "bogus" in cuaddr: return None else: return FakePrincipal(cuaddr, self) @patched def validUserIDForShare(resourceSelf, userid, request): """ Temporary replacement for L{CalDAVResource.validUserIDForShare} that marks any principal without 'bogus' in its name. """ result = principalForCalendarUserAddress(resourceSelf, userid) if result is None: return result return result.principalURL() @patched def principalForUID(resourceSelf, principalUID): return FakePrincipal("urn:uuid:" + principalUID, self)
def testScheduling(self): """ Exercise schedulePolledGroupCachingUpdate """ groupCacher = StubGroupCacher() def decorateTransaction(txn): txn._groupCacher = groupCacher store = yield buildStore(self, None) store.callWithNewTransactions(decorateTransaction) wp = (yield schedulePolledGroupCachingUpdate(store)) yield wp.whenExecuted() self.assertTrue(groupCacher.called)
def setUp(self): yield super(PurgePrincipalTests, self).setUp() self._sqlCalendarStore = yield buildStore(self, self.notifierFactory) yield self.populate() self.patch(config.DirectoryService.params, "xmlFile", os.path.join( os.path.dirname(__file__), "purge", "accounts.xml" ) ) self.patch(config.ResourceService.params, "xmlFile", os.path.join( os.path.dirname(__file__), "purge", "resources.xml" ) ) self.rootResource = getRootResource(config, self._sqlCalendarStore) self.directory = self.rootResource.getDirectory() txn = self._sqlCalendarStore.newTransaction() # Add attachment to attachment.ics self._sqlCalendarStore._dropbox_ok = True home = (yield txn.calendarHomeWithUID(self.uid)) calendar = (yield home.calendarWithName("calendar1")) event = (yield calendar.calendarObjectWithName("attachment.ics")) attachment = (yield event.createAttachmentWithName("attachment.txt")) t = attachment.store(MimeType("text", "x-fixture")) t.write("attachment") t.write(" text") (yield t.loseConnection()) self._sqlCalendarStore._dropbox_ok = False # Share calendars each way home2 = (yield txn.calendarHomeWithUID(self.uid2)) calendar2 = (yield home2.calendarWithName("calendar2")) self.sharedName = (yield calendar2.shareWith(home, _BIND_MODE_WRITE)) self.sharedName2 = (yield calendar.shareWith(home2, _BIND_MODE_WRITE)) (yield txn.commit()) txn = self._sqlCalendarStore.newTransaction() home = (yield txn.calendarHomeWithUID(self.uid)) calendar2 = (yield home.childWithName(self.sharedName)) self.assertNotEquals(calendar2, None) home2 = (yield txn.calendarHomeWithUID(self.uid2)) calendar1 = (yield home2.childWithName(self.sharedName2)) self.assertNotEquals(calendar1, None) (yield txn.commit())
def setUp(self): """ L{PeerConnectionPool} requires access to a database and the reactor. """ self.store = yield buildStore(self, None) def doit(txn): return txn.execSQL(schemaText) yield inTransaction(lambda: self.store.newTransaction("bonus schema"), doit) def indirectedTransactionFactory(*a): """ Allow tests to replace 'self.store.newTransaction' to provide fixtures with extra methods on a test-by-test basis. """ return self.store.newTransaction(*a) def deschema(): @inlineCallbacks def deletestuff(txn): for stmt in dropSQL: yield txn.execSQL(stmt) return inTransaction(lambda *a: self.store.newTransaction(*a), deletestuff) self.addCleanup(deschema) from twisted.internet import reactor self.node1 = PeerConnectionPool( reactor, indirectedTransactionFactory, 0, schema) self.node2 = PeerConnectionPool( reactor, indirectedTransactionFactory, 0, schema) class FireMeService(Service, object): def __init__(self, d): super(FireMeService, self).__init__() self.d = d def startService(self): self.d.callback(None) d1 = Deferred() d2 = Deferred() FireMeService(d1).setServiceParent(self.node1) FireMeService(d2).setServiceParent(self.node2) ms = MultiService() self.node1.setServiceParent(ms) self.node2.setServiceParent(ms) ms.startService() self.addCleanup(ms.stopService) yield gatherResults([d1, d2]) self.store.queuer = self.node1
def setUp(self): self.store = yield buildStore(self, None) self.directory = XMLDirectoryService( { 'xmlFile' : xmlFile, 'augmentService' : augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)), } ) self.sender = MailSender("*****@*****.**", 7, DummySMTPSender(), language="en") def _getSender(ignored): return self.sender self.patch(IMIPInvitationWork, "getMailSender", _getSender) self.wp = None self.store.queuer.callWithNewProposals(self._proposalCallback)
def setUp(self): yield super(RecipientCopy, self).setUp() self._sqlCalendarStore = yield buildStore(self, self.notifierFactory) yield self.populate() self.patch(config.DirectoryService.params, "xmlFile", os.path.join( os.path.dirname(__file__), "accounts.xml" ) ) self.patch(config.ResourceService.params, "xmlFile", os.path.join( os.path.dirname(__file__), "resources.xml" ) ) self.rootResource = getRootResource(config, self._sqlCalendarStore) self.directory = self.rootResource.getDirectory()
def test_addressbookObjectUID(self): """ Test that kind property UID is stored correctly in database """ addressbookStore = yield buildStore(self, self.notifierFactory) # Provision the home and addressbook, one user and one group txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) self.assertNotEqual(home, None) adbk = yield home.addressbookWithName("addressbook") self.assertNotEqual(adbk, None) person = VCard.fromString( """BEGIN:VCARD VERSION:3.0 N:Thompson;Default;;; FN:Default Thompson EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] TEL;type=WORK;type=pref:1-555-555-5555 TEL;type=CELL:1-444-444-4444 item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA item1.X-ABADR:us UID:uid1 END:VCARD """.replace("\n", "\r\n") ) self.assertEqual(person.resourceUID(), "uid1") abObject = yield adbk.createAddressBookObjectWithName("1.vcf", person) self.assertEqual(abObject.uid(), "uid1") yield txn.commit() txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) adbk = yield home.addressbookWithName("addressbook") abObject = yield adbk.objectResourceWithName("1.vcf") person = yield abObject.component() self.assertEqual(person.resourceUID(), "uid1") yield home.removeAddressBookWithName("addressbook") yield txn.commit()
def setUp(self): yield super(AddressBookSQLStorageTests, self).setUp() self._sqlStore = yield buildStore( self, self.notifierFactory, homes=( "home1", "home2", "home3", "home_bad", "home_empty", "homeNew", "new-home", "uid1", "uid2", "xyzzy", ) ) yield self.populate()
def test_work(self): self.store = yield buildStore(self, None) pushDistributor = StubDistributor() def decorateTransaction(txn): txn._pushDistributor = pushDistributor self.store.callWithNewTransactions(decorateTransaction) txn = self.store.newTransaction() wp = (yield txn.enqueue(PushNotificationWork, pushID="/CalDAV/localhost/foo/", )) yield txn.commit() yield wp.whenExecuted() self.assertEquals(pushDistributor.history, ["/CalDAV/localhost/foo/"]) pushDistributor.reset() txn = self.store.newTransaction() wp = (yield txn.enqueue(PushNotificationWork, pushID="/CalDAV/localhost/bar/", )) wp = (yield txn.enqueue(PushNotificationWork, pushID="/CalDAV/localhost/bar/", )) wp = (yield txn.enqueue(PushNotificationWork, pushID="/CalDAV/localhost/bar/", )) # Enqueue a different pushID to ensure those are not grouped with # the others: wp = (yield txn.enqueue(PushNotificationWork, pushID="/CalDAV/localhost/baz/", )) yield txn.commit() yield wp.whenExecuted() self.assertEquals(pushDistributor.history, ["/CalDAV/localhost/bar/", "/CalDAV/localhost/baz/"])
def setUp(self): super(InboundTests, self).setUp() self.store = yield buildStore(self, None) self.patch(config.DirectoryService.params, "xmlFile", xmlFile) self.root = getRootResource(config, self.store) self.directory = self.root.getDirectory() self.receiver = MailReceiver(self.store, self.directory) self.retriever = MailRetriever(self.store, self.directory, ConfigDict({ "Type" : "pop", "UseSSL" : False, "Server" : "example.com", "Port" : 123, }) ) def decorateTransaction(txn): txn._rootResource = self.root txn._mailRetriever = self.retriever self.store.callWithNewTransactions(decorateTransaction) module = getModule(__name__) self.dataPath = module.filePath.sibling("data")
def setUp(self): """ L{PeerConnectionPool} requires access to a database and the reactor. """ self.store = yield buildStore(self, None) @inlineCallbacks def doit(txn): for statement in splitSQLString(nodeSchema + schemaText): yield txn.execSQL(statement) yield inTransaction(lambda: self.store.newTransaction("bonus schema"), doit) def indirectedTransactionFactory(*a): """ Allow tests to replace "self.store.newTransaction" to provide fixtures with extra methods on a test-by-test basis. """ return self.store.newTransaction(*a) def deschema(): @inlineCallbacks def deletestuff(txn): for stmt in dropSQL: yield txn.execSQL(stmt) txn.execSQL("drop table node_info") return inTransaction(lambda *a: self.store.newTransaction(*a), deletestuff) self.addCleanup(deschema) from twisted.internet import reactor self.node1 = PeerConnectionPool(reactor, indirectedTransactionFactory, 0, schema) self.node2 = PeerConnectionPool(reactor, indirectedTransactionFactory, 0, schema) class FireMeService(Service, object): def __init__(self, d): super(FireMeService, self).__init__() self.d = d def startService(self): self.d.callback(None) d1 = Deferred() d2 = Deferred() FireMeService(d1).setServiceParent(self.node1) FireMeService(d2).setServiceParent(self.node2) ms = MultiService() self.node1.setServiceParent(ms) self.node2.setServiceParent(ms) ms.startService() @inlineCallbacks def _clean(): yield ms.stopService() self.flushLoggedErrors(CancelledError) self.addCleanup(_clean) yield gatherResults([d1, d2]) self.store.queuer = self.node1
def test_addressbookObjectKind(self): """ Test that kind property vCard is stored correctly in database """ addressbookStore = yield buildStore(self, self.notifierFactory) # Provision the home and addressbook, one user and one group txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) self.assertNotEqual(home, None) adbk = yield home.addressbookWithName("addressbook") self.assertNotEqual(adbk, None) person = VCard.fromString( """BEGIN:VCARD VERSION:3.0 N:Thompson;Default;;; FN:Default Thompson EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] TEL;type=WORK;type=pref:1-555-555-5555 TEL;type=CELL:1-444-444-4444 item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA item1.X-ABADR:us UID:uid1 END:VCARD """.replace("\n", "\r\n") ) self.assertEqual(person.resourceKind(), None) abObject = yield adbk.createAddressBookObjectWithName("p.vcf", person) self.assertEqual(abObject.kind(), _ABO_KIND_PERSON) group = VCard.fromString( """BEGIN:VCARD VERSION:3.0 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN UID:uid2 FN:Top Group N:Top Group;;;; REV:20120503T194243Z X-ADDRESSBOOKSERVER-KIND:group X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid1 END:VCARD """.replace("\n", "\r\n") ) abObject = self.assertEqual(group.resourceKind(), "group") abObject = yield adbk.createAddressBookObjectWithName("g.vcf", group) self.assertEqual(abObject.kind(), _ABO_KIND_GROUP) badgroup = VCard.fromString( """BEGIN:VCARD VERSION:3.0 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN UID:uid3 FN:Bad Group N:Bad Group;;;; REV:20120503T194243Z X-ADDRESSBOOKSERVER-KIND:badgroup X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid1 END:VCARD """.replace("\n", "\r\n") ) abObject = self.assertEqual(badgroup.resourceKind(), "badgroup") abObject = yield adbk.createAddressBookObjectWithName("bg.vcf", badgroup) self.assertEqual(abObject.kind(), _ABO_KIND_PERSON) yield txn.commit() txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) adbk = yield home.addressbookWithName("addressbook") abObject = yield adbk.objectResourceWithName("p.vcf") person = yield abObject.component() self.assertEqual(person.resourceKind(), None) self.assertEqual(abObject.kind(), _ABO_KIND_PERSON) abObject = yield adbk.objectResourceWithName("g.vcf") group = yield abObject.component() self.assertEqual(group.resourceKind(), "group") self.assertEqual(abObject.kind(), _ABO_KIND_GROUP) abObject = yield adbk.objectResourceWithName("bg.vcf") badgroup = yield abObject.component() self.assertEqual(badgroup.resourceKind(), "badgroup") self.assertEqual(abObject.kind(), _ABO_KIND_PERSON) yield home.removeAddressBookWithName("addressbook") yield txn.commit()
def test_addressbookObjectMembers(self): """ Test that kind property vCard is stored correctly in database """ addressbookStore = yield buildStore(self, self.notifierFactory) # Provision the home and addressbook, one user and one group txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) self.assertNotEqual(home, None) adbk = yield home.addressbookWithName("addressbook") self.assertNotEqual(adbk, None) person = VCard.fromString( """BEGIN:VCARD VERSION:3.0 N:Thompson;Default;;; FN:Default Thompson EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] TEL;type=WORK;type=pref:1-555-555-5555 TEL;type=CELL:1-444-444-4444 item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA item1.X-ABADR:us UID:uid1 END:VCARD """.replace("\n", "\r\n") ) self.assertEqual(person.resourceKind(), None) personObject = yield adbk.createAddressBookObjectWithName("p.vcf", person) group = VCard.fromString( """BEGIN:VCARD VERSION:3.0 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN UID:uid2 FN:Top Group N:Top Group;;;; REV:20120503T194243Z X-ADDRESSBOOKSERVER-KIND:group X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid3 END:VCARD """.replace("\n", "\r\n") ) groupObject = yield adbk.createAddressBookObjectWithName("g.vcf", group) aboForeignMembers = schema.ABO_FOREIGN_MEMBERS aboMembers = schema.ABO_MEMBERS memberRows = yield Select([aboMembers.GROUP_ID, aboMembers.MEMBER_ID], From=aboMembers,).on(txn) self.assertEqual(memberRows, []) foreignMemberRows = yield Select([aboForeignMembers.GROUP_ID, aboForeignMembers.MEMBER_ADDRESS], From=aboForeignMembers).on(txn) self.assertEqual(foreignMemberRows, [[groupObject._resourceID, "urn:uuid:uid3"]]) subgroup = VCard.fromString( """BEGIN:VCARD VERSION:3.0 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN UID:uid3 FN:Sub Group N:Sub Group;;;; REV:20120503T194243Z X-ADDRESSBOOKSERVER-KIND:group X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid1 END:VCARD """.replace("\n", "\r\n") ) subgroupObject = yield adbk.createAddressBookObjectWithName("sg.vcf", subgroup) memberRows = yield Select([aboMembers.GROUP_ID, aboMembers.MEMBER_ID], From=aboMembers,).on(txn) self.assertEqual(sorted(memberRows), sorted([ [groupObject._resourceID, subgroupObject._resourceID], [subgroupObject._resourceID, personObject._resourceID], ])) foreignMemberRows = yield Select([aboForeignMembers.GROUP_ID, aboForeignMembers.MEMBER_ADDRESS], From=aboForeignMembers).on(txn) self.assertEqual(foreignMemberRows, []) yield subgroupObject.remove() memberRows = yield Select([aboMembers.GROUP_ID, aboMembers.MEMBER_ID], From=aboMembers,).on(txn) self.assertEqual(memberRows, []) foreignMemberRows = yield Select([aboForeignMembers.GROUP_ID, aboForeignMembers.MEMBER_ADDRESS], From=aboForeignMembers, #Where=(aboForeignMembers.GROUP_ID == groupObject._resourceID), ).on(txn) self.assertEqual(foreignMemberRows, [[groupObject._resourceID, "urn:uuid:uid3"]]) yield home.removeAddressBookWithName("addressbook") yield txn.commit()
def setUp(self): yield super(ApplePushNotifierServiceTests, self).setUp() self.store = yield buildStore(self, None)
def setUp(self): yield super(AddressBookSQLStorageTests, self).setUp() self._sqlStore = yield buildStore(self, self.notifierFactory) yield self.populate()
def setUp(self): super(MailGatewayTokenDBTests, self).setUp() self.store = yield buildStore(self, None) self.directory = self.store.directoryService()
def setUp(self): self.calendarStore = yield buildStore(self, StubNotifierFactory()) super(DatabaseWrappingTests, self).setUp()
def setUp(self): self.calendarStore = yield buildStore(self, StubNotifierFactory()) yield super(DatabaseQueryTests, self).setUp()
def setUp(self): yield super(HomeMigrationTests, self).setUp() self.theStore = yield buildStore(self, self.notifierFactory)
def setUp(self): """ Set up two stores to migrate between. """ yield super(CommonSQLStoreTests, self).setUp() self._sqlStore = yield buildStore(self, self.notifierFactory)
def test_putConcurrency(self): """ Test that two concurrent attempts to PUT different address book object resources to the same address book home does not cause a deadlock. """ addressbookStore = yield buildStore(self, self.notifierFactory) # Provision the home and addressbook now txn = addressbookStore.newTransaction() home = yield txn.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) self.assertNotEqual(home, None) adbk = yield home.addressbookWithName("addressbook") self.assertNotEqual(adbk, None) yield txn.commit() txn1 = addressbookStore.newTransaction() txn2 = addressbookStore.newTransaction() home1 = yield txn1.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) home2 = yield txn2.homeWithUID(EADDRESSBOOKTYPE, "uid1", create=True) adbk1 = yield home1.addressbookWithName("addressbook") adbk2 = yield home2.addressbookWithName("addressbook") @inlineCallbacks def _defer1(): yield adbk1.createAddressBookObjectWithName("1.vcf", VCard.fromString( """BEGIN:VCARD VERSION:3.0 N:Thompson;Default1;;; FN:Default1 Thompson EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] TEL;type=WORK;type=pref:1-555-555-5555 TEL;type=CELL:1-444-444-4444 item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA item1.X-ABADR:us UID:uid1 END:VCARD """.replace("\n", "\r\n") )) yield txn1.commit() # FIXME: CONCURRENT d1 = _defer1() @inlineCallbacks def _defer2(): yield adbk2.createAddressBookObjectWithName("2.vcf", VCard.fromString( """BEGIN:VCARD VERSION:3.0 N:Thompson;Default2;;; FN:Default2 Thompson EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] TEL;type=WORK;type=pref:1-555-555-5556 TEL;type=CELL:1-444-444-4445 item1.ADR;type=WORK;type=pref:;;1234 Test;Sesame Street;California;11111;USA item1.X-ABADR:us UID:uid2 END:VCARD """.replace("\n", "\r\n") )) yield txn2.commit() # FIXME: CONCURRENT d2 = _defer2() yield d1 yield d2