def testTask(self):
        """ Simple test for creating instances of tasks """
        def _verifyTask(taskItem):
            self.failUnless(has_stamp(taskItem, TaskStamp))
            self.failUnlessEqual(taskItem.displayName, uw("test headline"))
            self.failUnlessEqual(taskItem.importance, 'important')

        self.loadParcel("osaf.pim.tasks")

        # Check that the globals got created by the parcel
        view = self.view
        taskPath = Path('//parcels/osaf/pim/tasks')
        self.failIfEqual(schema.itemFor(TaskStamp, view), None)
        self.failIfEqual(view.find(Path(taskPath, 'TaskStamp')), None)

        self.failUnlessEqual(schema.itemFor(TaskStamp, view),
                             view.find(Path(taskPath, 'TaskStamp')))

        # Construct A Sample Item
        task = Task("TestTask", itsView=view)
        task.itsItem.displayName = uw("test headline")
        task.itsItem.importance = "important"

        self._reopenRepository()
        view = self.view

        contentItemParent = view.findPath("//userdata")

        taskItem2 = contentItemParent.getItemChild("TestTask")
        _verifyTask(taskItem2)
Example #2
0
    def _makeValidValues(self):
        """ create valid values of appropriate types"""

        class myStruct(object):
            __slots__ = ('name', 'rank')
            
        view = self.view
        self.uuid = self.attrKind.itsUUID
        self.uuidString = str(self.uuid)
        self.pathString = '//Schema/Core/Item'
        self.path = Path(self.pathString)
        self.itemRef = ItemRef(self.uuid, view)
        self.itemClass = eval('chandlerdb.item.Item.Item')
        self.dateTimeString = '2004-01-08 12:34:56 US/Mountain'
        self.dateTime = datetime(2004, 1, 8, 12, 34, 56,
                                 tzinfo=view.tzinfo.getInstance('US/Mountain'))
        self.timeDeltaString= '-8+45.000012'
        self.timeDelta = timedelta(-8, 45, 12)
        
        self.enum = self.types['Enumeration'].newItem('myEnum', view)
        self.enum.values = ['red', 'green', 'blue']

        self.structType = self.types['Struct'].newItem('myStruct', view)
        self.structType.fields=['name','rank']
        self.structType.implementationTypes = {'python': myStruct }
        self.struct = myStruct()

        self.lob = self.types['Lob'].makeValue("aba;dsjfa;jfdl;ajru87z.vncxyt89q47654", encoding='utf-8', mimetype='text/plain')
Example #3
0
    def packStart(self, attrs):

        if attrs.has_key('cwd'):
            cwd = attrs['cwd']
            if isinstance(cwd, unicode):
                cwd = cwd.encode(self.fsenc)

            self.cwd[-1] = os.path.join(self.cwd[-1], cwd)

        if attrs.has_key('file'):
            if not self.view.find(Path('//', 'Packs', attrs['name'])):
                try:
                    file = attrs['file']
                    if isinstance(file, unicode):
                        file = file.encode(self.fsenc)

                    self.view.loadPack(os.path.join(self.cwd[-1], file),
                                       self.parent[-1], self.package)
                except:
                    self.saveException()
                    return

        else:
            self.name = attrs['name']
            self.pack = Item(self.name, self.packs, None)
            self.hooks.append([])
    def getTypeName(self, attribute, attrs, default):

        name = None

        if attrs.has_key('typeid'):
            try:
                name = self.view[UUID(attrs['typeid'])].handlerName()
            except KeyError:
                raise TypeError, "Type %s not found" % (attrs['typeid'])

        elif attrs.has_key('typepath'):
            typeItem = self.view.find(Path(attrs['typepath']))
            if typeItem is None:
                raise TypeError, "Type %s not found" % (attrs['typepath'])
            name = typeItem.handlerName()

        elif attrs.has_key('type'):
            name = attrs['type']

        elif attribute is not None:
            attrType = attribute.getAspect('type', None)
            if attrType is not None:
                name = attrType.handlerName()

        return name or default
    def kindEnd(self, itemHandler, attrs):

        if attrs['type'] == 'uuid':
            self.kindRef = UUID(self.data)
        else:
            self.kindRef = Path(self.data)

        self.kind = self.view._findSchema(self.kindRef, self.withSchema)
    def setUp(self):

        super(TestIndexes, self).setUp()

        view = self.view
        self.loadCineguide(view, False)
        self.kh = Path('//CineGuide/KHepburn')
        view.find(self.kh).movies.addIndex('n', 'numeric')
        view.commit()
    def testWalk(self):
        def callme(self, path, x):
            print path
            print x.itsName

        view = self.view
        view.walk(Path('//Schema/Core/Parcel'), callme)
        #TODO what's a resonable test here?
        pass
    def parentEnd(self, itemHandler, attrs):

        if attrs['type'] == 'uuid':
            self.parentRef = UUID(self.data)
        else:
            self.parentRef = Path(self.data)

        self.isContainer = attrs.get('container', 'False') == 'True'
        self.parent = self.view.find(self.parentRef)

        if self.parent is None:
            self.afterLoadHooks.append(self._move)
