Fix day filter
[cds-indico.git] / indico / util / user_test.py
blob57978cafb3beaceb1bb884bda83b3e0a60c4a455
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from mock import MagicMock
19 from indico.util.user import iter_acl, unify_user_args
22 def test_iter_acl():
23 user = MagicMock(is_group=False, spec=['is_group'])
24 local_group = MagicMock(is_group=True, is_local=True)
25 remote_group = MagicMock(is_group=True, is_local=False)
26 acl = [remote_group, user, local_group]
27 assert list(iter_acl(iter(acl))) == [user, local_group, remote_group]
30 def test_unify_user_args_new(dummy_avatar):
31 avatar = dummy_avatar
32 user = dummy_avatar.user
34 @unify_user_args
35 def fn(a, b, c, d, e, f):
36 # posargs
37 assert a == 'foo'
38 assert b == user
39 assert c == user
40 # kwargs
41 assert d == 'bar'
42 assert e == user
43 assert f == user
45 fn('foo', user, avatar, d='bar', e=user, f=avatar)
48 def test_unify_user_args_legacy(dummy_avatar):
49 avatar = dummy_avatar
50 user = dummy_avatar.user
52 @unify_user_args(legacy=True)
53 def fn(a, b, c, d, e, f):
54 # posargs
55 assert a == 'foo'
56 assert b == avatar
57 assert c == avatar
58 # kwargs
59 assert d == 'bar'
60 assert e == avatar
61 assert f == avatar
63 fn('foo', user, avatar, d='bar', e=user, f=avatar)