Esempio n. 1
0
    def setUp(self):
        self.ps = Server.getService("PersistenceService")
        self.ms = Server.getService("MappingService")
        self.ms.registerMapper(Widget, InMemoryDataMapper() )

        self.rs = Server.getService("RelationService")
        Server.txn.begin()
 def setUp(self):
     self.ps = Server.getService("PersistenceService")
     self.wh = Server.getHome("widgetHome")
     # self.ms = Server.getService("MappingService")
     # self.mapper = InMemoryDataMapper()
     # self.ms.registerMapper(Widget, self.mapper )
     Server.txn.begin()
Esempio n. 3
0
 def setUp(self):
     self.ps = Server.getService("PersistenceService")
     self.ms = Server.getService("MappingService")
     self.mapper = ZODBMapper.ZODBEntityMapper()
     self.ms.registerMapper(MoneyWidget, self.mapper )
     self.currency = getCurrency('usd')
     self.money = Money(10.00, self.currency)
     Server.txn.begin()
Esempio n. 4
0
    def setUp(self):
        txnStart()
        self._pool = Server.getService("PSQLPool")
        self._conn = self._pool.getConnection()
        self._cursor = self._conn.cursor()

        self.wHome = Server.getHome("widgetHome")
        self.dHome = Server.getHome("doodleHome")

        self.d1 = self.dHome.create()
        self.w1 = self.wHome.create()

        self.w1._set_doodle(self.d1)
Esempio n. 5
0
 def testRemove(self):
     w = Server.getHome('widgetHome').create()
     Server.txn.commit(0)
     Server.txn.begin()
     w1 = self.ps.load(Widget, w._get_primaryKey())
     self.ps.remove(w)
     Server.txn.commit(0)
     Server.txn.begin()
     self.assertRaises(KeyError, self.ps.load, Widget, w._get_primaryKey())
Esempio n. 6
0
    def testCreateEntity(self):
        wHome = Server.getHome("widgetHome")
        widget = wHome.create()
        pKey = widget._get_primaryKey()
        Server.txn.commit(0)
        
        txnStart()

        pool = Server.getService("PSQLPool")
        conn = pool.getConnection()
        cursor = conn.cursor()
        cursor.execute("SELECT primaryKey, wedgie FROM Widget WHERE primaryKey='%s'" % pKey)

        assert cursor.rowcount == 1, "Should have found 1 record matching widget.  Found: %s" % cursor.rowcount

        data = cursor.fetchone()
        assert data[0] == pKey
        assert data[1] == 0
Esempio n. 7
0
 def testUpdate(self):
     w = Server.getHome('widgetHome').create()
     Server.txn.commit(0)
     Server.txn.begin()
     w1 = self.ps.load(Widget, w._get_primaryKey())
     assert w1._get_wedgie() == 0
     w1._set_wedgie(1)
     Server.txn.commit(0)
     Server.txn.begin()
     w2 = self.ps.load(Widget, w._get_primaryKey())
     assert w2._get_wedgie() == 1
Esempio n. 8
0
 def testSet(self):
     w = Server.getHome('moneyWidgetHome').create(self.money)
     Server.txn.commit(0)
     Server.txn.begin()
     w1 = self.ps.load(MoneyWidget, w._get_primaryKey())
     assert w1._get_money().getAmount() == 10.0
     money = Money(5.00, self.currency)
     w1._set_money(money)
     Server.txn.commit(0)
     Server.txn.begin()
     w2 = self.ps.load(MoneyWidget, w._get_primaryKey())
     assert w2._get_money().getAmount() == 5.0
Esempio n. 9
0
    def testLoadEntity(self):
        wHome = Server.getHome("widgetHome")
        widget = wHome.create()
        widget._set_wedgie(1)
        pKey = widget._get_primaryKey()
        Server.txn.commit(0)
        
        txnStart()
        widget = wHome.findByPrimaryKey(pKey)

        assert widget._get_primaryKey() == pKey
        assert widget._get_wedgie() == 1
Esempio n. 10
0
    def testRelateThree(self):

        """Create three objects, relate them, then see if the relation
        service returns the right values."""
        
        w1 = Server.getHome('widgetHome').create()
        w2 = Server.getHome('widgetHome').create()
        w3 = Server.getHome('widgetHome').create()
        w4 = Server.getHome('widgetHome').create()

        self.rs.relate(w1, w2, "many_test")
        self.rs.relate(w1, w3, "many_test")
        self.rs.relate(w1, w4, "many_test")

        relatives = self.rs.findPointingFrom(w1, "many_test")
        assert len(relatives) == 3, "Should have 3 relatives, found %s" % len(relatives)
        
        Server.txn.commit(0)
        Server.txn.begin()

        relatives = self.rs.findPointingFrom(w1, "many_test")
        assert len(relatives) == 3, "Should have 3 relatives, found %s" % len(relatives)
