diff options
| author | 2021-04-01 21:15:36 +0800 | |
|---|---|---|
| committer | 2021-04-01 21:15:36 +0800 | |
| commit | 5f77e80691179ba54ddabf8500dfa704e9514430 (patch) | |
| tree | d5cf47421e50fad39eed628e61b20f79a7667ca2 /pydis_site/apps/resources/tests | |
| parent | Merge pull request #393 from ks129/guides-app (diff) | |
| parent | Change typo postion -> position in Real Python podcast resource (diff) | |
Merge pull request #421 from ks129/resources-lists
Dewikification - Display resources based on YAML files
Diffstat (limited to 'pydis_site/apps/resources/tests')
6 files changed, 56 insertions, 0 deletions
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 index 497e9bfe..53685eef 100644 --- a/pydis_site/apps/resources/tests/test_views.py +++ b/pydis_site/apps/resources/tests/test_views.py @@ -1,6 +1,14 @@ +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): @@ -8,3 +16,19 @@ class TestResourcesView(TestCase): 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 |