diff options
Diffstat (limited to '')
| -rw-r--r-- | pydis_site/apps/guides/tests/test_utils.py | 26 | 
1 files changed, 7 insertions, 19 deletions
| diff --git a/pydis_site/apps/guides/tests/test_utils.py b/pydis_site/apps/guides/tests/test_utils.py index b72aee92..9b96ce28 100644 --- a/pydis_site/apps/guides/tests/test_utils.py +++ b/pydis_site/apps/guides/tests/test_utils.py @@ -1,5 +1,5 @@  import os -from unittest.mock import patch, DEFAULT +from unittest.mock import patch  from django.conf import settings  from django.http import Http404 @@ -12,27 +12,23 @@ 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] +        path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides") +        with patch("pydis_site.apps.guides.utils._get_base_path", return_value=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 +        path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides") +        with patch("pydis_site.apps.guides.utils._get_base_path", 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 patch("pydis_site.apps.guides.utils._get_base_path", return_value=path):              with self.assertRaises(Http404):                  utils.get_category("test.md") @@ -42,15 +38,7 @@ class TestGetCategories(TestCase):          """Check does this return test guides categories."""          path = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides") -        side_effects = [path] -        for name in os.listdir(path): -            side_effects.append(os.path.join(path, name)) -            if os.path.isdir(os.path.join(path, name)): -                side_effects.append(os.path.join(path, name)) -                side_effects.append(os.path.join(path, name, "_info.yml")) - -        with patch("pydis_site.apps.guides.utils.os.path.join") as p: -            p.side_effect = side_effects +        with patch("pydis_site.apps.guides.utils._get_base_path", return_value=path):              result = utils.get_categories()          self.assertEqual(result, {"category": {"name": "My Category", "description": "My Description"}}) | 