Esempio n. 11
0
    def testKey(self):
        kgs = Server.getService("KeyGenService")
        kg = kgs.getKeyGenerator('')
        key = kg.nextKey()
        key2 = kg.nextKey()

        assert (int(key.split('-')[1]) +1) == (int(key2.split('-')[1]))

        Server.txn.commit(0)
        txnStart()
        
        key = kg.currentKey()
        assert key == key2
Esempio n. 12
0
    def testRelate(self):

        """Create two objects relate them, then see if the relation
        service returns the right values."""


        w1 = Server.getHome('widgetHome').create()
        w2 = Server.getHome('widgetHome').create()

        self.rs.relate(w1, w2, "relation")

        assert self.rs.isPointingTo(w1, w2, "relation")
                
        Server.txn.commit(0)
        Server.txn.begin()

        assert self.rs.isPointingTo(w1, w2, "relation")

        # Check primary keys, cause technically we shouldn't be
        # holding onto w1 and w2 after the commit.

        assert self.rs.findPointingFrom(w1, "relation")[0]._get_primaryKey() == w2._get_primaryKey()
        assert self.rs.findPointingTo(w2, "relation")[0]._get_primaryKey() == w1._get_primaryKey()
Esempio n. 13
0
    def testRemoveEntity(self):

        """Verifies that deleting an entity removes all the relations
        the entity was involved in."""

        w1 = Server.getHome('widgetHome').create()
        w2 = Server.getHome('widgetHome').create()
        
        self.rs.relate(w1, w2, "relation")
        assert self.rs.isPointingTo(w1, w2, "relation")
        
        Server.txn.commit(0)
        Server.txn.begin()

        w2 = Server.getHome('widgetHome').findByPrimaryKey(w2._get_primaryKey())
        assert self.rs.isPointingTo(w1, w2, "relation")
        
        Server.getHome('widgetHome').remove(w2)

        Server.txn.commit(0)
        Server.txn.begin()

        
        assert not self.rs.isPointingTo(w1, w2, "relation")
Esempio n. 14
0
    def testOneToManyRelation(self):

        wHome = Server.getHome("widgetHome")
        parent = wHome.create()
        child1 = wHome.create()
        child2 = wHome.create()


        
        parentKey = parent._get_primaryKey()
        childKey1 = child1._get_primaryKey()
        childKey2 = child2._get_primaryKey()

        print parentKey, childKey1, childKey2

        parent._set_wedgie(1)

        child1._set_parent(parent)
        child2._set_parent(parent)
        
        Server.txn.commit(0)
        txnStart()

        parent = wHome.findByPrimaryKey(parentKey)

        children = parent._get_children()
        assert len(children) == 2, "Should have 2 children.  Has %s" % len(children)

        for child in children:
            assert child._get_primaryKey() in [childKey1, childKey2]

        Server.txn.commit(0)
        txnStart()

        removed = wHome.findByPrimaryKey(childKey2)
        wHome.remove(removed)

        Server.txn.commit(0)
        txnStart()

        parent = wHome.findByPrimaryKey(parentKey)

        children = parent._get_children()
        assert len(children) == 1, "Should have 1 child.  Has %s" % len(children)

        assert children[0]._get_primaryKey() == childKey1
Esempio n. 15
0
    def testOneToOneRelation(self):
        wHome = Server.getHome("widgetHome")
        widget1 = wHome.create()
        widget2 = wHome.create()

        widgetKey1 = widget1.primaryKey
        widgetKey2 = widget2.primaryKey

        widget1._set_other1(widget2)

        Server.txn.commit(0)
        txnStart()

        widget1 = wHome.findByPrimaryKey(widgetKey1)
        widget2 = wHome.findByPrimaryKey(widgetKey2)

        assert widget1._get_other1().primaryKey == widgetKey2
        assert widget2._get_other2().primaryKey == widgetKey1        
Esempio n. 16
0
    def testRemoveEntity(self):

        wHome = Server.getHome("widgetHome")
        widget = wHome.create()
        pKey = widget._get_primaryKey()
        Server.txn.commit(0)

        txnStart()
        widget = wHome.findByPrimaryKey(pKey)
        wHome.remove(widget)
        
        Server.txn.commit(0)

        txnStart()
        try:
            wHome.findByPrimaryKey(pKey)
            raise AssertionError("Widget not deleted.")
        except FinderException:
            pass
