123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #
- # This file is part of Lodel 2 (https://github.com/OpenEdition)
- #
- # Copyright (C) 2015-2017 Cléo UMS-3287
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published
- # by the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
-
-
- import unittest
-
- import itertools
-
- import tests.loader_utils
- from tests.leapi.query.utils import dyncode_module as dyncode
-
- from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
- from lodel.leapi.exceptions import LeApiQueryError
-
- class LeGetQueryTestCase(unittest.TestCase):
-
- def test_init_default(self):
- """ Testing GetQuery instanciation arguments default value """
- tclass_list = [ dyncode.Object,
- dyncode.Entry,
- dyncode.Person,
- dyncode.Text,
- dyncode.Section,
- dyncode.Publication,
- dyncode.Text_Person ]
-
- for tclass in tclass_list:
- get_q = LeGetQuery(tclass, [])
- qinfos = get_q.dump_infos()
- self.assertEqual( set(qinfos['field_list']),
- set(tclass.fieldnames(True)))
- self.assertEqual( qinfos['limit'],
- None)
- self.assertEqual( qinfos['offset'],
- 0)
- self.assertEqual( qinfos['group'],
- None)
- self.assertEqual( qinfos['order'],
- None)
- self.assertEqual( qinfos['query_filter'],
- ([],[]))
- self.assertEqual( qinfos['target_class'],
- tclass)
-
- def test_field_list(self):
- """ Testing GetQuery field list argument processing """
- tclass_list = [ dyncode.Object,
- dyncode.Entry,
- dyncode.Person,
- dyncode.Text,
- dyncode.Section,
- dyncode.Publication,
- dyncode.Text_Person ]
-
- for tclass in tclass_list:
- # testing all field list possible combinations
- field_list = tclass.fieldnames(True)
- for r in range(1, len(field_list) + 1):
- combinations = [ list(c) for c in itertools.combinations(field_list, r)]
- for test_flist in combinations:
- expected = set(test_flist)
- get_q = LeGetQuery(tclass, [], field_list = test_flist)
- qinfos = get_q.dump_infos()
- self.assertEqual( sorted(qinfos['field_list']),
- sorted(test_flist))
-
- def test_field_list_duplicated(self):
- """ Testing GetQuery field list argument deduplication """
- tclass_list = [ dyncode.Object,
- dyncode.Text,
- dyncode.Section,
- dyncode.Publication,
- dyncode.Text_Person ]
- for tclass in tclass_list:
- fl = [ 'lodel_id',
- 'lodel_id',
- 'help_text',
- 'help_text',
- 'help_text']
- get_q = LeGetQuery(tclass, [], field_list = fl)
- self.assertEqual( sorted(list(set(fl))),
- sorted(get_q.dump_infos()['field_list']))
-
- def test_field_list_invalid(self):
- """ Testing GetQuery invalid field name detection in field list """
- bad_field_lists = ( ('non-existing',),
- (1,),
- (True,),
- (None,),
- ('lodel_id', 'non-existing',),
- ('lodel_id', 1,),
- ('lodel_id', True,),
- ('lodel_id', None,) )
-
- for bad_field_list in bad_field_lists:
- with self.assertRaises(LeApiQueryError):
- LeGetQuery(dyncode.Object, [], field_list = bad_field_list)
|