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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 itertools
  21. import tests.loader_utils
  22. from tests.leapi.query.utils import dyncode_module as dyncode
  23. from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
  24. from lodel.leapi.exceptions import LeApiQueryError
  25. class LeGetQueryTestCase(unittest.TestCase):
  26. def test_init_default(self):
  27. """ Testing GetQuery instanciation arguments default value """
  28. tclass_list = [ dyncode.Object,
  29. dyncode.Entry,
  30. dyncode.Person,
  31. dyncode.Text,
  32. dyncode.Section,
  33. dyncode.Publication,
  34. dyncode.Text_Person ]
  35. for tclass in tclass_list:
  36. get_q = LeGetQuery(tclass, [])
  37. qinfos = get_q.dump_infos()
  38. self.assertEqual( set(qinfos['field_list']),
  39. set(tclass.fieldnames(True)))
  40. self.assertEqual( qinfos['limit'],
  41. None)
  42. self.assertEqual( qinfos['offset'],
  43. 0)
  44. self.assertEqual( qinfos['group'],
  45. None)
  46. self.assertEqual( qinfos['order'],
  47. None)
  48. self.assertEqual( qinfos['query_filter'],
  49. ([],[]))
  50. self.assertEqual( qinfos['target_class'],
  51. tclass)
  52. def test_field_list(self):
  53. """ Testing GetQuery field list argument processing """
  54. tclass_list = [ dyncode.Object,
  55. dyncode.Entry,
  56. dyncode.Person,
  57. dyncode.Text,
  58. dyncode.Section,
  59. dyncode.Publication,
  60. dyncode.Text_Person ]
  61. for tclass in tclass_list:
  62. # testing all field list possible combinations
  63. field_list = tclass.fieldnames(True)
  64. for r in range(1, len(field_list) + 1):
  65. combinations = [ list(c) for c in itertools.combinations(field_list, r)]
  66. for test_flist in combinations:
  67. expected = set(test_flist)
  68. get_q = LeGetQuery(tclass, [], field_list = test_flist)
  69. qinfos = get_q.dump_infos()
  70. self.assertEqual( sorted(qinfos['field_list']),
  71. sorted(test_flist))
  72. def test_field_list_duplicated(self):
  73. """ Testing GetQuery field list argument deduplication """
  74. tclass_list = [ dyncode.Object,
  75. dyncode.Text,
  76. dyncode.Section,
  77. dyncode.Publication,
  78. dyncode.Text_Person ]
  79. for tclass in tclass_list:
  80. fl = [ 'lodel_id',
  81. 'lodel_id',
  82. 'help_text',
  83. 'help_text',
  84. 'help_text']
  85. get_q = LeGetQuery(tclass, [], field_list = fl)
  86. self.assertEqual( sorted(list(set(fl))),
  87. sorted(get_q.dump_infos()['field_list']))
  88. def test_field_list_invalid(self):
  89. """ Testing GetQuery invalid field name detection in field list """
  90. bad_field_lists = ( ('non-existing',),
  91. (1,),
  92. (True,),
  93. (None,),
  94. ('lodel_id', 'non-existing',),
  95. ('lodel_id', 1,),
  96. ('lodel_id', True,),
  97. ('lodel_id', None,) )
  98. for bad_field_list in bad_field_lists:
  99. with self.assertRaises(LeApiQueryError):
  100. LeGetQuery(dyncode.Object, [], field_list = bad_field_list)