Example #9
0
    def itemStart(self, attrs):

        parent = None

        if attrs.get('afterLoadHooks', 'False') == 'True':
            self.hooks.append([])

        if attrs.has_key('path'):
            parent = self.view.find(Path(attrs['path']))
        elif attrs.has_key('uuid'):
            parent = self.view.find(UUID(attrs['uuid']))
        elif attrs.has_key('file'):
            file = attrs['file']
            if isinstance(file, unicode):
                file = file.encode(self.fsenc)

            parent = self.loadItem(os.path.join(self.cwd[-1], file),
                                   self.parent[-1])

        elif attrs.has_key('files'):
            files = attrs['files']
            if isinstance(files, unicode):
                files = files.encode(self.fsenc)

            pattern = '^' + files + '$'
            pattern = pattern.replace('.', '\\.').replace('*', '.*')
            exp = re.compile(pattern)

            if self.package is not None:
                if os.path.sep != '/':
                    path = self.cwd[-1].replace(os.path.sep, '/')
                else:
                    path = self.cwd[-1]
                files = resource_listdir(self.package, path)
            else:
                files = os.listdir(self.cwd[-1])

            for file in files:
                if exp.match(file):
                    parent = self.loadItem(os.path.join(self.cwd[-1], file),
                                           self.parent[-1])
                    if self.errorOccurred():
                        return

        self.parent.append(parent)

        if attrs.has_key('cwd'):
            cwd = attrs['cwd']
            if isinstance(cwd, unicode):
                cwd = cwd.encode(self.fsenc)

            self.cwd.append(os.path.join(self.cwd[-1], cwd))
    def setUp(self):

        super(TestAfterChange, self).setUp()

        view = self.view
        self.loadCineguide(view, False)
        self.kh = Path('//CineGuide/KHepburn')
        movies = view.find(self.kh).movies
        movies.addIndex('n', 'numeric')
        movies.first().itsKind.getAttribute('title').afterChange = [
            'titleChanged'
        ]
        view.commit()
    def testContacts(self):
        """ Simple test for creating instances of contact related kinds """

        self.loadParcel("osaf.pim.contacts")
        def _verifyContactName(name):
            self.assertEqual(name.firstName, uw('Sylvia'))
            self.assertEqual(name.lastName, uw('Plath'))

        # Test the globals
        contactsPath = Path('//parcels/osaf/pim/contacts')
        view = self.view

        self.assertEqual(Contact.getKind(view),
                         view.find(Path(contactsPath, 'Contact')))
        self.assertEqual(ContactName.getKind(view),
                         view.find(Path(contactsPath, 'ContactName')))

        # Construct sample items
        contactItem = Contact("contactItem", itsView=view)
        contactNameItem = ContactName("contactNameItem", itsView=view)

        # Double check kinds
        self.assertEqual(contactItem.itsKind, Contact.getKind(view))
        self.assertEqual(contactNameItem.itsKind, ContactName.getKind(view))

        # Literal properties
        contactNameItem.firstName = uw("Sylvia")
        contactNameItem.lastName = uw("Plath")

        _verifyContactName(contactNameItem)

        self._reopenRepository()
        view = self.view

        contentItemParent = view.findPath("//userdata")

        contactNameItem = contentItemParent.getItemChild("contactNameItem")
        _verifyContactName(contactNameItem)
    def refEnd(self, itemHandler, attrs):

        if self.tags[-1] == 'item':
            attribute = self.attributes.pop()
            cardinality = self.getCardinality(attribute, attrs)
            otherCard = attrs.get('otherCard', None)

        else:
            cardinality = 'single'
            otherCard = self.tagAttrs[-1].get('otherCard', None)

        if cardinality == 'single':  # cardinality of tag
            typeName = attrs.get('type', 'path')

            if typeName == 'path':
                ref = Path(self.data)
            elif typeName == 'none':
                self.references[attrs['name']] = None
                return
            else:
                ref = UUID(self.data)

            if self.collections:
                refList = self.collections[-1]
                self.refs.append(
                    RefArgs(refList._name,
                            None,
                            refList._otherName,
                            ref,
                            otherCard=otherCard,
                            otherAlias=attrs.get('otherAlias'),
                            previous=self.refName(attrs, 'previous'),
                            next=self.refName(attrs, 'next'),
                            alias=attrs.get('alias')))
            else:
                name = attrs['name']
                otherName = self.getOtherName(name, self.getAttribute(name),
                                              attrs)
                self.refs.append(
                    RefArgs(name,
                            None,
                            otherName,
                            ref,
                            otherCard=otherCard,
                            otherAlias=attrs.get('otherAlias')))
        else:
            value = self.collections.pop()
            self.references[attrs['name']] = value
            if value._indexes:
                self.afterLoadHooks.append(value._restoreIndexes)
        def _find(spec):

            typeAttr = attrs.get('type', 'path')
            if typeAttr == 'path':
                item = self.parent.find(Path(spec))
            elif typeAttr == 'uuid':
                item = self.parent.find(UUID(spec))
            else:
                raise TypeError, typeAttr

            if item is None:
                raise NoSuchItemError, (spec, self.version)

            return item
    def testNotes(self):
        """ Simple test for creating instances of note related kinds """

        self.loadParcel("osaf.pim")

        def _verifyNote(note):
            self.assertEqual(note.displayName, uw("sample note"))

            self.assertEqual(note.body, uw("more elaborate sample note body"))

        # Test the globals
        notesPath = Path('//parcels/osaf/pim')
        view = self.view

        self.assertEqual(pim.Note.getKind(view),
                         view.find(Path(notesPath, 'Note')))

        # Construct sample items
        noteItem = pim.Note("noteItem", itsView=view)

        # Double check kinds
        self.assertEqual(noteItem.itsKind, pim.Note.getKind(view))

        # Literal properties
        noteItem.displayName = uw("sample note")

        noteItem.body = uw("more elaborate sample note body")

        _verifyNote(noteItem)

        self._reopenRepository()
        view = self.view
        contentItemParent = view.findPath("//userdata")

        noteItem = contentItemParent.getItemChild("noteItem")

        _verifyNote(noteItem)
