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 itertools
import count
21 from indico
.util
.string
import seems_html
, to_unicode
, make_unique_token
24 def test_seems_html():
25 assert seems_html('<b>test')
26 assert seems_html('a <b> c')
27 assert not seems_html('test')
28 assert not seems_html('a < b > c')
31 @pytest.mark
.parametrize(('input', 'output'), (
32 (b
'foo', u
'foo'), # ascii
33 (u
'foo', u
'foo'), # unicode
34 (b
'm\xc3\xb6p', u
'm\xf6p'), # utf8
35 (b
'm\xf6p', u
'm\xf6p'), # latin1
36 (b
'm\xc3\xb6p m\xf6p', # mixed...
37 u
'm\xc3\xb6p m\xf6p'), # ...decoded as latin1
39 def test_to_unicode(input, output
):
40 assert to_unicode(input) == output
43 def test_make_unique_token(monkeypatch
):
44 monkeypatch
.setattr('indico.util.string.uuid4', lambda _counter
=count(): str(next(_counter
)))
48 token
= make_unique_token(lambda t
: t
not in tokens
)
52 assert _get_token() == '0'
53 assert _get_token() == '2'
54 assert _get_token() == '4'
55 assert _get_token() == '5'