test/unittest_schema.py
changeset 2635 c94df21f7ab2
parent 2456 aa25d6b244c8
child 2730 bb6fcb8c5d71
equal deleted inserted replaced
2634:273eec072cf8 2635:c94df21f7ab2
    14 from rql import RQLSyntaxError
    14 from rql import RQLSyntaxError
    15 
    15 
    16 from yams import BadSchemaDefinition
    16 from yams import BadSchemaDefinition
    17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint
    17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint
    18 from yams.buildobjs import RelationDefinition, EntityType, RelationType
    18 from yams.buildobjs import RelationDefinition, EntityType, RelationType
       
    19 from yams.reader import PyFileReader
    19 
    20 
    20 from cubicweb.schema import CubicWebSchema, CubicWebEntitySchema, \
    21 from cubicweb.schema import CubicWebSchema, CubicWebEntitySchema, \
    21      RQLConstraint, CubicWebSchemaLoader, ERQLExpression, RRQLExpression, \
    22      RQLConstraint, CubicWebSchemaLoader, ERQLExpression, RRQLExpression, \
    22      normalize_expression
    23      normalize_expression
    23 from cubicweb.devtools import TestServerConfiguration as TestConfiguration
    24 from cubicweb.devtools import TestServerConfiguration as TestConfiguration
   131 config.bootstrap_cubes()
   132 config.bootstrap_cubes()
   132 loader.lib_directory = config.schemas_lib_dir()
   133 loader.lib_directory = config.schemas_lib_dir()
   133 
   134 
   134 class SQLSchemaReaderClassTest(TestCase):
   135 class SQLSchemaReaderClassTest(TestCase):
   135 
   136 
   136     def test_knownValues_include_schema_files(self):
       
   137         schema_files = loader.include_schema_files('Bookmark')
       
   138         for file in schema_files:
       
   139             self.assert_(isabs(file))
       
   140         self.assertListEquals([basename(f) for f in schema_files], ['Bookmark.py'])
       
   141 
       
   142     def test_knownValues_load_schema(self):
   137     def test_knownValues_load_schema(self):
   143         schema = loader.load(config)
   138         schema = loader.load(config)
   144         self.assert_(isinstance(schema, CubicWebSchema))
   139         self.assert_(isinstance(schema, CubicWebSchema))
   145         self.assertEquals(schema.name, 'data')
   140         self.assertEquals(schema.name, 'data')
   146         entities = [str(e) for e in schema.entities()]
   141         entities = [str(e) for e in schema.entities()]
   231 class BadSchemaRQLExprTC(TestCase):
   226 class BadSchemaRQLExprTC(TestCase):
   232     def setUp(self):
   227     def setUp(self):
   233         self.loader = CubicWebSchemaLoader()
   228         self.loader = CubicWebSchemaLoader()
   234         self.loader.defined = {}
   229         self.loader.defined = {}
   235         self.loader.loaded_files = []
   230         self.loader.loaded_files = []
   236         self.loader._instantiate_handlers()
   231         self.loader._pyreader = PyFileReader(self.loader)
   237 
   232 
   238     def _test(self, schemafile, msg):
   233     def _test(self, schemafile, msg):
   239         self.loader.handle_file(join(DATADIR, schemafile))
   234         self.loader.handle_file(join(DATADIR, schemafile))
   240         ex = self.assertRaises(BadSchemaDefinition,
   235         ex = self.assertRaises(BadSchemaDefinition,
   241                                self.loader._build_schema, 'toto', False)
   236                                self.loader._build_schema, 'toto', False)