Example #15
0
    def testLocations(self):
        """ Simple test for the Locations Factory - getLocation """

        self.loadParcel("osaf.pim.calendar")

        # Test the globals
        locationsPath = Path('//parcels/osaf/pim/calendar')
        view = self.view

        self.assertEqual(Calendar.Location.getKind(view),
                         view.find(Path(locationsPath, 'Location')))

        locationNames = [uw("Alderon"), uw("Atlantis"), uw("Arcadia")]

        # Construct sample items
        for loc in locationNames:
            # use the factory to create or lookup an item
            aRoom = Calendar.Location.getLocation(view, loc)
            # test that convert to string yeilds the name of the location
            self.assertEqual(loc, unicode(aRoom))

        # call the factory on the last name again, to ensure reuse
        sameLocation = Calendar.Location.getLocation(view, locationNames[-1])
        self.assert_(aRoom is sameLocation,
                     "Location factory failed to return the same location!")

        # Double check kinds
        self.assertEqual(aRoom.itsKind, Calendar.Location.getKind(view))

        # Literal properties
        aRoom.displayName = uw("A Nice Place")  # change the Location name
        # make sure we can get the name, and find it by that name
        sameLocation = Calendar.Location.getLocation(view, aRoom.displayName)
        self.assert_(
            aRoom is sameLocation,
            "Location factory failed to return an identical location!")
    def testCalendar(self):
        """ Simple test for creating instances of calendar related kinds """
        def getEventValue(event, attrName):
            try:
                attrName = getattr(type(event), attrName).name
            except AttributeError:
                pass
            return getattr(event.itsItem, attrName)

        def _verifyCalendarEvent(event):
            self.failUnless(stamping.has_stamp(event, Calendar.EventStamp))

            self.assertEqual(event.summary, uw("simple headline"))

            self.assertEqual(event.itsItem.importance, 'fyi')
            self.assertEqual(getEventValue(event, 'importance'), 'fyi')

            self.assertEqual(event.transparency, "confirmed")
            self.assertEqual(getEventValue(event, 'transparency'), "confirmed")

            self.assertEqual(event.allDay, False)
            self.assertEqual(getEventValue(event, 'allDay'), False)

            self.assertEqual(event.anyTime, True)
            self.assertEqual(getEventValue(event, 'anyTime'), True)

        def _verifyCalendarItems(location, recurrence):
            self.assertEqual(location.displayName, uw("simple location"))

        # Check that the globals got created by the parcel
        calendarPath = Path('//parcels/osaf/pim/calendar')
        view = self.sandbox.itsView

        self.assertEqual(schema.itemFor(Calendar.EventStamp, view),
                         view.find(Path(calendarPath, 'EventStamp')))
        self.assertEqual(Calendar.Location.getKind(view),
                         view.find(Path(calendarPath, 'Location')))
        self.assertEqual(Calendar.RecurrencePattern.getKind(view),
                         view.find(Path(calendarPath, 'RecurrencePattern')))

        # Construct a sample item
        calendarEventItem = Calendar.CalendarEvent("calendarEventItem",
                                                   itsParent=self.sandbox)
        locationItem = Calendar.Location("locationItem",
                                         itsParent=self.sandbox)
        recurrenceItem = Calendar.RecurrencePattern("recurrenceItem",
                                                    itsParent=self.sandbox)

        # CalendarEvent properties
        calendarEventItem.summary = uw("simple headline")
        calendarEventItem.itsItem.importance = "fyi"
        _verifyCalendarEvent(calendarEventItem)
        calendarEventItem.location = locationItem

        # Calendar properties
        locationItem.displayName = uw("simple location")
        _verifyCalendarItems(locationItem, recurrenceItem)

        # Check cloud membership - event + location
        items = calendarEventItem.itsItem.getItemCloud('copying')
        self.assertEqual(len(items), 2)

        # Re-examine items
        self.reopenRepository()
        view = self.sandbox.itsView

        calendarEventItem = Calendar.EventStamp(
            self.sandbox.getItemChild("calendarEventItem"))
        locationItem = self.sandbox.getItemChild("locationItem")
        recurrenceItem = self.sandbox.getItemChild("recurrenceItem")

        _verifyCalendarEvent(calendarEventItem)
        _verifyCalendarItems(locationItem, recurrenceItem)
