diff options
| author | 2021-05-16 18:42:50 +0100 | |
|---|---|---|
| committer | 2021-05-16 18:42:50 +0100 | |
| commit | 8c7c3b137fb6c60818d29ac3d14ebb397357ee0e (patch) | |
| tree | fec5581d5e27fc860db6424f7c1d6a3a71565693 /pydis_site/apps/resources/tests | |
| parent | Resolve conflicts (diff) | |
| parent | Merge pull request #501 from python-discord/update/sir-lancebot-env-vars (diff) | |
Merge branch 'main' into fix_327
Diffstat (limited to 'pydis_site/apps/resources/tests')
7 files changed, 66 insertions, 0 deletions
diff --git a/pydis_site/apps/resources/tests/__init__.py b/pydis_site/apps/resources/tests/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pydis_site/apps/resources/tests/__init__.py diff --git a/pydis_site/apps/resources/tests/test_as_icon.py b/pydis_site/apps/resources/tests/test_as_icon.py new file mode 100644 index 00000000..5b33910d --- /dev/null +++ b/pydis_site/apps/resources/tests/test_as_icon.py @@ -0,0 +1,28 @@ +from django.test import TestCase + +from pydis_site.apps.resources.templatetags import as_icon + + +class TestAsIcon(TestCase): + """Tests for `as_icon` templatetag.""" + + def test_as_icon(self): + """Should return proper icon type class and icon class based on input.""" + test_cases = [ + { + "input": "regular/icon", + "output": "fas fa-icon", + }, + { + "input": "branding/brand", + "output": "fab fa-brand", + }, + { + "input": "fake/my-icon", + "output": "fas fa-my-icon", + } + ] + + for case in test_cases: + with self.subTest(input=case["input"], output=case["output"]): + self.assertEqual(case["output"], as_icon(case["input"])) diff --git a/pydis_site/apps/resources/tests/test_views.py b/pydis_site/apps/resources/tests/test_views.py new file mode 100644 index 00000000..53685eef --- /dev/null +++ b/pydis_site/apps/resources/tests/test_views.py @@ -0,0 +1,34 @@ +from pathlib import Path +from unittest.mock import patch + +from django.conf import settings +from django.test import TestCase +from django_hosts import reverse + +TESTING_RESOURCES_PATH = Path( + settings.BASE_DIR, "pydis_site", "apps", "resources", "tests", "testing_resources" +) + + +class TestResourcesView(TestCase): + def test_resources_index_200(self): + """Check does index of resources app return 200 HTTP response.""" + url = reverse("resources:index") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + +class TestResourcesListView(TestCase): + @patch("pydis_site.apps.resources.views.resources_list.RESOURCES_PATH", TESTING_RESOURCES_PATH) + def test_valid_resource_list_200(self): + """Check does site return code 200 when visiting valid resource list.""" + url = reverse("resources:resources", ("testing",)) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + @patch("pydis_site.apps.resources.views.resources_list.RESOURCES_PATH", TESTING_RESOURCES_PATH) + def test_invalid_resource_list_404(self): + """Check does site return code 404 when trying to visit invalid resource list.""" + url = reverse("resources:resources", ("invalid",)) + response = self.client.get(url) + self.assertEqual(response.status_code, 404) diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml new file mode 100644 index 00000000..bae17ea3 --- /dev/null +++ b/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml @@ -0,0 +1 @@ +name: Testing diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml new file mode 100644 index 00000000..eaac32d9 --- /dev/null +++ b/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml @@ -0,0 +1 @@ +name: Foobar diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/foobar/resource_test.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/foobar/resource_test.yaml new file mode 100644 index 00000000..22835090 --- /dev/null +++ b/pydis_site/apps/resources/tests/testing_resources/testing/foobar/resource_test.yaml @@ -0,0 +1 @@ +name: Resource Test diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/my_resource.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/my_resource.yaml new file mode 100644 index 00000000..61df6173 --- /dev/null +++ b/pydis_site/apps/resources/tests/testing_resources/testing/my_resource.yaml @@ -0,0 +1 @@ +name: My Resource |