#! /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 for EntityClassDescription
CVS information
$Id: test_EntityClassDescription.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
import unittest
if __name__ == "__main__":
import utils, sys
utils.disable_model_cache()
utils.fixpath()
from Modeling import EntityClassDescription
from Modeling.ModelSet import defaultModelSet
from StoreEmployees.Employee import Employee
class TestEntityClassDescription(unittest.TestCase):
"Tests EntityClassDescription"
def test_01_classForEntity(self):
"[EntityClassDescription] classForEntity"
m=defaultModelSet().modelNamed('StoreEmployees')
e=m.entityNamed('Employee')
self.assertEqual(EntityClassDescription.classForEntity(e), Employee)
def test_02_classForEntity_incorrect_packageName(self):
"[EntityClassDescription] classForEntity: ImportError for an incorrect packageName"
# Bug #690224
# change the model's packageName
m=defaultModelSet().modelNamed('StoreEmployees')
m.setPackageName('Dummy.'+m.packageName()) # first position
e=m.entityNamed('Employee')
try:
self.assertRaises(ImportError, EntityClassDescription.classForEntity, e)
finally:
m.setPackageName(m.packageName()[6:])
def test_02b_classForEntity_incorrect_packageName(self):
"[EntityClassDescription] classForEntity: ImportError for an incorrect packageName, 2nd"
# Bug #690224
# change the model's packageName
m=defaultModelSet().modelNamed('StoreEmployees')
m.setPackageName(m.packageName()+'.Dummy') # end position
e=m.entityNamed('Employee')
try:
self.assertRaises(ImportError, EntityClassDescription.classForEntity, e)
finally:
m.setPackageName(m.packageName()[:-6])
def test_03_classForEntity_incorrect_className(self):
"[EntityClassDescription] classForEntity: ImportError for an incorrect className"
# Related to bug #690224
# change the entity's className
m=defaultModelSet().modelNamed('StoreEmployees')
e=m.entityNamed('Employee')
e.setClassName('Dummy')
try:
self.assertRaises(ImportError, EntityClassDescription.classForEntity, e)
finally:
e.setClassName('Employee')
def test_999_classForEntity(self):
"[EntityClassDescription] classForEntity, again"
# Yes, again: just to check we broke nothing, such as: not restoring the
# original package or class names
m=defaultModelSet().modelNamed('StoreEmployees')
e=m.entityNamed('Employee')
self.assertEqual(EntityClassDescription.classForEntity(e), Employee)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestEntityClassDescription, "test_"))
return suite
if __name__ == "__main__":
errs = utils.run_suite(test_suite())
sys.exit(errs and 1 or 0)
|