aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-09-21 16:36:05 +0300
committerGravatar ks129 <[email protected]>2020-09-21 16:36:05 +0300
commit8d2e397d265c13b8712746f140de4cb21867f319 (patch)
treeb47cd44c3262370102b5d10dafba843b963b0ae8
parentApply testability changes to views tests (diff)
Create tests for get_category guides utility function
-rw-r--r--pydis_site/apps/guides/tests/test_utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/pydis_site/apps/guides/tests/test_utils.py b/pydis_site/apps/guides/tests/test_utils.py
new file mode 100644
index 00000000..f7ed3b62
--- /dev/null
+++ b/pydis_site/apps/guides/tests/test_utils.py
@@ -0,0 +1,36 @@
+import os
+from unittest.mock import patch
+
+from django.conf import settings
+from django.http import Http404
+from django.test import TestCase
+
+from pydis_site.apps.guides import utils
+
+
+class TestGetCategory(TestCase):
+ def test_get_category_successfully(self):
+ """Check does this get right data from category data file."""
+ path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides", "category")
+ info_path = os.path.join(path, "_info.yml")
+ with patch("pydis_site.apps.guides.utils.os.path.join") as p:
+ p.side_effect = [path, info_path]
+ result = utils.get_category("category")
+
+ self.assertEqual(result, {"name": "My Category", "description": "My Description"})
+
+ def test_get_category_not_exists(self):
+ """Check does this raise 404 error when category don't exists."""
+ path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides", "invalid")
+ with patch("pydis_site.apps.guides.utils.os.path.join") as p:
+ p.return_value = path
+ with self.assertRaises(Http404):
+ utils.get_category("invalid")
+
+ def test_get_category_not_directory(self):
+ """Check does this raise 404 error when category isn't directory."""
+ path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides", "test.md")
+ with patch("pydis_site.apps.guides.utils.os.path.join") as p:
+ p.return_value = path
+ with self.assertRaises(Http404):
+ utils.get_category("test.md")