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_reference.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import unittest
  2. from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef
  3. from leapi.query.utils import init_dyncode
  4. from lodel.exceptions import *
  5. from lodel.leapi.leobject import LeObject
  6. dyncode = init_dyncode()
  7. obj1 = dyncode.Person(
  8. lodel_id = '1',
  9. lastname = "Foo",
  10. firstname = "Bar",
  11. alias = "Foobar")
  12. obj2 = dyncode.Collection(
  13. lodel_id = '3',
  14. title = "Foo)")
  15. obj3 = dyncode.Collection(
  16. lodel_id = '4',
  17. title = "Foo")
  18. class ReferenceTestCase(unittest.TestCase):
  19. def test_init_reference_class(self):
  20. reference = None
  21. try:
  22. reference = Reference()
  23. except NotImplementedError:
  24. self.assertNotIsInstance(reference, DataHandler)
  25. self.assertIsNone(datahandler)
  26. def test_reference_check_bad_data_value(self):
  27. test_ref = Reference((obj1, obj2))
  28. for test_value in ['toto']:
  29. with self.assertRaises(FieldValidationError):
  30. test_ref._check_data_value(test_value)
  31. def test_reference_check_good_data_value(self):
  32. test_ref = Reference((obj1,))
  33. for test_value in [obj3, 15]:
  34. value = test_ref._check_data_value(test_value)
  35. self.assertEqual(test_value, value)
  36. class MultipleRefTestCase(unittest.TestCase):
  37. def test_multiref_check_data_value_not_iter(self):
  38. test_multiref = MultipleRef(3)
  39. for test_value in [(obj3, 15)]:
  40. value = test_multiref._check_data_value(test_value)
  41. self.assertEqual(test_value, value)