~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to mainpage/utest/test_wl_markdown.py

  • Committer: Holger Rapp
  • Date: 2009-03-02 17:42:51 UTC
  • mto: (48.1.13 widelands)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: holgerrapp@gmx.net-20090302174251-pxkt6jgix4vgz49e
Implemented wishlist bug for colored links

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import sys; sys.path.append("..")
15
15
 
16
16
import unittest
 
17
from wiki.models import Article
 
18
from django.contrib.sites.models import Site
 
19
from settings import SITE_ID
 
20
from django.test import TestCase as DBTestCase
 
21
_domain = Site.objects.get(pk=SITE_ID).domain
17
22
 
18
23
from templatetags.wl_markdown import do_wl_markdown
19
24
 
21
26
    def setUp(self):
22
27
        self.res = do_wl_markdown(self.input)
23
28
 
24
 
class TestWlMarkdown_SimpleCase_ExceptCorrectResult(_TestWlMarkdown_Base):
25
 
    input = u"Hallo Welt"
26
 
    wanted = u"<p>Hallo Welt</p>\n"
27
 
    def runTest(self):
28
 
        self.assertEqual(self.wanted,self.res)
29
 
# WlMarkup doesn't do urlization
30
 
# class TestWlMarkdown_AutoLinkHTTP_ExceptCorrectResult(_TestWlMarkdown_Base):
31
 
#     input = u"Sun: http://www.sun.com"
32
 
#     wanted = u"""<p>Sun: <a href="http://www.sun.com">http://www.sun.com</a></p>\n"""
33
 
#     def runTest(self):
34
 
#         self.assertEqual(self.wanted,self.res)
35
 
class TestWlMarkdown_WikiWordsSimple_ExceptCorrectResult(_TestWlMarkdown_Base):
36
 
    input = u"Na Du HalloWelt, Du?"
37
 
    wanted = u"""<p>Na Du <a href="/wiki/HalloWelt">HalloWelt</a>, Du?</p>\n"""
38
 
    def runTest(self):
39
 
        self.assertEqual(self.wanted,self.res)
40
 
class TestWlMarkdown_WikiWordsAvoid_ExceptCorrectResult(_TestWlMarkdown_Base):
41
 
    input = u"Hi !NotAWikiWord Moretext"
42
 
    wanted = u"""<p>Hi NotAWikiWord Moretext</p>\n"""
43
 
    def runTest(self):
44
 
        self.assertEqual(self.wanted,self.res)
45
 
class TestWlMarkdown_WikiWordsInLink_ExceptCorrectResult(_TestWlMarkdown_Base):
46
 
    input = u"""WikiWord [NoWikiWord](http://www.sun.com)"""
47
 
    wanted = u"""<p><a href="/wiki/WikiWord">WikiWord</a> <a href="http://www.sun.com">NoWikiWord</a></p>\n"""
48
 
    def runTest(self):
49
 
        self.assertEqual(self.wanted,self.res)
50
 
 
 
29
class TestWlMarkdown(DBTestCase):
 
30
    def setUp(self):
 
31
        a = Article.objects.create(title="MainPage")
 
32
        a = Article.objects.create(title="HalloWelt")
 
33
        a = Article.objects.create(title="NoWikiWord")
 
34
        a = Article.objects.create(title="WikiWord")
 
35
 
 
36
    def _check(self, input, wanted):
 
37
        res = do_wl_markdown(input)
 
38
        self.assertEqual(wanted,res)
 
39
 
 
40
    def test_simple_case__correct_result(self):
 
41
        input = u"Hallo Welt"
 
42
        wanted = u"<p>Hallo Welt</p>\n"
 
43
        self._check(input,wanted)
 
44
 
 
45
    def test_wikiwords_simple__except_correct_result(self):
 
46
        input = u"Na Du HalloWelt, Du?"
 
47
        wanted = u"""<p>Na Du <a href="/wiki/HalloWelt">HalloWelt</a>, Du?</p>\n"""
 
