aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/tests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/content/tests/helpers.py')
-rw-r--r--pydis_site/apps/content/tests/helpers.py79
1 files changed, 39 insertions, 40 deletions
diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py
index d897c024..0e7562e8 100644
--- a/pydis_site/apps/content/tests/helpers.py
+++ b/pydis_site/apps/content/tests/helpers.py
@@ -1,12 +1,13 @@
+import atexit
+import shutil
+import tempfile
from pathlib import Path
-from pyfakefs import fake_filesystem_unittest
+from django.test import TestCase
-# Set the module constant within Patcher to use the fake filesystem
-# https://jmcgeheeiv.github.io/pyfakefs/master/usage.html#modules-to-reload
-with fake_filesystem_unittest.Patcher() as _:
- BASE_PATH = Path("res")
+BASE_PATH = Path(tempfile.mkdtemp(prefix='pydis-site-content-app-tests-'))
+atexit.register(shutil.rmtree, BASE_PATH, ignore_errors=True)
# Valid markdown content with YAML metadata
@@ -50,7 +51,7 @@ PARSED_METADATA = {
PARSED_CATEGORY_INFO = {"title": "Category Name", "description": "Description"}
-class MockPagesTestCase(fake_filesystem_unittest.TestCase):
+class MockPagesTestCase(TestCase):
"""
TestCase with a fake filesystem for testing.
@@ -61,43 +62,41 @@ class MockPagesTestCase(fake_filesystem_unittest.TestCase):
├── not_a_page.md
├── tmp.md
├── tmp
- |   ├── _info.yml
- |   └── category
- |    ├── _info.yml
- |      └── subcategory_without_info
+ | ├── _info.yml
+ | └── category
+ | ├── _info.yml
+ | └── subcategory_without_info
└── category
-    ├── _info.yml
-    ├── with_metadata.md
-    └── subcategory
-    ├── with_metadata.md
-       └── without_metadata.md
+ ├── _info.yml
+ ├── with_metadata.md
+ └── subcategory
+ ├── with_metadata.md
+ └── without_metadata.md
"""
- def setUp(self):
+ def setUp(self) -> None:
"""Create the fake filesystem."""
- self.setUpPyfakefs()
-
- self.fs.create_file(f"{BASE_PATH}/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_file(f"{BASE_PATH}/root.md", contents=MARKDOWN_WITH_METADATA)
- self.fs.create_file(
- f"{BASE_PATH}/root_without_metadata.md", contents=MARKDOWN_WITHOUT_METADATA
- )
- self.fs.create_file(f"{BASE_PATH}/not_a_page.md/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_file(f"{BASE_PATH}/category/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_file(
- f"{BASE_PATH}/category/with_metadata.md", contents=MARKDOWN_WITH_METADATA
- )
- self.fs.create_file(f"{BASE_PATH}/category/subcategory/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_file(
- f"{BASE_PATH}/category/subcategory/with_metadata.md", contents=MARKDOWN_WITH_METADATA
- )
- self.fs.create_file(
- f"{BASE_PATH}/category/subcategory/without_metadata.md",
- contents=MARKDOWN_WITHOUT_METADATA
- )
+ Path(f"{BASE_PATH}/_info.yml").write_text(CATEGORY_INFO)
+ Path(f"{BASE_PATH}/root.md").write_text(MARKDOWN_WITH_METADATA)
+ Path(f"{BASE_PATH}/root_without_metadata.md").write_text(MARKDOWN_WITHOUT_METADATA)
+ Path(f"{BASE_PATH}/not_a_page.md").mkdir(exist_ok=True)
+ Path(f"{BASE_PATH}/not_a_page.md/_info.yml").write_text(CATEGORY_INFO)
+ Path(f"{BASE_PATH}/category").mkdir(exist_ok=True)
+ Path(f"{BASE_PATH}/category/_info.yml").write_text(CATEGORY_INFO)
+ Path(f"{BASE_PATH}/category/with_metadata.md").write_text(MARKDOWN_WITH_METADATA)
+ Path(f"{BASE_PATH}/category/subcategory").mkdir(exist_ok=True)
+ Path(f"{BASE_PATH}/category/subcategory/_info.yml").write_text(CATEGORY_INFO)
+ Path(
+ f"{BASE_PATH}/category/subcategory/with_metadata.md"
+ ).write_text(MARKDOWN_WITH_METADATA)
+ Path(
+ f"{BASE_PATH}/category/subcategory/without_metadata.md"
+ ).write_text(MARKDOWN_WITHOUT_METADATA)
temp = f"{BASE_PATH}/tmp" # noqa: S108
- self.fs.create_file(f"{temp}/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_file(f"{temp}.md", contents=MARKDOWN_WITH_METADATA)
- self.fs.create_file(f"{temp}/category/_info.yml", contents=CATEGORY_INFO)
- self.fs.create_dir(f"{temp}/category/subcategory_without_info")
+ Path(f"{temp}").mkdir(exist_ok=True)
+ Path(f"{temp}/_info.yml").write_text(CATEGORY_INFO)
+ Path(f"{temp}.md").write_text(MARKDOWN_WITH_METADATA)
+ Path(f"{temp}/category").mkdir(exist_ok=True)
+ Path(f"{temp}/category/_info.yml").write_text(CATEGORY_INFO)
+ Path(f"{temp}/category/subcategory_without_info").mkdir(exist_ok=True)