1
+ from django .core .urlresolvers import reverse
1
2
from django .test import TestCase
2
3
3
4
from example_project .polls .factories import UserFactory
@@ -19,56 +20,61 @@ class AppTests(LoggedInTestCase):
19
20
20
21
def test_bare_mixin_works (self ):
21
22
# hit admin that doesn't have any tools defined, just the mixin
22
- response = self .client .get ('/ admin/polls/poll/add/' )
23
+ response = self .client .get (reverse ( ' admin:polls_poll_add' ) )
23
24
self .assertEqual (response .status_code , 200 )
24
25
25
26
def test_configured_mixin_works (self ):
26
27
# hit admin that does have any tools defined
27
- response = self .client .get ('/ admin/polls/choice/add/' )
28
+ response = self .client .get (reverse ( ' admin:polls_choice_add' ) )
28
29
self .assertEqual (response .status_code , 200 )
29
30
self .assertIn ('objectactions' , response .context_data )
30
31
31
32
def test_tool_func_gets_executed (self ):
32
33
c = Choice .objects .get (pk = 1 )
33
34
votes = c .votes
34
- response = self .client .get ('/ admin/polls/choice/1/tools/ increment_vote/' )
35
+ response = self .client .get (reverse ( ' admin:polls_choice_tools' , args = ( 1 , ' increment_vote' )) )
35
36
self .assertEqual (response .status_code , 302 )
36
- self .assertTrue (response ['location' ].endswith ('/admin/polls/choice/1/' ))
37
+ url = reverse ('admin:polls_choice_change' , args = (1 ,))
38
+ self .assertTrue (response ['location' ].endswith (url ))
37
39
c = Choice .objects .get (pk = 1 )
38
40
self .assertEqual (c .votes , votes + 1 )
39
41
40
42
def test_tool_can_return_httpresponse (self ):
41
43
# we know this url works because of fixtures
42
- url = '/ admin/polls/choice/2/tools/ edit_poll/'
44
+ url = reverse ( ' admin:polls_choice_tools' , args = ( 2 , ' edit_poll' ))
43
45
response = self .client .get (url )
44
46
# we expect a redirect
45
47
self .assertEqual (response .status_code , 302 )
46
- self .assertTrue (response ['location' ].endswith ('/ admin/polls/poll/1/' ))
48
+ self .assertTrue (response ['location' ].endswith (reverse ( ' admin:polls_poll_change' , args = ( 1 ,)) ))
47
49
48
50
def test_can_return_template (self ):
49
51
# This is more of a test of render_to_response than the app, but I think
50
52
# it's good to document that this is something we can do.
51
- url = '/ admin/polls/poll/1/tools/ delete_all_choices/'
53
+ url = reverse ( ' admin:polls_poll_tools' , args = ( 1 , ' delete_all_choices' ))
52
54
response = self .client .get (url )
53
55
self .assertTemplateUsed (response , "clear_choices.html" )
54
56
55
57
def test_message_user_sends_message (self ):
56
- url = '/ admin/polls/poll/1/tools/ delete_all_choices/'
58
+ url = reverse ( ' admin:polls_poll_tools' , args = ( 1 , ' delete_all_choices' ))
57
59
self .assertNotIn ('messages' , self .client .cookies )
58
60
self .client .get (url )
59
61
self .assertIn ('messages' , self .client .cookies )
60
62
61
63
def test_intermediate_page_with_post_works (self ):
62
64
self .assertTrue (Choice .objects .filter (poll = 1 ).count ())
63
- url = '/ admin/polls/poll/1/tools/ delete_all_choices/'
65
+ url = reverse ( ' admin:polls_poll_tools' , args = ( 1 , ' delete_all_choices' ))
64
66
response = self .client .post (url )
65
67
self .assertEqual (response .status_code , 302 )
66
68
self .assertEqual (Choice .objects .filter (poll = 1 ).count (), 0 )
67
69
68
70
def test_undefined_tool_404s (self ):
69
- response = self .client .get ('/ admin/polls/choice/1/tools/ weeeewoooooo/' )
71
+ response = self .client .get (reverse ( ' admin:polls_poll_tools' , args = ( 1 , ' weeeewoooooo' )) )
70
72
self .assertEqual (response .status_code , 404 )
71
73
72
74
def test_key_error_tool_500s (self ):
73
75
self .assertRaises (KeyError , self .client .get ,
74
- '/admin/polls/choice/1/tools/raise_key_error/' )
76
+ reverse ('admin:polls_choice_tools' , args = (1 , 'raise_key_error' )))
77
+
78
+ def test_render_button (self ):
79
+ response = self .client .get (reverse ('admin:polls_choice_change' , args = (1 ,)))
80
+ self .assertEqual (response .status_code , 200 )
0 commit comments