Ejemplo n.º 1
0
    def setUp(self):
        yield super(MigrateResourcesTest, self).setUp()
        self.store = self.storeUnderTest()

        self.sourceService = InMemoryDirectoryService(None)
        fieldName = self.sourceService.fieldName
        records = (
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"loc1", ),
                    fieldName.recordType: CalRecordType.location,
                }),
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location2",
                    fieldName.shortNames: (u"loc2", ),
                    fieldName.recordType: CalRecordType.location,
                }),
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"resource1",
                    fieldName.shortNames: (u"res1", ),
                    fieldName.recordType: CalRecordType.resource,
                }),
        )
        yield self.sourceService.updateRecords(records, create=True)
Ejemplo n.º 2
0
    def setUp(self):
        yield super(MigrateResourcesTest, self).setUp()
        self.store = self.storeUnderTest()

        self.sourceService = InMemoryDirectoryService(None)
        fieldName = self.sourceService.fieldName
        records = (
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"loc1",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location2",
                    fieldName.shortNames: (u"loc2",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"resource1",
                    fieldName.shortNames: (u"res1",),
                    fieldName.recordType: CalRecordType.resource,
                }
            ),
        )
        yield self.sourceService.updateRecords(records, create=True)
Ejemplo n.º 3
0
    def test_updateRecords(self):
        service = InMemoryDirectoryService(u"xyzzy")

        # Record does not exist
        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)

        records = (
            DirectoryRecord(
                service,
                {
                    service.fieldName.uid: u"foo",
                    service.fieldName.shortNames: (u"foo1", u"foo2"),
                    service.fieldName.recordType: RecordType.user,
                }
            ),
        )
        try:
            # Trying to update a record when it does not exist should fail
            yield service.updateRecords(records, create=False)
        except NoSuchRecordError:
            pass
        except:
            self.fail("Did not raise NoSuchRecordError when create=False and record does not exist")

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)

        # Create the record
        yield service.updateRecords(records, create=True)

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(record.uid, u"foo")

        records = yield service.recordsWithRecordType(RecordType.user)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"foo")

        record = yield service.recordWithShortName(RecordType.user, u"foo1")
        self.assertEquals(record.uid, u"foo")
        record = yield service.recordWithShortName(RecordType.user, u"foo2")
        self.assertEquals(record.uid, u"foo")

        records = (
            DirectoryRecord(
                service,
                {
                    service.fieldName.uid: u"foo",
                    service.fieldName.shortNames: (u"foo3", u"foo4"),
                    service.fieldName.recordType: RecordType.group,
                }
            ),
            DirectoryRecord(
                service,
                {
                    service.fieldName.uid: u"bar",
                    service.fieldName.shortNames: (u"bar1", u"bar2"),
                    service.fieldName.recordType: RecordType.user,
                }
            ),
        )

        # Update the existing record and create a new one
        yield service.updateRecords(records, create=True)

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(record.uid, u"foo")
        self.assertEquals(set(record.shortNames), set((u'foo3', u'foo4')))

        records = yield service.recordsWithRecordType(RecordType.group)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"foo")

        records = yield service.recordsWithRecordType(RecordType.user)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"bar")

        record = yield service.recordWithShortName(RecordType.group, u"foo3")
        self.assertEquals(record.uid, u"foo")
        record = yield service.recordWithShortName(RecordType.group, u"foo4")
        self.assertEquals(record.uid, u"foo")

        # Remove a record
        yield service.removeRecords((u"foo",))
        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)
Ejemplo n.º 4
0
    def test_updateRecords(self):
        service = InMemoryDirectoryService(u"xyzzy")

        # Record does not exist
        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)

        records = (DirectoryRecord(
            service, {
                service.fieldName.uid: u"foo",
                service.fieldName.shortNames: (u"foo1", u"foo2"),
                service.fieldName.recordType: RecordType.user,
            }), )
        try:
            # Trying to update a record when it does not exist should fail
            yield service.updateRecords(records, create=False)
        except NoSuchRecordError:
            pass
        except:
            self.fail(
                "Did not raise NoSuchRecordError when create=False and record does not exist"
            )

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)

        # Create the record
        yield service.updateRecords(records, create=True)

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(record.uid, u"foo")

        records = yield service.recordsWithRecordType(RecordType.user)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"foo")

        record = yield service.recordWithShortName(RecordType.user, u"foo1")
        self.assertEquals(record.uid, u"foo")
        record = yield service.recordWithShortName(RecordType.user, u"foo2")
        self.assertEquals(record.uid, u"foo")

        records = (
            DirectoryRecord(
                service, {
                    service.fieldName.uid: u"foo",
                    service.fieldName.shortNames: (u"foo3", u"foo4"),
                    service.fieldName.recordType: RecordType.group,
                }),
            DirectoryRecord(
                service, {
                    service.fieldName.uid: u"bar",
                    service.fieldName.shortNames: (u"bar1", u"bar2"),
                    service.fieldName.recordType: RecordType.user,
                }),
        )

        # Update the existing record and create a new one
        yield service.updateRecords(records, create=True)

        record = yield service.recordWithUID(u"foo")
        self.assertEquals(record.uid, u"foo")
        self.assertEquals(set(record.shortNames), set((u'foo3', u'foo4')))

        records = yield service.recordsWithRecordType(RecordType.group)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"foo")

        records = yield service.recordsWithRecordType(RecordType.user)
        self.assertEquals(len(records), 1)
        self.assertEquals(list(records)[0].uid, u"bar")

        record = yield service.recordWithShortName(RecordType.group, u"foo3")
        self.assertEquals(record.uid, u"foo")
        record = yield service.recordWithShortName(RecordType.group, u"foo4")
        self.assertEquals(record.uid, u"foo")

        # Remove a record
        yield service.removeRecords((u"foo", ))
        record = yield service.recordWithUID(u"foo")
        self.assertEquals(None, record)
