Skip to content

Commit

Permalink
Merge pull request #34 from django-ve/2025_upgrades
Browse files Browse the repository at this point in the history
Added views test case
  • Loading branch information
macagua authored Feb 11, 2025
2 parents b30cbc9 + 6888f7e commit 2caf64e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
36 changes: 33 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ And later to test the Django Installation is done with the following command:

::

$ python -m django --version
$ python3 -m django --version
5.1.6


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

A Django 'Hello World' program example
A Django 'Hello World' application example

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

Django Admin Interface running


Running the testing
===================

Running the ``helloworld`` application tests with the following command:

::

$ python3 manage.py test helloworld.tests

At which point you should see:

::

Found 2 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..
----------------------------------------------------------------------
Ran 2 tests in 1.017s

OK
Destroying test database for alias 'default'...


Building with docker
====================

Expand Down Expand Up @@ -147,6 +172,11 @@ Requesting the URL http://localhost:4000 with the following command:
::

$ curl localhost:4000

At which point you should see:

::

Hello, world!


Expand Down
Empty file added helloworld/tests/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions helloworld/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User

class HelloWorldViewTests(TestCase):
def test_hello_world_view(self):
"""
Test the hello world view returns a 200 status code and the correct content.
"""
response = self.client.get(reverse('index'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Hello, world!\n")

def test_admin_view(self):
"""
Test the admin view returns a 200 status code.
"""
# Create a superuser
User.objects.create_superuser(username='admin', email='[email protected]', password='adminpass')
# Log in the superuser
self.client.login(username='admin', password='adminpass')
# Access the admin view
response = self.client.get(reverse('admin:index'))
self.assertEqual(response.status_code, 200)

0 comments on commit 2caf64e

Please sign in to comment.