class RepositoryTestCase(TestCase):

    logLevel = logging.WARNING  # a nice quiet default

    def _openRepository(self, ramdb=True):

        self.rep = DBRepository(os.path.join(self.testdir, '__repository__'))

        self.rep.create(ramdb=self.ramdb, refcounted=True)
        self.rep.logger.setLevel(self.logLevel)

        self.view = view = self.rep.createView("Test")
        view.commit()

    def setUp(self, ramdb=True, testdir='tests'):

        self.ramdb = ramdb
        self.testdir = testdir
        self._openRepository(ramdb)

    def tearDown(self):
        self.rep.close()
        self.rep.logger.debug('RAMDB = %s', self.ramdb)
        if not self.ramdb:
            self.rep.delete()

    def _reopenRepository(self):
        view = self.view
        view.commit()

        if self.ramdb:
            view.closeView()
            view.openView()
        else:
            dbHome = self.rep.dbHome
            self.rep.close()
            self.rep = DBRepository(dbHome)
            self.rep.open()
            self.view = view = self.rep.createView("Test")

    def loadCineguide(self, view, commit=True):

        view.loadPack('data/packs/cineguide.pack', package='tests')
        if commit:
            view.commit()

    def loadCollections(self, view, commit=True):

        view.loadPack('data/packs/collections.pack', package='tests')
        if commit:
            view.commit()

    _KIND_KIND = Path("//Schema/Core/Kind")
    _ITEM_KIND = Path("//Schema/Core/Item")

    # Repository specific assertions
    def assertIsRoot(self, item):
        self.assert_(item in list(item.itsView.iterRoots()))

    def assertItemPathEqual(self, item, string):
        self.assertEqual(str(item.itsPath), string)

    def setLoggerLevel(self, level):
        current = self.rep.logger.level
        self.rep.logger.setLevel(level)
        return current
