def test1(self):
        'simple object with just string'

        # create a simple data object type
        class Dummy:
            def __init__(self, a):
                self.a = a

        # add inventory
        from dsaw.model.Inventory import Inventory as base

        class Inventory(base):

            a = base.descriptors.str(name='a')

        Dummy.Inventory = Inventory

        # create a data object instance
        dummy = Dummy('hello')

        # convert dummy to a db record
        from dsaw.model.visitors.Object2DBRecord import Object2DBRecord
        o2r = Object2DBRecord()
        record = o2r(dummy)

        self.assertEqual(record.a, dummy.a)
        self.assertEqual(record.name, 'dummy')
        return
    def test1(self):
        'data object that is unhashable'

        # create a data object instance
        atom1 = Atom()
        atom2 = Atom()
        atoms = [atom1, atom2]
        struct = Structure(atoms)

        # convert struct to a db record
        from dsaw.model.visitors.Object2DBRecord import Object2DBRecord
        o2r = Object2DBRecord()
        record = o2r(struct)

        self.orm.save(struct)
        self.structid = self.orm(struct).id

        self.orm2.registerObjectType(Atom)
        struct2 = self.orm2.load(Structure, self.structid)
        self.assertEqual(len(struct2), 2)
        for atom in struct2:
            self.assertEqual(atom.__class__, Atom)

        self.orm.destroy(struct)
        return
    def test4(self):
        'referenceset'
        import dataobjects as do
        structure = do.Structure(do.Cylinder(r=3, h=10), [do.Atom(symbol='C')])

        # convert to a db record
        from dsaw.model.visitors.Object2DBRecord import Object2DBRecord
        o2r = Object2DBRecord()
        record = o2r(structure)

        self.assert_(o2r.registry.getRecord(structure.shape))
        return
    def test3(self):
        'object for which Inventory is created on the fly'
        import dataobjects
        Computation = dataobjects.Computation
        Job = dataobjects.Job

        # create data objects
        computation = Computation('what?')
        job = Job('a.b.c', computation)

        # convert to a db record
        from dsaw.model.visitors.Object2DBRecord import Object2DBRecord
        o2r = Object2DBRecord()
        record = o2r(job)

        self.assertEqual(job.server, record.server)
        self.assertEqual(record.name, 'job')
        print record.computation
        return
    def test2(self):
        'object with reference'

        from dsaw.model.Inventory import Inventory as InventoryBase

        # create data object types
        class Computation:
            def __init__(self, about):
                self.about = about
                return

            class Inventory(InventoryBase):

                about = InventoryBase.descriptors.str(name='about')

        class Job:
            def __init__(self, server, computation):
                self.server = server
                self.computation = computation

            class Inventory(InventoryBase):

                server = InventoryBase.descriptors.str(name='server')
                computation = InventoryBase.descriptors.reference(
                    name='computation', targettype=Computation)

        # create data objects
        computation = Computation('what?')
        job = Job('a.b.c', computation)

        # convert to a db record
        from dsaw.model.visitors.Object2DBRecord import Object2DBRecord
        o2r = Object2DBRecord()
        record = o2r(job)

        self.assertEqual(job.server, record.server)
        self.assertEqual(record.name, 'job')
        print record.computation
        return