Esempio n. 17
0
    def testTwoRelatesOneTransaction(self):
        """testTwoRelatesOneTransaction
        Assures that if you relate an object to two different objects over
        the course of a transaction that everything behaves properly as we
        have/had a problem with things freaking out.  The relations should
        all exist before the transaction starts.
        """
        wHome = Server.getHome('widgetHome')

        user1 = wHome.create()
        user2 = wHome.create()
        lead1 = wHome.create()
        lead2 = wHome.create()

        u1pk = user1._get_primaryKey()
        u2pk = user2._get_primaryKey()

        rs = self.rs

        rs.relate(user1, lead1, 'many_test')
        rs.relate(user2, lead2, 'many_test')

        Server.txn.commit(0)
        Server.txn.begin()
        
        lead3 = wHome.create()
        user1 = wHome.findByPrimaryKey(u1pk)
        user2 = wHome.findByPrimaryKey(u2pk)

        rs.relate(user1, lead3, 'many_test')
        #rs.relate(user2, lead3, 'many_test')

        try:
            Server.txn.commit(0) # This is usually the problem line
            Server.txn.begin()
        except:
            Server.txn.suspend()
            Server.txn.begin()
            assert 0, "Caught error during commit."

        assert 1
 def setUp(self):
     self.ds = Server.getService("TXNDescriptionService")
 def setUp(self):
     self.eds = Server.getService("EntityDescriptionService")
     self.rr = Server.getService("RelationRegistryService")
     self.qs = PostgresQueryService
     txnStart()
Esempio n. 20
0
import unittest, os

import logging
logging.basicConfig()
#logging.getLogger("EventChannel").setLevel(logging.DEBUG)
#logging.getLogger("Rambler").setLevel(logging.DEBUG)
#logging.getLogger("ZODBPool").setLevel(logging.DEBUG)

# Sucks that we need to do this.
from omniORB import importIDL
importIDL('Widget.idl', ['-I../idl'])

from Rambler import Server
Server.init("giop:tcp::6666")


# Sigh, all these import's have to be done in the proper order
from Rambler import ZODBPool, ZODBMapper
from ZODB import FileStorage, Persistent, DB
from tempfile import mktemp

tempdir = '/tmp' # Just for now

filename = mktemp()
storage = FileStorage.FileStorage(filename)
db = DB(storage, cache_size=1000)
Server.registerService(ZODBPool.ZODBConnectionPool(db, 6), "ZODBPool")

from Widget import Widget, WidgetHome
Server.loadConfig(Widget, 'Widget.cfg')
Server.registerEntity(WidgetHome, Widget)
Esempio n. 21
0
 def setUp(self):
     self.ps = Server.getService("PersistenceService")
     self.ms = Server.getService("MappingService")
     self.mapper = ZODBMapper.ZODBEntityMapper()
     self.ms.registerMapper(Widget, self.mapper )
     Server.txn.begin()
Esempio n. 22
0
 def testCreate(self):
     # Just test to make sure we don't get any errors.
     w = Server.getHome('widgetHome').create()
     Server.txn.commit(0)
     Server.txn.begin()
Esempio n. 23
0
    def testRelationConflict(self):
        """Test 2 users trying to modify the same relation"""
        wHome = Server.getHome('widgetHome')

        w1a = wHome.create()
        w1b = wHome.create()
        w1c = wHome.create()
        w2 = wHome.create()

        # Keys for loading it later
        w1aKey = w1a._get_primaryKey()
        w1bKey = w1b._get_primaryKey()
        w1cKey = w1c._get_primaryKey()
        w2Key = w2._get_primaryKey()

        # w2 is assocated with w1a.  2 transactions each try to
        # move ti, one to w1b and one to w1c.  At the end, the last
        # committed transaction should win with no invalid references
        # laying around.
        self.rs.relate(w1a, w2, 'many_test')
        Server.txn.commit(0)

        # Load the objects in each transaction
        Server.txn.begin()
        w1b = wHome.findByPrimaryKey(w1bKey)
        w2a = wHome.findByPrimaryKey(w2Key)
        context1 = Server.txn.suspend()

        Server.txn.begin()
        w1c = wHome.findByPrimaryKey(w1cKey)
        w2b = wHome.findByPrimaryKey(w2Key)
        context2 = Server.txn.suspend()

        Server.txn.resume(context1)
        self.rs.relate(w1b, w2a, 'many_test')
        context1 = Server.txn.suspend()

        Server.txn.resume(context2)
        self.rs.relate(w1c, w2b, 'many_test')
        context2 = Server.txn.suspend()

        Server.txn.resume(context1)
        Server.txn.commit(0)

        Server.txn.resume(context2)
        Server.txn.commit(0)

        Server.txn.begin()
        # Reload all the objects for this transaction
        w1a = wHome.findByPrimaryKey(w1aKey)
        w1b = wHome.findByPrimaryKey(w1bKey)
        w1c = wHome.findByPrimaryKey(w1cKey)
        w2 = wHome.findByPrimaryKey(w2Key)
        
        # Validate the final object
        relatives = self.rs.findPointingFrom(w1c, 'many_test')
        assert len(relatives) == 1, "Should have 1 relative, found %s" % len(relatives)
        assert relatives[0]._get_primaryKey() == w2._get_primaryKey()

        # Validate the object we moved
        relatives = self.rs.findPointingTo(w2, 'many_test')
        assert len(relatives) == 1, "Should have 1 relative, found %s" % len(relatives)
        assert relatives[0]._get_primaryKey() == w1c._get_primaryKey()

        # Assure both the other objects have no relations
        relatives = self.rs.findPointingFrom(w1a, 'many_test')
        assert len(relatives) == 0, "Should have 0 relatives, found %s" % len(relatives)
        relatives = self.rs.findPointingFrom(w1b, 'many_test')
        assert len(relatives) == 0, "Should have 0 relatives, found %s" % len(relatives)
 def setUp(self):
     self.ds = Server.getService("EntityDescriptionService")
