aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-09-21 20:29:39 +0300
committerGravatar ks129 <[email protected]>2020-09-21 20:29:39 +0300
commit259ef59298a72778579eaba552213afd8080f9c5 (patch)
tree7b5308995b3bed9ea8252f3425056b5b3a225019
parentCreate test for `_get_base_path` (diff)
Move base path to constant for guides utils unit tests
-rw-r--r--pydis_site/apps/guides/tests/test_utils.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/pydis_site/apps/guides/tests/test_utils.py b/pydis_site/apps/guides/tests/test_utils.py
index ad9916cc..bfbb8d67 100644
--- a/pydis_site/apps/guides/tests/test_utils.py
+++ b/pydis_site/apps/guides/tests/test_utils.py
@@ -8,6 +8,8 @@ from markdown import Markdown
from pydis_site.apps.guides import utils
+BASE_PATH = os.path.join(settings.BASE_DIR, "pydis_site", "apps", "guides", "tests", "test_guides")
+
class TestGetBasePath(TestCase):
def test_get_base_path(self):
@@ -21,23 +23,20 @@ class TestGetBasePath(TestCase):
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")
- with patch("pydis_site.apps.guides.utils._get_base_path", return_value=path):
+ with patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_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")
- with patch("pydis_site.apps.guides.utils._get_base_path", return_value=path):
+ with patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_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._get_base_path", return_value=path):
+ with patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_PATH):
with self.assertRaises(Http404):
utils.get_category("test.md")
@@ -45,9 +44,7 @@ class TestGetCategory(TestCase):
class TestGetCategories(TestCase):
def test_get_categories(self):
"""Check does this return test guides categories."""
- 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 patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_PATH):
result = utils.get_categories()
self.assertEqual(result, {"category": {"name": "My Category", "description": "My Description"}})
@@ -56,9 +53,7 @@ class TestGetCategories(TestCase):
class TestGetGuides(TestCase):
def test_get_all_root_guides(self):
"""Check does this return all root level testing guides."""
- 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 patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_PATH):
result = utils.get_guides()
for case in ["test", "test2"]:
@@ -72,13 +67,11 @@ class TestGetGuides(TestCase):
def test_get_all_category_guides(self):
"""Check does this return all category testing guides."""
- 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 patch("pydis_site.apps.guides.utils._get_base_path", return_value=BASE_PATH):
result = utils.get_guides("category")
md = Markdown(extensions=['meta'])
- with open(os.path.join(path, "category", "test3.md")) as f:
+ with open(os.path.join(BASE_PATH, "category", "test3.md")) as f:
md.convert(f.read())
self.assertIn("test3", result)