@@ -25,9 +25,10 @@ def phantomjs(self, *args, **kwargs):
25
25
26
26
27
27
class JasmineTests (JsTestCase ):
28
+ urls = 'djangojs.urls'
28
29
29
30
def test_jasmine_suite (self ):
30
- '''It shoudl run its its own Jasmine test suite'''
31
+ '''It should run its its own Jasmine test suite'''
31
32
jasmine_runner_url = '' .join ([self .live_server_url , reverse ('jasmine_runner' )])
32
33
phantomjs_jasmine_runner = join (dirname (__file__ ), 'phantomjs' , 'run-jasmine.js' )
33
34
@@ -37,9 +38,73 @@ def test_jasmine_suite(self):
37
38
38
39
39
40
class DjangoJsJsonTest (TestCase ):
41
+ urls = 'djangojs.urls'
40
42
41
- def test_should_render (self ):
43
+ def setUp (self ):
44
+ self .response = self .client .get (reverse ('django_js_json' ))
45
+ self .json = json .loads (self .response .content )
46
+
47
+ def test_render (self ):
42
48
'''It should render a JSON URLs descriptor'''
43
- response = self .client .get (reverse ('django_js_json' ))
44
- self .assertEqual (response .status_code , 200 )
45
- self .assertEqual (response ['Content-Type' ], 'application/json' )
49
+ self .assertIsNotNone (self .response )
50
+ self .assertEqual (self .response .status_code , 200 )
51
+ self .assertEqual (self .response ['Content-Type' ], 'application/json' )
52
+ self .assertIsNotNone (self .json )
53
+
54
+ def test_simple_url (self ):
55
+ '''It should serialize a simple URL without parameters'''
56
+ self .assertTrue ('django_js_json' in self .json )
57
+ self .assertEqual (self .json ['django_js_json' ], '/urls' )
58
+
59
+ def test_url_an_arg (self ):
60
+ '''It should serialize an URL with a single anonymous parameter'''
61
+ self .assertTrue ('test_arg' in self .json )
62
+ self .assertEqual (self .json ['test_arg' ], '/tests/arg/<>' )
63
+
64
+ def test_url_many_args (self ):
65
+ '''It should serialize an URL with many anonymous parameters'''
66
+ self .assertTrue ('test_arg_multi' in self .json )
67
+ self .assertEqual (self .json ['test_arg_multi' ], '/tests/arg/<>/<>' )
68
+
69
+ def test_url_a_kwarg (self ):
70
+ '''It should serialize an URL with a single named parameter'''
71
+ self .assertTrue ('test_named' in self .json )
72
+ self .assertEqual (self .json ['test_named' ], '/tests/named/<test>' )
73
+
74
+ def test_url_many_kwargs (self ):
75
+ '''It should serialize an URL with many named parameters'''
76
+ self .assertTrue ('test_named_multi' in self .json )
77
+ self .assertEqual (self .json ['test_named_multi' ], '/tests/named/<str>/<num>' )
78
+
79
+ def test_unnamed_url (self ):
80
+ '''It should not serialize unnamed URLs'''
81
+ self .assertFalse ('' in self .json )
82
+ for key , value in self .json .iteritems ():
83
+ self .assertNotEqual (value , '/tests/anonymous' )
84
+
85
+ def test_optionnal_chars (self ):
86
+ '''It should not serialize optionnal characters (take the shortest)'''
87
+ self .assertTrue ('opt' in self .json )
88
+ url = self .json ['opt' ]
89
+ self .assertFalse ('?' in url )
90
+ self .assertEqual (url , '/tests/optionnal' )
91
+
92
+ self .assertTrue ('opt_multi' in self .json )
93
+ url = self .json ['opt_multi' ]
94
+ self .assertFalse ('?' in url )
95
+ self .assertEqual (url , '/tests/man/optionnal' )
96
+
97
+ def test_optionnal_groups (self ):
98
+ '''It should not serialize optionnal non capturing groups'''
99
+ self .assertTrue ('opt_grp' in self .json )
100
+ url = self .json ['opt_grp' ]
101
+ self .assertFalse ('?' in url )
102
+ self .assertEqual (url , '/tests/optionnal/group' )
103
+
104
+
105
+ class VerbatimTagTest (TestCase ):
106
+ urls = 'djangojs.urls'
107
+
108
+
109
+ class DjangoJsTagTest (TestCase ):
110
+ urls = 'djangojs.urls'
0 commit comments