File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,31 @@ the *Django Admin Interface* like this:
111
111
112
112
Django Admin Interface running
113
113
114
+
115
+ Running the testing
116
+ ===================
117
+
118
+ Running the ``helloworld `` application tests with the following command:
119
+
120
+ ::
121
+
122
+ $ python3 manage.py test helloworld.tests
123
+
124
+ At which point you should see:
125
+
126
+ ::
127
+
128
+ Found 2 test(s).
129
+ Creating test database for alias 'default'...
130
+ System check identified no issues (0 silenced).
131
+ ..
132
+ ----------------------------------------------------------------------
133
+ Ran 2 tests in 1.017s
134
+
135
+ OK
136
+ Destroying test database for alias 'default'...
137
+
138
+
114
139
Building with docker
115
140
====================
116
141
Original file line number Diff line number Diff line change
1
+ from django .test import TestCase
2
+ from django .urls import reverse
3
+ from django .contrib .auth .models import User
4
+
5
+ class HelloWorldViewTests (TestCase ):
6
+ def test_hello_world_view (self ):
7
+ """
8
+ Test the hello world view returns a 200 status code and the correct content.
9
+ """
10
+ response = self .client .get (reverse ('index' ))
11
+ self .assertEqual (response .status_code , 200 )
12
+ self .assertContains (response , "Hello, world!\n " )
13
+
14
+ def test_admin_view (self ):
15
+ """
16
+ Test the admin view returns a 200 status code.
17
+ """
18
+ # Create a superuser
19
+ User .
objects .
create_superuser (
username = 'admin' ,
email = '[email protected] ' ,
password = 'adminpass' )
20
+ # Log in the superuser
21
+ self .client .login (username = 'admin' , password = 'adminpass' )
22
+ # Access the admin view
23
+ response = self .client .get (reverse ('admin:index' ))
24
+ self .assertEqual (response .status_code , 200 )
You can’t perform that action at this time.
0 commit comments