From b1695727b7a8a750845576c8c71ab36e9c931c6f Mon Sep 17 00:00:00 2001 From: "Leonardo J. Caballero G" Date: Tue, 11 Feb 2025 14:20:46 +0100 Subject: [PATCH 1/2] Added the views test case --- README.rst | 25 +++++++++++++++++++++++++ helloworld/tests/__init__.py | 0 helloworld/tests/test_views.py | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 helloworld/tests/__init__.py create mode 100644 helloworld/tests/test_views.py diff --git a/README.rst b/README.rst index fcad990..63aecfb 100644 --- a/README.rst +++ b/README.rst @@ -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 ==================== diff --git a/helloworld/tests/__init__.py b/helloworld/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/helloworld/tests/test_views.py b/helloworld/tests/test_views.py new file mode 100644 index 0000000..4020578 --- /dev/null +++ b/helloworld/tests/test_views.py @@ -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='admin@mail.com', 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) From 6888f7eefd76b3dafa6a78d14475f4e70c2a1030 Mon Sep 17 00:00:00 2001 From: "Leonardo J. Caballero G" Date: Tue, 11 Feb 2025 14:21:37 +0100 Subject: [PATCH 2/2] Updated README file --- README.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 63aecfb..ce14f58 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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: @@ -172,6 +172,11 @@ Requesting the URL http://localhost:4000 with the following command: :: $ curl localhost:4000 + +At which point you should see: + +:: + Hello, world!