Fix errors in collection views
[mediagoblin.git] / mediagoblin / tests / test_tags.py
CommitLineData
8ff4dec7 1# GNU MediaGoblin -- federated, autonomous media hosting
cf29e8a8 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
8ff4dec7
CFD
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
1be247b3 17from mediagoblin.tests.tools import get_app
152a3bfa 18from mediagoblin.tools import text
8ff4dec7 19
b97144dc 20def test_list_of_dicts_conversion():
8ff4dec7
CFD
21 """
22 When the user adds tags to a media entry, the string from the form is
23 converted into a list of tags, where each tag is stored in the database
24 as a dict. Each tag dict should contain the tag's name and slug. Another
25 function performs the reverse operation when populating a form to edit tags.
26 """
1be247b3 27 test_app = get_app(dump_old_app=False)
8ff4dec7 28 # Leading, trailing, and internal whitespace should be removed and slugified
152a3bfa 29 assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
8ff4dec7
CFD
30 {'name': u'sleep', 'slug': u'sleep'},
31 {'name': u'6 AM', 'slug': u'6-am'},
32 {'name': u'chainsaw!', 'slug': u'chainsaw'}]
33
34 # If the user enters two identical tags, record only one of them
152a3bfa 35 assert text.convert_to_tag_list_of_dicts('echo,echo') == [{'name': u'echo',
8ff4dec7
CFD
36 'slug': u'echo'}]
37
38 # Make sure converting the list of dicts to a string works
152a3bfa 39 assert text.media_tags_as_string([{'name': u'yin', 'slug': u'yin'},
8ff4dec7 40 {'name': u'yang', 'slug': u'yang'}]) == \
d5bb51f9 41 u'yin, yang'