No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_translator_picklefile.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import unittest
  20. import tempfile
  21. import os
  22. import tests.loader_utils
  23. from lodel.editorial_model.translator import picklefile
  24. from lodel.editorial_model.model import EditorialModel
  25. from lodel.editorial_model.components import *
  26. from lodel.editorial_model.exceptions import *
  27. class PickleFileTestCase(unittest.TestCase):
  28. def test_save(self):
  29. model = EditorialModel("test model", description = "Test EM")
  30. cls1 = model.new_class('testclass1', display_name = 'Classe de test 1', help_text = 'super aide')
  31. c1f1 = cls1.new_field('testfield1', data_handler = 'varchar')
  32. c1f2 = cls1.new_field('testfield2', data_handler = 'varchar')
  33. cls2 = model.new_class('testclass2')
  34. c2f1 = cls2.new_field('testfield1', data_handler = 'varchar')
  35. c2f2 = cls2.new_field('testfield2', data_handler = 'varchar')
  36. grp1 = model.new_group('testgroup1')
  37. grp1.add_components((cls1, c1f1))
  38. grp2 = model.new_group('testgroup2')
  39. grp2.add_components((cls2, c1f2, c2f1, c2f2))
  40. grp2.add_dependency(grp1)
  41. tmpfd, temp_file = tempfile.mkstemp()
  42. os.close(tmpfd)
  43. os.unlink(temp_file)
  44. model.save(picklefile, filename=temp_file)
  45. new_model = model.load(picklefile, filename=temp_file)
  46. self.assertNotEqual(id(new_model), id(model))
  47. self.assertEqual(new_model.d_hash(), model.d_hash())
  48. os.unlink(temp_file)