1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
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/>.
19 from mediagoblin
.tools
import common
, url
, translate
, mail
, text
, testing
21 testing
._activate
_testing
()
24 def _import_component_testing_method(silly_string
):
25 # Just for the sake of testing that our component importer works.
26 return u
"'%s' is the silliest string I've ever seen" % silly_string
29 def test_import_component():
30 imported_func
= common
.import_component(
31 'mediagoblin.tests.test_util:_import_component_testing_method')
32 result
= imported_func('hooobaladoobala')
33 expected
= u
"'hooobaladoobala' is the silliest string I've ever seen"
34 assert result
== expected
37 def test_send_email():
38 mail
._clear
_test
_inboxes
()
42 "sender@mediagoblin.example.org",
43 ["amanda@example.org", "akila@example.org"],
44 "Testing is so much fun!",
47 I hope you like unit tests JUST AS MUCH AS I DO!""")
49 # check the main inbox
50 assert len(mail
.EMAIL_TEST_INBOX
) == 1
51 message
= mail
.EMAIL_TEST_INBOX
.pop()
52 assert message
['From'] == "sender@mediagoblin.example.org"
53 assert message
['To'] == "amanda@example.org, akila@example.org"
54 assert message
['Subject'] == "Testing is so much fun!"
55 assert message
.get_payload(decode
=True) == """HAYYY GUYS!
57 I hope you like unit tests JUST AS MUCH AS I DO!"""
59 # Check everything that the FakeMhost.sendmail() method got is correct
60 assert len(mail
.EMAIL_TEST_MBOX_INBOX
) == 1
61 mbox_dict
= mail
.EMAIL_TEST_MBOX_INBOX
.pop()
62 assert mbox_dict
['from'] == "sender@mediagoblin.example.org"
63 assert mbox_dict
['to'] == ["amanda@example.org", "akila@example.org"]
64 mbox_message
= email
.message_from_string(mbox_dict
['message'])
65 assert mbox_message
['From'] == "sender@mediagoblin.example.org"
66 assert mbox_message
['To'] == "amanda@example.org, akila@example.org"
67 assert mbox_message
['Subject'] == "Testing is so much fun!"
68 assert mbox_message
.get_payload(decode
=True) == """HAYYY GUYS!
70 I hope you like unit tests JUST AS MUCH AS I DO!"""
73 assert url
.slugify('a walk in the park') == 'a-walk-in-the-park'
74 assert url
.slugify('A Walk in the Park') == 'a-walk-in-the-park'
75 assert url
.slugify('a walk in the park') == 'a-walk-in-the-park'
76 assert url
.slugify('a walk in-the-park') == 'a-walk-in-the-park'
77 assert url
.slugify('a w@lk in the park?') == 'a-w-lk-in-the-park'
78 assert url
.slugify(u
'a walk in the par\u0107') == 'a-walk-in-the-parc'
79 assert url
.slugify(u
'\u00E0\u0042\u00E7\u010F\u00EB\u0066') == 'abcdef'
81 def test_locale_to_lower_upper():
83 Test cc.i18n.util.locale_to_lower_upper()
85 assert translate
.locale_to_lower_upper('en') == 'en'
86 assert translate
.locale_to_lower_upper('en_US') == 'en_US'
87 assert translate
.locale_to_lower_upper('en-us') == 'en_US'
89 # crazy renditions. Useful?
90 assert translate
.locale_to_lower_upper('en-US') == 'en_US'
91 assert translate
.locale_to_lower_upper('en_us') == 'en_US'
94 def test_locale_to_lower_lower():
96 Test cc.i18n.util.locale_to_lower_lower()
98 assert translate
.locale_to_lower_lower('en') == 'en'
99 assert translate
.locale_to_lower_lower('en_US') == 'en-us'
100 assert translate
.locale_to_lower_lower('en-us') == 'en-us'
102 # crazy renditions. Useful?
103 assert translate
.locale_to_lower_lower('en-US') == 'en-us'
104 assert translate
.locale_to_lower_lower('en_us') == 'en-us'
107 def test_html_cleaner():
109 result
= text
.clean_html(
111 '<img src="http://example.org/huge-purple-barney.png" /></p>\n'
115 '<p>Hi everybody! </p>\n'
119 # Remove evil javascript
120 result
= text
.clean_html(
121 '<p><a href="javascript:nasty_surprise">innocent link!</a></p>')
123 '<p><a href="">innocent link!</a></p>')