11import os
2- from unittest .mock import Mock , patch
3- from urllib .parse import urlencode
2+ from unittest .mock import patch
43
54from django .contrib .flatpages .models import FlatPage
65from django .http import HttpResponse
@@ -17,89 +16,6 @@ def compress_whitespace(s):
1716
1817
1918class TestViews (TestCase ):
20- @patch ("tinymce.views.enchant" )
21- def test_spell_check_words (self , enchant_mock ):
22- checker_mock = Mock ()
23- checker_mock .check .return_value = True
24- enchant_mock .Dict .return_value = checker_mock
25-
26- body = urlencode ({"method" : "spellcheck" , "text" : "tesat" , "lang" : "en" })
27- response = self .client .post (
28- "/tinymce/spellchecker/" , body , content_type = "application/x-www-form-urlencoded"
29- )
30-
31- output = {"words" : {}}
32-
33- self .assertEqual (200 , response .status_code )
34- self .assertEqual ("application/json" , response ["Content-Type" ])
35- self .assertEqual (output , response .json ())
36-
37- @patch ("tinymce.views.enchant" )
38- def test_spell_check_suggest (self , enchant_mock ):
39- result = ["sample" ]
40- checker_mock = Mock ()
41- checker_mock .check .return_value = False
42- checker_mock .suggest .return_value = result
43- enchant_mock .Dict .return_value = checker_mock
44-
45- body = urlencode ({"method" : "spellcheck" , "text" : "smaple" , "lang" : "en" })
46- response = self .client .post (
47- "/tinymce/spellchecker/" , body , content_type = "application/x-www-form-urlencoded"
48- )
49-
50- output = {"words" : {"smaple" : ["sample" ]}}
51-
52- self .assertEqual (200 , response .status_code )
53- self .assertEqual ("application/json" , response ["Content-Type" ])
54- self .assertEqual (output , response .json ())
55-
56- @patch ("tinymce.views.enchant" )
57- def test_spell_check_empty (self , enchant_mock ):
58- checker_mock = Mock ()
59- checker_mock .check .return_value = True
60- enchant_mock .Dict .return_value = checker_mock
61-
62- body = urlencode ({"method" : "spellcheck" , "text" : "" , "lang" : "en" })
63- response = self .client .post (
64- "/tinymce/spellchecker/" , body , content_type = "application/x-www-form-urlencoded"
65- )
66-
67- output = {"words" : {}}
68-
69- self .assertEqual (200 , response .status_code )
70- self .assertEqual ("application/json" , response ["Content-Type" ])
71- self .assertEqual (output , response .json ())
72-
73- @patch ("tinymce.views.enchant" )
74- def test_spell_check_unknown_method (self , enchant_mock ):
75- body = urlencode ({"method" : "test" , "text" : "test" , "lang" : "en" })
76- with patch ("sys.stderr" , devnull ):
77- response = self .client .post (
78- "/tinymce/spellchecker/" , body , content_type = "application/x-www-form-urlencoded"
79- )
80-
81- output = {"error" : "Got an unexpected method 'test'" }
82-
83- self .assertEqual (200 , response .status_code )
84- self .assertEqual ("application/json" , response ["Content-Type" ])
85- self .assertEqual (output , response .json ())
86-
87- @patch ("tinymce.views.enchant" )
88- def test_spell_check_unknown_lang (self , enchant_mock ):
89- enchant_mock .dict_exists .return_value = False
90-
91- body = urlencode ({"method" : "spellcheck" , "text" : "test" , "lang" : "en" })
92- with patch ("sys.stderr" , devnull ):
93- response = self .client .post (
94- "/tinymce/spellchecker/" , body , content_type = "application/x-www-form-urlencoded"
95- )
96-
97- output = {"error" : "Dictionary not found for language 'en', check pyenchant." }
98-
99- self .assertEqual (200 , response .status_code )
100- self .assertEqual ("application/json" , response ["Content-Type" ])
101- self .assertEqual (output , response .json ())
102-
10319 def test_flatpages_link_list (self ):
10420 FlatPage .objects .create (
10521 url = "/test/url" ,
0 commit comments