Example #18
0
class TestMerge(RepositoryTestCase):
    """ Test item merging """

    itemPath = Path('//Schema/Core/Item')
    kindPath = Path('//Schema/Core/Kind')
    attributePath = Path('//Schema/Core/Attribute')
    cPath = Path('//kinds/c')

    def setUp(self):

        super(TestMerge, self).setUp()

        view = self.view
        item = view.find(TestMerge.itemPath)
        kind = view.find(TestMerge.kindPath)
        attribute = view.find(TestMerge.attributePath)

        kinds = item.newItem('kinds', view)
        item.newItem('cm', view)
        item.newItem('co', view)

        p = kind.newItem('p', kinds)
        p.addValue('superKinds', item)
        c = kind.newItem('c', kinds)
        c.addValue('superKinds', item)

        ap = attribute.newItem('ap', p)
        ap.otherName = 'ac'
        ap.cardinality = 'list'
        p.addValue('attributes', ap, alias='ap')

        ac = attribute.newItem('ac', c)
        ac.otherName = 'ap'
        ac.cardinality = 'single'
        c.addValue('attributes', ac, alias='ac')

        p.newItem('p', view)

        view.commit()

    def merge(self, o, m):

        main = self.view
        pm = main['p']
        km = main.find(TestMerge.cPath)
        am = []

        oc = [c.itsName for c in pm.iterChildren()]
        view = self.rep.createView('view')

        po = view['p']
        ko = view.find(TestMerge.cPath)
        ao = []
        for i in xrange(o):
            ao.append(ko.newItem('ao_%02d' % (i), po))
        view.commit()

        for i in xrange(m):
            am.append(km.newItem('am_%02d' % (i), pm))
        main.commit()

        ic = [c.itsName for c in pm.iterChildren()]
        uc = oc[:]
        uc.extend([c.itsName for c in am])
        uc.extend([c.itsName for c in ao])
        self.assert_(ic == uc)

        c = pm._children

        for i in xrange(o - 1):
            self.assert_(c.nextKey(ao[i].itsUUID) == ao[i + 1].itsUUID)
        for i in xrange(1, o):
            self.assert_(c.previousKey(ao[i].itsUUID) == ao[i - 1].itsUUID)

        self.assert_(c.nextKey(am[m - 1].itsUUID) == ao[0].itsUUID)
        self.assert_(c.previousKey(ao[0].itsUUID) == am[m - 1].itsUUID)

        for i in xrange(m - 1):
            self.assert_(c.nextKey(am[i].itsUUID) == am[i + 1].itsUUID)
        for i in xrange(1, m):
            self.assert_(c.previousKey(am[i].itsUUID) == am[i - 1].itsUUID)

        self.assert_(c.lastKey() == ao[o - 1].itsUUID)

    def mergeRefs(self, o, m):

        main = self.view
        pm = main['p']
        cm = main['cm']
        km = main.find(TestMerge.cPath)
        am = []

        oc = [c.itsName for c in pm.ap]

        view = self.rep.createView('view')

        po = view['p']
        co = view['co']
        ko = view.find(TestMerge.cPath)
        ao = []
        for i in xrange(o):
            c = ko.newItem('ao_%02d' % (i), co)
            c.ac = po
            #po.ap.dir()
            ao.append(c)
        view.commit()

        for i in xrange(m):
            c = km.newItem('am_%02d' % (i), cm)
            c.ac = pm
            #pm.ap.dir()
            am.append(c)
        main.commit()

        ic = [c.itsName for c in pm.ap]
        uc = oc[:]
        uc.extend([c.itsName for c in am])
        uc.extend([c.itsName for c in ao])
        self.assert_(ic == uc)

        c = pm.ap

        for i in xrange(o - 1):
            self.assert_(c.nextKey(ao[i].itsUUID) == ao[i + 1].itsUUID)
        for i in xrange(1, o):
            self.assert_(c.previousKey(ao[i].itsUUID) == ao[i - 1].itsUUID)

        self.assert_(c.nextKey(am[m - 1].itsUUID) == ao[0].itsUUID)
        self.assert_(c.previousKey(ao[0].itsUUID) == am[m - 1].itsUUID)

        for i in xrange(m - 1):
            self.assert_(c.nextKey(am[i].itsUUID) == am[i + 1].itsUUID)
        for i in xrange(1, m):
            self.assert_(c.previousKey(am[i].itsUUID) == am[i - 1].itsUUID)

        self.assert_(c.lastKey() == ao[o - 1].itsUUID)

    def rename(self, o_name, m_name):

        main = self.view
        pm = main['p']
        km = main.find(TestMerge.cPath)

        cm = km.newItem('child', pm)
        main.commit()

        view = self.rep.createView('view')

        po = view['p']
        co = po['child']
        co.rename(o_name)
        view.commit()

        cm.rename(m_name)
        main.commit()

    def move(self, o_name, m_name):

        main = self.view
        pm = main['p']
        km = main.find(TestMerge.cPath)

        cm = km.newItem('child', pm)
        km.newItem(m_name, main)
        if o_name != m_name:
            km.newItem(o_name, main)

        main.commit()

        view = self.rep.createView('view')

        po = view['p']
        co = po['child']
        co.move(view[o_name])
        view.commit()

        cm.move(main[m_name])
        main.commit()

    def test1Merge1(self):
        view = self.view
        view.find(TestMerge.cPath).newItem('c0', view['p'])
        view.commit()
        self.merge(1, 1)

    def test1Merge2(self):
        view = self.view
        view.find(TestMerge.cPath).newItem('c0', view['p'])
        view.commit()
        self.merge(2, 2)

    def test1MergeN(self):
        view = self.view
        view.find(TestMerge.cPath).newItem('c0', view['p'])
        view.commit()
        self.merge(5, 8)
        self.assert_(view.check(), 'view did not check out')

    def test0Merge1(self):
        self.merge(1, 1)

    def test0Merge2(self):
        self.merge(2, 2)

    def test0MergeN(self):
        self.merge(6, 9)

    def testRenameSameSame(self):
        self.rename('foo', 'foo')

    def testRenameSameDifferent(self):
        try:
            level = self.setLoggerLevel(logging.CRITICAL)
            self.rename('foo', 'bar')
        except MergeError, e:
            self.assert_(e.getReasonCode() == MergeError.RENAME)
        else:
