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_get.py 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import unittest
  2. import itertools
  3. import tests.loader_utils
  4. from tests.leapi.query.utils import dyncode_module as dyncode
  5. from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
  6. from lodel.leapi.exceptions import LeApiQueryError
  7. class LeGetQueryTestCase(unittest.TestCase):
  8. def test_init_default(self):
  9. """ Testing GetQuery instanciation arguments default value """
  10. tclass_list = [ dyncode.Object,
  11. dyncode.Entry,
  12. dyncode.Person,
  13. dyncode.Text,
  14. dyncode.Section,
  15. dyncode.Publication,
  16. dyncode.Text_Person ]
  17. for tclass in tclass_list:
  18. get_q = LeGetQuery(tclass, [])
  19. qinfos = get_q.dump_infos()
  20. self.assertEqual( set(qinfos['field_list']),
  21. set(tclass.fieldnames(True)))
  22. self.assertEqual( qinfos['limit'],
  23. None)
  24. self.assertEqual( qinfos['offset'],
  25. 0)
  26. self.assertEqual( qinfos['group'],
  27. None)
  28. self.assertEqual( qinfos['order'],
  29. None)
  30. self.assertEqual( qinfos['query_filter'],
  31. ([],[]))
  32. self.assertEqual( qinfos['target_class'],
  33. tclass)
  34. def test_field_list(self):
  35. """ Testing GetQuery field list argument processing """
  36. tclass_list = [ dyncode.Object,
  37. dyncode.Entry,
  38. dyncode.Person,
  39. dyncode.Text,
  40. dyncode.Section,
  41. dyncode.Publication,
  42. dyncode.Text_Person ]
  43. for tclass in tclass_list:
  44. # testing all field list possible combinations
  45. field_list = tclass.fieldnames(True)
  46. for r in range(1, len(field_list) + 1):
  47. combinations = [ list(c) for c in itertools.combinations(field_list, r)]
  48. for test_flist in combinations:
  49. expected = set(test_flist)
  50. get_q = LeGetQuery(tclass, [], field_list = test_flist)
  51. qinfos = get_q.dump_infos()
  52. self.assertEqual( sorted(qinfos['field_list']),
  53. sorted(test_flist))
  54. def test_field_list_duplicated(self):
  55. """ Testing GetQuery field list argument deduplication """
  56. tclass_list = [ dyncode.Object,
  57. dyncode.Text,
  58. dyncode.Section,
  59. dyncode.Publication,
  60. dyncode.Text_Person ]
  61. for tclass in tclass_list:
  62. fl = [ 'lodel_id',
  63. 'lodel_id',
  64. 'help_text',
  65. 'help_text',
  66. 'help_text']
  67. get_q = LeGetQuery(tclass, [], field_list = fl)
  68. self.assertEqual( sorted(list(set(fl))),
  69. sorted(get_q.dump_infos()['field_list']))
  70. def test_field_list_invalid(self):
  71. """ Testing GetQuery invalid field name detection in field list """
  72. bad_field_lists = ( ('non-existing',),
  73. (1,),
  74. (True,),
  75. (None,),
  76. ('lodel_id', 'non-existing',),
  77. ('lodel_id', 1,),
  78. ('lodel_id', True,),
  79. ('lodel_id', None,) )
  80. for bad_field_list in bad_field_lists:
  81. with self.assertRaises(LeApiQueryError):
  82. LeGetQuery(dyncode.Object, [], field_list = bad_field_list)