Skip to content

Commit 2caf64e

Browse files
authored
Merge pull request #34 from django-ve/2025_upgrades
Added views test case
2 parents b30cbc9 + 6888f7e commit 2caf64e

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

README.rst

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ And later to test the Django Installation is done with the following command:
3333

3434
::
3535

36-
$ python -m django --version
36+
$ python3 -m django --version
3737
5.1.6
3838

3939

@@ -97,9 +97,9 @@ see the hello world example like this:
9797
.. figure:: https://github.com/django-ve/django-helloworld/raw/master/docs/django_helloword.png
9898
:width: 315px
9999
:align: center
100-
:alt: A Django 'Hello World' program example
100+
:alt: A Django 'Hello World' application example
101101

102-
A Django 'Hello World' program example
102+
A Django 'Hello World' application example
103103

104104
Also you can open in your web browser the URL http://127.0.0.1:8000/admin for access to
105105
the *Django Admin Interface* like this:
@@ -111,6 +111,31 @@ the *Django Admin Interface* like this:
111111

112112
Django Admin Interface running
113113

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+
114139
Building with docker
115140
====================
116141

@@ -147,6 +172,11 @@ Requesting the URL http://localhost:4000 with the following command:
147172
::
148173

149174
$ curl localhost:4000
175+
176+
At which point you should see:
177+
178+
::
179+
150180
Hello, world!
151181

152182

helloworld/tests/__init__.py

Whitespace-only changes.

helloworld/tests/test_views.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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)

0 commit comments

Comments
 (0)