48
        self._check(input,wanted)
 
49
    
 
50
    def test_wikiwords_avoid__except_correct_result(self):
 
51
        input = u"Hi !NotAWikiWord Moretext"
 
52
        wanted = u"""<p>Hi NotAWikiWord Moretext</p>\n"""
 
53
        self._check(input,wanted)
 
54
 
 
55
    def test_wikiwords_in_link__except_correct_result(self):
 
56
        input = u"""WikiWord [NoWikiWord](/forum/)"""
 
57
        wanted = u"""<p><a href="/wiki/WikiWord">WikiWord</a> <a href="/forum/">NoWikiWord</a></p>\n"""
 
58
        self._check(input,wanted)
 
59
 
 
60
    def test_wikiwords_external_links__except_correct_result(self):
 
61
        input = u"""[NoWikiWord](http://www.sun.com)"""
 
62
        wanted = u"""<p><a href="http://www.sun.com" class="external">NoWikiWord</a></p>\n"""
 
63
        self._check(input,wanted)
 
64
 
 
65
    def test_wikiwords_noexternal_links__except_correct_result(self):
 
66
        input = u"""[NoWikiWord](http://%s/blahfasel/wiki)""" % _domain
 
67
        wanted = u"""<p><a href="http://%s/blahfasel/wiki">NoWikiWord</a></p>\n""" %_domain
 
68
        self._check(input,wanted)
 
69
 
 
70
    def test_wikiwords_noclasschangeforimage_links__except_correct_result(self):
 
71
        input =  u"""<a href="http://www.ccc.de"><img src="/blub" /></a>"""
 
72
        wanted = u"""<p><a href="http://www.ccc.de"><img src="/blub" /></a></p>\n"""
 
73
        self._check(input,wanted)
 
74
    
 
75
    # Existing links
 
76
    def test_existing_link_html(self):
 
77
        input = u"""<a href="/wiki/MainPage">this page</a>"""
 
78
        wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>\n"""
 
79
        self._check(input,wanted)
 
80
 
 
81
    def test_existing_link_markdown(self):
 
82
        input = u"""[this page](/wiki/MainPage)"""
 
83
        wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>\n"""
 
84
        self._check(input,wanted)
 
85
 
 
86
    def test_existing_link_wikiword(self):
 
87
        input = u"""MainPage"""
 
88
        wanted = u"""<p><a href="/wiki/MainPage">MainPage</a></p>\n"""
 
89
        self._check(input,wanted)
 
90
 
 
91
    def test_existing_editlink_wikiword(self):
 
92
        input = u"""<a href="/wiki/MainPage/edit/">this page</a>"""
 
93
        wanted = u"""<p><a href="/wiki/MainPage/edit/">this page</a></p>\n"""
 
94
        self._check(input,wanted)
 
95
 
 
96
    # Missing links
 
97
    def test_missing_link_html(self):
 
98
        input = u"""<a href="/wiki/MissingPage">this page</a>"""
 
99
        wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>\n"""
 
100
        self._check(input,wanted)
 
101
 
 
102
    def test_missing_link_markdown(self):
 
103
        input = u"""[this page](/wiki/MissingPage)"""
 
104
        wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>\n"""
 
105
        self._check(input,wanted)
 
106
 
 
107
    def test_missing_link_wikiword(self):
 
108
        input = u"""BlubMissingPage"""
 
109
        wanted = u"""<p><a href="/wiki/BlubMissingPage" class="missing">BlubMissingPage</a></p>\n"""
 
110
        res = do_wl_markdown(input)
 
111
        # self._check(input,wanted)
 
112
 
 
113
    def test_missing_editlink_wikiword(self):
 
114
        input = u"""<a href="/wiki/MissingPage/edit/">this page</a>"""
 
115
        wanted = u"""<p><a href="/wiki/MissingPage/edit/" class="missing">this page</a></p>\n"""
 
116
        self._check(input,wanted)
51
117
 
52
118
if __name__ == '__main__':
53
119
    unittest.main()