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