From aa9aaad78cace0b5a037a241838cf5a4062fc5d5 Mon Sep 17 00:00:00 2001 From: Eric Redon Date: Sun, 10 May 2020 16:20:13 +0200 Subject: [PATCH] Add simple tests against the project using IPv4 and IPv6 --- CONTRIBUTING.md | 8 ++++++++ tests.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48dfd4f..2fabf19 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,13 @@ ## Development Environment FAQ +### How to run tests? + +From the project root directory, execute the following command: + +```sh +python ./manage.py test +``` + ### How to maintain `requirements.txt`? The canonical list of installation requirements (including development requirements) is maintained in the [`setup.py`](setup.py) file. diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..34bb236 --- /dev/null +++ b/tests.py @@ -0,0 +1,22 @@ +from django.urls import reverse +from django.test import Client, TestCase + + +class UngleichScreeningTaskTests(TestCase): + def setUp(self): + self.ipv4_client = Client(REMOTE_ADDR="127.0.0.1") + self.ipv6_client = Client(REMOTE_ADDR="::1") + + def test_project_using_ipv4(self): + url = reverse("index") + response = self.ipv4_client.get(url) + self.assertContains( + response, "Sorry, only reachable by IPv6", status_code=400, html=True + ) + + def test_project_using_ipv6(self): + url = reverse("index") + response = self.ipv6_client.get(url) + self.assertContains( + response, "A friendly cat picture", status_code=200, html=True + )