1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
17 from mediagoblin
.tests
.tools
import setup_fresh_app
18 from mediagoblin
import util
19 from mediagoblin
import mg_globals
23 def test_list_of_dicts_conversion(test_app
):
25 When the user adds tags to a media entry, the string from the form is
26 converted into a list of tags, where each tag is stored in the database
27 as a dict. Each tag dict should contain the tag's name and slug. Another
28 function performs the reverse operation when populating a form to edit tags.
30 # Leading, trailing, and internal whitespace should be removed and slugified
31 assert util
.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
32 {'name': u
'sleep', 'slug': u
'sleep'},
33 {'name': u
'6 am', 'slug': u
'6-am'},
34 {'name': u
'chainsaw!', 'slug': u
'chainsaw'}]
36 # Make sure case-sensitivity is retained when desired
37 mg_globals
.app_config
['tags_case_sensitive'] = True
38 assert util
.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
39 {'name': u
'sleep', 'slug': u
'sleep'},
40 {'name': u
'6 AM', 'slug': u
'6-am'},
41 {'name': u
'chainsaw!', 'slug': u
'chainsaw'}]
43 # If the user enters two identical tags, record only one of them
44 assert util
.convert_to_tag_list_of_dicts('echo,echo') == [{'name': u
'echo',
47 # Make sure converting the list of dicts to a string works
48 assert util
.media_tags_as_string([{'name': u
'yin', 'slug': u
'yin'},
49 {'name': u
'yang', 'slug': u
'yang'}]) == \
52 # If the tag delimiter is a space then we expect different results
53 mg_globals
.app_config
['tags_delimiter'] = u
' '
54 assert util
.convert_to_tag_list_of_dicts('unicorn ceramic nazi') == [
55 {'name': u
'unicorn', 'slug': u
'unicorn'},
56 {'name': u
'ceramic', 'slug': u
'ceramic'},
57 {'name': u
'nazi', 'slug': u
'nazi'}]