Example #19
0
from chandlerdb.persistence.c import Record
from chandlerdb.schema.c import CDescriptor, CAttribute, CKind
from chandlerdb.item.c import isitem, CItem, isitemref, ItemRef, ItemValue
from chandlerdb.item.ItemError import NoSuchAttributeError

from chandlerdb.item.Item import Item, MissingClass, override
from chandlerdb.item.RefCollections import RefList
from chandlerdb.item.Sets import AbstractSet
from chandlerdb.item.Values import Values, References
from chandlerdb.item.PersistentCollections import PersistentCollection
from chandlerdb.util.Path import Path
from chandlerdb.schema.TypeHandler import TypeHandler
from chandlerdb.schema.Correlation import Correlation
from chandlerdb.persistence.RepositoryError import RecursiveLoadItemError

CORE = Path('//Schema/Core')


class Kind(Item):
    def __init__(self, *args, **kw):

        super(Kind, self).__init__(*args, **kw)
        self.__init()
        self._createExtent(self.itsView)

    def __init(self):

        if self.c is None:
            self.c = CKind(self)

        self._initialValues = None
Example #20
0
    def testMail(self):
        """ Simple test for creating instances of email related kinds """

        self.loadParcel("osaf.pim.mail")

        # Test the globals
        mailPath = Path('//parcels/osaf/pim/mail')
        view = self.view

        self.assertEqual(Mail.AccountBase.getKind(view),
                         view.find(Path(mailPath, 'AccountBase')))

        self.assertEqual(Mail.IMAPAccount.getKind(view),
                         view.find(Path(mailPath, 'IMAPAccount')))

        self.assertEqual(Mail.SMTPAccount.getKind(view),
                         view.find(Path(mailPath, 'SMTPAccount')))

        self.assertEqual(schema.itemFor(Mail.MIMEBase, view),
                         view.find(Path(mailPath, 'MIMEBase')))

        self.assertEqual(schema.itemFor(Mail.MIMENote, view),
                         view.find(Path(mailPath, 'MIMENote')))

        self.assertEqual(schema.itemFor(Mail.MailStamp, view),
                         view.find(Path(mailPath, 'MailStamp')))

        self.assertEqual(schema.itemFor(Mail.MIMEBinary, view),
                         view.find(Path(mailPath, 'MIMEBinary')))

        self.assertEqual(schema.itemFor(Mail.MIMEText, view),
                         view.find(Path(mailPath, 'MIMEText')))

        self.assertEqual(schema.itemFor(Mail.MIMEContainer, view),
                         view.find(Path(mailPath, 'MIMEContainer')))

        self.assertEqual(schema.itemFor(Mail.MIMESecurity, view),
                         view.find(Path(mailPath, 'MIMESecurity')))

        self.assertEqual(Mail.EmailAddress.getKind(view),
                         view.find(Path(mailPath, 'EmailAddress')))

        # Construct sample items
        accountBaseItem = Mail.AccountBase("accountBaseItem", itsView=view)
        imapAccountItem = Mail.IMAPAccount("imapAccountItem", itsView=view)
        smtpAccountItem = Mail.SMTPAccount("smtpAccountItem", itsView=view)

        mimeBaseObject = Mail.MIMEBase("mimeBaseItem", itsView=view)
        mimeNoteObject = Mail.MIMENote("mimeNoteItem", itsView=view)
        mailMessageObject = Mail.MailMessage("mailMessageItem", itsView=view)
        mimeBinaryObject = Mail.MIMEBinary("mimeBinaryItem", itsView=view)
        mimeTextObject = Mail.MIMEText("mimeTextItem", itsView=view)
        mimeContainerObject = Mail.MIMEContainer("mimeContainerItem",
                                                 itsView=view)
        mimeSecurityObject = Mail.MIMESecurity("mimeSecurityItem",
                                               itsView=view)
        emailAddressItem = Mail.EmailAddress("emailAddressItem", itsView=view)

        # Double check kinds
        self.assertEqual(accountBaseItem.itsKind,
                         Mail.AccountBase.getKind(view))

        self.assertEqual(imapAccountItem.itsKind,
                         Mail.IMAPAccount.getKind(view))

        self.assertEqual(smtpAccountItem.itsKind,
                         Mail.SMTPAccount.getKind(view))

        self.failUnless(isinstance(mimeBaseObject, Mail.MIMEBase))
        self.failUnless(isinstance(mimeNoteObject, Mail.MIMENote))

        self.failUnless(isinstance(mailMessageObject, Mail.MailStamp))
        self.failUnless(isinstance(mailMessageObject.itsItem, Note))
        self.failUnless(has_stamp(mailMessageObject, Mail.MailStamp))

        self.failUnless(isinstance(mimeBinaryObject, Mail.MIMEBinary))

        self.failUnless(isinstance(mimeTextObject, Mail.MIMEText))

        self.failUnless(isinstance(mimeContainerObject, Mail.MIMEContainer))

        self.failUnless(isinstance(mimeSecurityObject, Mail.MIMESecurity))

        self.assertEqual(emailAddressItem.itsKind,
                         Mail.EmailAddress.getKind(view))

        accountBaseItem = self.__populateAccount(accountBaseItem)
        smtpAccountItem = self.__populateAccount(smtpAccountItem)
        imapAccountItem = self.__populateAccount(imapAccountItem)

        mimeBaseObject.mimeType = "SGML"
        mimeBinaryObject.mimeType = "APPLICATION"
        mimeTextObject.mimeType = "PLAIN"
        mimeContainerObject.mimeType = "ALTERNATIVE"
        mimeSecurityObject.mimeType = "SIGNED"

        # Literal properties
        mailMessageObject.dateSent = datetime.now(view.tzinfo.default)
        mailMessageObject.subject = uw("Hello")
        self.assertEqual(mailMessageObject.subject,
                         mailMessageObject.itsItem.displayName)
        #mailMessageObject.spamScore = 5

        # Item Properties
        emailAddressItem.emailAddress = u"*****@*****.**"
        mailMessageObject.replyToAddress = emailAddressItem

        self._reopenRepository()
        view = self.view

        contentItemParent = view.findPath("//userdata")
        mailMessageItem = contentItemParent.getItemChild("mailMessageItem")

        #Test cloud membership

        items = mailMessageItem.getItemCloud('copying')
        self.assertEqual(len(items), 3)  # item & reply-to address, mimeContent