Esempio n. 25
0
import unittest, os

import logging
logging.basicConfig()
#logging.getLogger("EventChannel").setLevel(logging.DEBUG)
#logging.getLogger("Rambler").setLevel(logging.DEBUG)
#logging.getLogger("ZODBPool").setLevel(logging.DEBUG)

# Sucks that we need to do this.
from omniORB import importIDL
importIDL('Widget.idl', ['-I../idl'])

from Rambler import Server
Server.init("giop:tcp::6666")

from Rambler.PersistenceService import InMemoryDataMapper
# Sigh, all these import's have to be done in the proper order
##from Rambler import ZODBPool, ZODBMapper
##from ZODB import FileStorage, Persistent, DB
##from tempfile import mktemp

##tempdir = '/tmp' # Just for now

##filename = mktemp()
##storage = FileStorage.FileStorage(filename)
##db = DB(storage, cache_size=1000)
##Server.registerService(ZODBPool.ZODBConnectionPool(db, 6), "ZODBPool")

from Rambler.ciRelationService import ciRelationService
RS = Server.registerService(ciRelationService, "RelationService")
Server.loadDescriptor('widget.xml')
import unittest

from omniORB import importIDL
importIDL('Widget.idl', ['-I../idl'])

from Rambler import Server
Server.init("giop:tcp::6666")
Server.loadDescriptor('widget.xml')

from Rambler.tests.Widget import Widget

class Test(unittest.TestCase):
    def setUp(self):
        self.ds = Server.getService("EntityDescriptionService")

    def testGetFields(self):
        fields = self.ds.getFields("Widget")

        cmrFields = []
        cmpFields = []
        for field in fields:
            if not field.isRelation():
                cmpFields.append(field)
            else:
                cmrFields.append(field)
        
        assert (len(cmpFields) == 3), "Widget should have 3 CMP fields.  Has %s" % len(cmpFields)
        assert (len(cmrFields) == 5), "Widget should have 5 CMR fields.  Has %s" % len(cmrFields)

        for field in cmpFields:
            assert field.getName() in ['primaryKey', 'wedgie', 'name'], "Invalid field name: %s" % field.getName()
Esempio n. 27
0
 def testLoad(self):
     w = Server.getHome('widgetHome').create()
     Server.txn.commit(0)
     Server.txn.begin()
     w1 = self.ps.load(Widget, w._get_primaryKey())
     assert w1._get_primaryKey() == w._get_primaryKey()
Esempio n. 28
0
from omniORB import importIDL

importIDL("Widget.idl", ["-I../idl"])
# importIDL('../idl/epo.idl', ['-I../idl'])

import logging

logging.basicConfig()
# logging.getLogger("EventChannel").setLevel(logging.DEBUG)
# logging.getLogger("Rambler").setLevel(logging.DEBUG)
# logging.getLogger("ZODBPool").setLevel(logging.DEBUG)


from Rambler import Server

Server.init("giop:tcp::6666")

# from Rambler.PersistenceService import PersistenceService, InMemoryDataMapper
from Rambler.PSQLPool import PSQLPool

Server.registerService(PSQLPool("host=dev2", 20), "PSQLPool")

Server.loadDescriptor("widget.xml")

import Rambler.PostgresMappers

tid = Server.txn.get_transaction_name()
Server.getService("EventService").publishEvent("Initializing", Server, tid)


# from tempfile import mktemp
Esempio n. 29
0
 def _get_home():
     return Server.getHome("widgetHome")
Esempio n. 30
0
 def _get_home():
     return Server.getHome("doodleHome")