def test_save(self): emmodel = EditorialModel("test model", description="Test EM") cls1 = emmodel.new_class('testclass1', display_name='Classe de test 1', help_text='super aide') c1f1 = cls1.new_field('testfield1', data_handler='varchar') c1f2 = cls1.new_field('testfield2', data_handler='varchar') cls2 = emmodel.new_class('testclass2') c2f1 = cls2.new_field('testfield1', data_handler='varchar') c2f2 = cls2.new_field('testfield2', data_handler='varchar') grp1 = emmodel.new_group('testgroup1') grp1.add_components((cls1, c1f1)) grp2 = emmodel.new_group('testgroup2') grp2.add_components((cls2, c1f2, c2f1, c2f2)) grp2.add_dependency(grp1) f_tmp, file_name = tempfile.mkstemp() os.close(f_tmp) emmodel.save(xmlfile, filename=file_name) new_model = EditorialModel.load(xmlfile, filename=file_name) f_tmp, fname = tempfile.mkstemp() os.close(f_tmp) new_model.save(xmlfile, filename=fname) os.unlink(file_name) os.unlink(fname) self.assertNotEqual(id(new_model), id(emmodel)) self.assertEqual(new_model.d_hash(), emmodel.d_hash())
def generate_dyncode(model_file, translator): from lodel.editorial_model.model import EditorialModel from lodel.leapi import lefactory model = EditorialModel.load(translator, filename=model_file) dyncode = lefactory.dyncode_from_em(model) return dyncode
def test_groups_dependencies(self): """ Testing xmlfile groups population dependencies """ emmodel = EditorialModel("em_test", description="test model") grp1 = emmodel.new_group('test_grp', display_name="Test group") grp2 = emmodel.new_group('test_grp2', display_name="Test group2") grp3 = emmodel.new_group('test_grp3', display_name="Test group3", depends=[grp1, grp2]) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_groups(self): """ Testing xmlfile groups handling """ emmodel = EditorialModel("em_test", description="test model") emmodel.new_group('test_grp', display_name="Test group") emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_groups_population(self): """ Testing xmlfile groups population handling """ emmodel = EditorialModel("em_test", description="test model") cls1 = emmodel.new_class('testclass1', display_name="test class 1") cls2 = emmodel.new_class('testclass2', display_name="test class 2") cls1f1 = cls1.new_field('testfield1', data_handler='varchar') cls2f1 = cls2.new_field('testfield2', data_handler='varchar') cls2f2 = cls2.new_field('testfield3', data_handler='varchar') grp1 = emmodel.new_group('test_grp', display_name="Test group") grp2 = emmodel.new_group('test_grp2', display_name="Test group2") grp1.add_components([cls1, cls2]) grp2.add_components([cls1f1, cls2f1, cls2f2]) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_abstract_classes(self): """ Testing xmlfile abtract class handling """ emmodel = EditorialModel("em_test", description="Test model") cls1 = emmodel.new_class('testclass1', display_name="test class 1", abstract=True) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_emfield_with_prop_bool(self): """ Testing xmlfile with bool as property for datahandler """ emmodel = EditorialModel("em_test", description="test model") cls1 = emmodel.new_class('testclass1', display_name="test class 1") cls1f1 = cls1.new_field('testfield1', data_handler='varchar', nullable=True) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_emclass_with_ml_strings(self): """ Testing xmlfile mlstring handling in classes""" emmodel = EditorialModel("em_test", description="test model") cls1 = emmodel.new_class('testclass1', display_name={ 'eng': "test class 1", 'fre': 'classe de test 1' }) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_emfield_with_ml_strings(self): """ Testing xmlfile mlstring handling in data handlers """ emmodel = EditorialModel("em_test", description="test model") cls1 = emmodel.new_class('testclass1', display_name="test class 1") cls1f1 = cls1.new_field('testfield1', display_name={ 'eng': 'test1', 'fre': 'test1' }, data_handler='varchar') emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def test_emfield_with_prop_tuple(self): """ Testing xmlfile with iterable as property for datahandler """ emmodel = EditorialModel("em_test", description="test model") cls1 = emmodel.new_class('testclass1', display_name="test class 1") cls2 = emmodel.new_class('testclass2', display_name="test class 2") cls1f1 = cls1.new_field('testfield1', data_handler='varchar') cls2f1 = cls2.new_field('testfield2', data_handler='list', allowed_classes=[cls1, cls2]) cls2f1 = cls2.new_field('testfield3', data_handler='varchar', back_reference=('testclass2', 'testfield1')) emmodel.save(xmlfile, filename=self.tmpfile) emmodel_loaded = xmlfile.load(self.tmpfile) self.assertEqual(emmodel.d_hash(), emmodel_loaded.d_hash())
def setUpClass(cls): """ Generate an example model for this TestCase """ model = EditorialModel( "test_model", description = "Model for LeFactoryTestCase" ) cls1 = model.new_class('testclass1') cls2 = model.new_class('testclass2') cls3 = model.new_class('testclass3', parents = [cls2]) cls4 = model.new_class('testclass4', parents = [cls1, cls3]) cls5 = model.new_class('testclass5', parents = [cls4]) cls6 = model.new_class('testclass6', parents = [cls5]) cls1.new_field('testfield1', data_handler='varchar') cls1.new_field('testfield2', data_handler='varchar', nullable = True) cls1.new_field('testfield3', data_handler='varchar', max_length=64) cls1.new_field('testfield4', data_handler='varchar', max_length=64, nullable=False, uniq=True) cls1.new_field('id', data_handler='integer', primary_key = True) cls5.new_field('id2', data_handler='varchar', primary_key = True) cls.model = model
# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from lodel.context import LodelContext LodelContext.init() from lodel.settings.settings import Settings as settings settings('globconf.d') from lodel.settings import Settings from lodel.editorial_model.components import * from lodel.editorial_model.exceptions import * from lodel.editorial_model.model import EditorialModel em = EditorialModel('testem', 'Test editorial model') base_group = em.new_group( 'base_group', display_name='Base group', help_text='Base group that implements base EM features (like classtype)') #################### # Lodel Object # #################### em_abstract = em.new_class('abstract_object', display_name='Abstract lodel object', help_text='For testing purpose', group=base_group, abstract=True)
# from lodel.context import LodelContext LodelContext.init() from lodel.settings.settings import Settings as settings settings('globconf.d') from lodel.settings import Settings from lodel.editorial_model.components import * from lodel.editorial_model.exceptions import * from lodel.editorial_model.model import EditorialModel em = EditorialModel('LodelSites', 'LodelSites editorial model') base_group = em.new_group( 'base_group', display_name='Base group', help_text='Base group that implements base EM features (like classtype)') em_lodel_site = em.new_class('LodelSite', group=base_group) em_lodel_site.new_field('name', display_name='lodelSiteName', help_text='Lodel site full name', group=base_group, data_handler='varchar') em_lodel_site.new_field('shortname',