Ejemplo n.º 5
0
class MigrateResourcesTest(StoreTestCase):
    @inlineCallbacks
    def setUp(self):
        yield super(MigrateResourcesTest, self).setUp()
        self.store = self.storeUnderTest()

        self.sourceService = InMemoryDirectoryService(None)
        fieldName = self.sourceService.fieldName
        records = (
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"loc1", ),
                    fieldName.recordType: CalRecordType.location,
                }),
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location2",
                    fieldName.shortNames: (u"loc2", ),
                    fieldName.recordType: CalRecordType.location,
                }),
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"resource1",
                    fieldName.shortNames: (u"res1", ),
                    fieldName.recordType: CalRecordType.resource,
                }),
        )
        yield self.sourceService.updateRecords(records, create=True)

    @inlineCallbacks
    def test_migrateResources(self):

        # Record location1 has not been migrated
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record, None)

        # Migrate location1, location2, and resource1
        yield migrateResources(self.sourceService, self.directory)
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record.uid, u"location1")
        self.assertEquals(record.shortNames[0], u"loc1")
        record = yield self.directory.recordWithUID(u"location2")
        self.assertEquals(record.uid, u"location2")
        self.assertEquals(record.shortNames[0], u"loc2")
        record = yield self.directory.recordWithUID(u"resource1")
        self.assertEquals(record.uid, u"resource1")
        self.assertEquals(record.shortNames[0], u"res1")

        # Add a new location to the sourceService, and modify an existing
        # location
        fieldName = self.sourceService.fieldName
        newRecords = (
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"newloc1", ),
                    fieldName.recordType: CalRecordType.location,
                }),
            TestRecord(
                self.sourceService, {
                    fieldName.uid: u"location3",
                    fieldName.shortNames: (u"loc3", ),
                    fieldName.recordType: CalRecordType.location,
                }),
        )
        yield self.sourceService.updateRecords(newRecords, create=True)

        yield migrateResources(self.sourceService, self.directory)

        # Ensure an existing record does not get migrated again; verified by
        # seeing if shortNames changed, which they should not:
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record.uid, u"location1")
        self.assertEquals(record.shortNames[0], u"loc1")

        # Ensure new record does get migrated
        record = yield self.directory.recordWithUID(u"location3")
        self.assertEquals(record.uid, u"location3")
        self.assertEquals(record.shortNames[0], u"loc3")
Ejemplo n.º 6
0
class MigrateResourcesTest(StoreTestCase):

    @inlineCallbacks
    def setUp(self):
        yield super(MigrateResourcesTest, self).setUp()
        self.store = self.storeUnderTest()

        self.sourceService = InMemoryDirectoryService(None)
        fieldName = self.sourceService.fieldName
        records = (
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"loc1",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location2",
                    fieldName.shortNames: (u"loc2",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"resource1",
                    fieldName.shortNames: (u"res1",),
                    fieldName.recordType: CalRecordType.resource,
                }
            ),
        )
        yield self.sourceService.updateRecords(records, create=True)


    @inlineCallbacks
    def test_migrateResources(self):

        # Record location1 has not been migrated
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record, None)

        # Migrate location1, location2, and resource1
        yield migrateResources(self.sourceService, self.directory)
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record.uid, u"location1")
        self.assertEquals(record.shortNames[0], u"loc1")
        record = yield self.directory.recordWithUID(u"location2")
        self.assertEquals(record.uid, u"location2")
        self.assertEquals(record.shortNames[0], u"loc2")
        record = yield self.directory.recordWithUID(u"resource1")
        self.assertEquals(record.uid, u"resource1")
        self.assertEquals(record.shortNames[0], u"res1")

        # Add a new location to the sourceService, and modify an existing
        # location
        fieldName = self.sourceService.fieldName
        newRecords = (
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location1",
                    fieldName.shortNames: (u"newloc1",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
            TestRecord(
                self.sourceService,
                {
                    fieldName.uid: u"location3",
                    fieldName.shortNames: (u"loc3",),
                    fieldName.recordType: CalRecordType.location,
                }
            ),
        )
        yield self.sourceService.updateRecords(newRecords, create=True)

        yield migrateResources(self.sourceService, self.directory)

        # Ensure an existing record does not get migrated again; verified by
        # seeing if shortNames changed, which they should not:
        record = yield self.directory.recordWithUID(u"location1")
        self.assertEquals(record.uid, u"location1")
        self.assertEquals(record.shortNames[0], u"loc1")

        # Ensure new record does get migrated
        record = yield self.directory.recordWithUID(u"location3")
        self.assertEquals(record.uid, u"location3")
        self.assertEquals(record.shortNames[0], u"loc3")