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_field.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import os
  2. from unittest import TestCase
  3. from EditorialModel.fields import EmField
  4. from EditorialModel.model import Model
  5. from EditorialModel.backend.json_backend import EmBackendJson
  6. EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
  7. EM_TEST_OBJECT = None
  8. ## SetUpModule
  9. #
  10. # This function is called once for this module.
  11. # It is designed to overwrite the database configurations, and prepare objects for test_case initialization
  12. def setUpModule():
  13. global EM_TEST_OBJECT
  14. EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST))
  15. #initTestDb(TEST_FIELD_DBNAME)
  16. #setDbConf(TEST_FIELD_DBNAME)
  17. #logging.basicConfig(level=logging.CRITICAL)
  18. def tearDownModule():
  19. #cleanDb(TEST_FIELD_DBNAME)
  20. pass
  21. ## FieldTestCase (Class)
  22. #
  23. # The parent class of all other test cases for the fields module.
  24. # It defines a SetUp function and some utility functions for EmField tests.
  25. class FieldTestCase(TestCase):
  26. @classmethod
  27. def setUpClass(cls):
  28. pass
  29. def setUp(self):
  30. self.test_fieldtype = 'integer'
  31. self.test_fieldgroup = EM_TEST_OBJECT.component(3)
  32. ## TestField (Class)
  33. #
  34. # The test class for the fields module
  35. class TestField(FieldTestCase):
  36. ## Test_create (Function)
  37. #
  38. # tests the creation process of a field
  39. def test_create(self):
  40. field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testfield1', 'fieldgroup_id': self.test_fieldgroup.uid, 'fieldtype': self.test_fieldtype})
  41. # We check that the field has been added
  42. field_records = EM_TEST_OBJECT.component(field.uid)
  43. self.assertIsNot(field_records, False)
  44. # We check that the field has been added in the right list in the model object
  45. field_components_records = EM_TEST_OBJECT.components(EmField)
  46. self.assertIn(field, field_components_records)
  47. ## Test_Deletion
  48. #
  49. # tests the deletion process of a field
  50. def test_deletion(self):
  51. fields = []
  52. field_names = ['field1', 'field2']
  53. # We create the two fields
  54. for name in field_names:
  55. fields.append(EM_TEST_OBJECT.create_component(EmField.__name__, {'name': name, 'fieldgroup_id': self.test_fieldgroup.uid, 'fieldtype': self.test_fieldtype}))
  56. for field in fields:
  57. # We check if the delete process was performed to the end
  58. self.assertTrue(EM_TEST_OBJECT.delete_component(field.uid))
  59. # We check that the field object is not in the editorial model anymore
  60. self.assertFalse(EM_TEST_OBJECT.component(field.uid))
  61. # We check that the field object is not in the EmField components list
  62. field_components_records = EM_TEST_OBJECT.components(EmField)
  63. self.assertNotIn(field, field_components_records)