#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
Tests that 'CooperatingObjectStoreNeededNotification' is correctly handled,
meaning that ...
CVS information
$Id: test_CooperatingObjectStoreNeededNotification.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
import unittest
if __name__ == "__main__":
import utils, sys
utils.fixpath()
from Modeling.ObjectStoreCoordinator import \
defaultCoordinator, ObjectStoreCoordinator, \
CooperatingObjectStoreNeededNotification
from Modeling import ModelSet
from Modeling.FetchSpecification import FetchSpecification
from NotificationFramework import NotificationCenter
NC=NotificationCenter
import Modeling.tests.testPackages.AuthorBooks
class TestCooperatingObjectStoreNeededNotification(unittest.TestCase):
"Tests basic functionalities of EditingContext"
def test_01_initialState(self):
"[Coop.Obj.StoreNotification] Tests the initial state"
objStoreCoordinator=defaultCoordinator()
fetchSpec=FetchSpecification(entityName='Book')
dbContext=objStoreCoordinator.objectStoreForFetchSpecification(fetchSpec)
## TBD ...
# DBContext <<-> Database configuration
database=dbContext.database()
self.failUnless(database, "Database object should exist")
model=ModelSet.defaultModelSet().modelNamed('AuthorBooks')
self.failUnless(model in database.models(),
'Model should be loaded within Database')
self.failUnless(dbContext in database.registeredContexts())
# DBContext <<-> ObjectStoreCoordinator configuration
self.failUnless(dbContext.delegate()==None,
"DatabaseContext has no delegate by default")
self.failUnless(dbContext.coordinator()==objStoreCoordinator)
self.failUnless(dbContext in objStoreCoordinator.cooperatingObjectStores())
# adaptor __TBD
from PostgresqlAdaptorLayer import PostgresqlAdaptor
self.failUnless(database.adaptor().__class__==PostgresqlAdaptor)
def test_02_defaultDelegate(self):
"[DatabaseContext] "
from Modeling import DatabaseContext
self.failUnless(DatabaseContext.defaultDelegate()==None)
self.assertRaises('Unimplemented', DatabaseContext.setDefaultDelegate, 0)
def test_02_shareDBContext(self):
"[ObjectStoreCoordinator] "
pass
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCooperatingObjectStoreNeededNotification, "test_"))
return suite
if __name__ == "__main__":
errs = utils.run_suite(test_suite())
sys.exit(errs and 1 or 0)
|