diff --git a/README.rst b/README.rst index fcad990..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: @@ -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 ==================== @@ -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! 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)