mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-15 15:52:02 +01:00
[#49] Changed the migration handler used in the tests for Model
This commit is contained in:
parent
38395e09a5
commit
eaf0520d3b
1 changed files with 17 additions and 19 deletions
|
|
@ -7,19 +7,20 @@ from EditorialModel.fieldgroups import EmFieldGroup
|
|||
from EditorialModel.fields import EmField
|
||||
|
||||
from EditorialModel.backend.json_backend import EmBackendJson
|
||||
from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
|
||||
#from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
|
||||
from EditorialModel.migrationhandler.django import DjangoMigrationHandler
|
||||
|
||||
class TestModel(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.me = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
self.me = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
|
||||
def test_init(self):
|
||||
""" Instanciation test """
|
||||
model = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
self.assertTrue(isinstance(model, Model))
|
||||
model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler = DummyMigrationHandler(True))
|
||||
|
||||
model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DjangoMigrationHandler('test',debug=True))
|
||||
self.assertTrue(isinstance(model, Model))
|
||||
|
||||
def test_components(self):
|
||||
|
|
@ -27,41 +28,38 @@ class TestModel(unittest.TestCase):
|
|||
for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
|
||||
comp_l = self.me.components(comp_class)
|
||||
for component in comp_l:
|
||||
self.assertTrue(isinstance(component, comp_class), "Model.components method don't return EmComponent of the right type. Asked for {} but got {}".format(type(comp_class), type(component)))
|
||||
self.assertTrue(isinstance(component, comp_class), "Model.components method doesn't return EmComponent of the right type. Asked for {} but got {}".format(type(comp_class), type(component)))
|
||||
|
||||
def test_sort_components(self):
|
||||
""" Test that Model.sort_components method actually sort components """
|
||||
#disordering an EmClass
|
||||
# disordering an EmClass
|
||||
cl_l = self.me.components(EmClass)
|
||||
last_class = cl_l[0]
|
||||
last_class.rank = 10000
|
||||
self.me.sort_components(EmClass)
|
||||
self.assertEqual(self.me._components['EmClass'][-1].uid, last_class.uid, "The methode sort_components don't really sort by rank")
|
||||
self.assertEqual(self.me._components['EmClass'][-1].uid, last_class.uid, "The sort_components method doesn't really sort by rank")
|
||||
|
||||
def test_new_uid(self):
|
||||
""" Test that Model.new_uid return a new uniq uid """
|
||||
""" Test that model.new_uid return a new uniq uid """
|
||||
new_uid = self.me.new_uid()
|
||||
self.assertNotIn(new_uid, self.me._components['uids'].keys())
|
||||
|
||||
|
||||
def test_hash(self):
|
||||
""" Test that __hash__ and __eq__ works properly on models """
|
||||
me = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler = DummyMigrationHandler(True))
|
||||
""" Test that __hash__ and __eq__ work properly on models """
|
||||
me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DjangoMigrationHandler('test', debug=True))
|
||||
|
||||
self.assertEqual(hash(me), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
|
||||
self.assertTrue(me, me2)
|
||||
self.assertEqual(hash(me1), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
|
||||
self.assertTrue(me1, me2)
|
||||
|
||||
cl_l = me.classes()
|
||||
cl_l = me1.classes()
|
||||
cl_l[0].modify_rank(1)
|
||||
|
||||
self.assertNotEqual(hash(me), hash(me2), "After a class rank modification the hashes are the same")
|
||||
self.assertFalse(me, me2)
|
||||
self.assertNotEqual(hash(me1), hash(me2), "After a class rank modification the hashes are the same")
|
||||
self.assertFalse(me1, me2)
|
||||
|
||||
cl_l = me2.classes()
|
||||
cl_l[0].modify_rank(1)
|
||||
|
||||
self.assertEqual(hash(me), hash(me2), "After doing sames modifications in the two models the hashes differs")
|
||||
self.assertTrue(me, me2)
|
||||
|
||||
|
||||
self.assertTrue(me1, me2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue