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 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_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_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())
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) em_object = em.new_class( 'object', display_name='Object', help_text='Main class for all Em objects',
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', display_text='lodelSiteShortName', help_text='Lodel site short string identifier', group=base_group, data_handler='varchar',