4
4
5
5
from pydis_site .apps .content import utils
6
6
from pydis_site .apps .content .tests .helpers import (
7
- MockPagesTestCase , PARSED_CATEGORY_INFO , PARSED_HTML , PARSED_METADATA
7
+ BASE_PATH , MockPagesTestCase , PARSED_CATEGORY_INFO , PARSED_HTML , PARSED_METADATA
8
8
)
9
9
10
10
11
11
class GetCategoryTests (MockPagesTestCase ):
12
12
"""Tests for the get_category function."""
13
13
14
14
def test_get_valid_category (self ):
15
- result = utils .get_category (Path ("category" ))
15
+ result = utils .get_category (Path (BASE_PATH , "category" ))
16
16
17
17
self .assertEqual (result , {"title" : "Category Name" , "description" : "Description" })
18
18
19
19
def test_get_nonexistent_category (self ):
20
20
with self .assertRaises (Http404 ):
21
- utils .get_category (Path ("invalid" ))
21
+ utils .get_category (Path (BASE_PATH , "invalid" ))
22
22
23
23
def test_get_category_with_path_to_file (self ):
24
24
# Valid categories are directories, not files
25
25
with self .assertRaises (Http404 ):
26
- utils .get_category (Path ("root.md" ))
26
+ utils .get_category (Path (BASE_PATH , "root.md" ))
27
27
28
28
def test_get_category_without_info_yml (self ):
29
29
# Categories should provide an _info.yml file
30
30
with self .assertRaises (FileNotFoundError ):
31
- utils .get_category (Path ("tmp/category/subcategory_without_info" ))
31
+ utils .get_category (Path (BASE_PATH , "tmp/category/subcategory_without_info" ))
32
32
33
33
34
34
class GetCategoriesTests (MockPagesTestCase ):
35
35
"""Tests for the get_categories function."""
36
36
37
37
def test_get_root_categories (self ):
38
- result = utils .get_categories (Path ( "." ) )
38
+ result = utils .get_categories (BASE_PATH )
39
39
40
40
info = PARSED_CATEGORY_INFO
41
- self .assertEqual (result , {"category" : info , "tmp" : info , "not_a_page.md" : info })
41
+ categories = {
42
+ "category" : info ,
43
+ "tmp" : info ,
44
+ "not_a_page.md" : info ,
45
+ }
46
+ self .assertEqual (result , categories )
42
47
43
48
def test_get_categories_with_subcategories (self ):
44
- result = utils .get_categories (Path ("category" ))
49
+ result = utils .get_categories (Path (BASE_PATH , "category" ))
45
50
46
51
self .assertEqual (result , {"subcategory" : PARSED_CATEGORY_INFO })
47
52
48
53
def test_get_categories_without_subcategories (self ):
49
- result = utils .get_categories (Path ("category/subcategory" ))
54
+ result = utils .get_categories (Path (BASE_PATH , "category/subcategory" ))
50
55
51
56
self .assertEqual (result , {})
52
57
@@ -56,14 +61,14 @@ class GetCategoryPagesTests(MockPagesTestCase):
56
61
57
62
def test_get_pages_in_root_category_successfully (self ):
58
63
"""The method should successfully retrieve page metadata."""
59
- root_category_pages = utils .get_category_pages (Path ( "." ) )
64
+ root_category_pages = utils .get_category_pages (BASE_PATH )
60
65
self .assertEqual (
61
66
root_category_pages , {"root" : PARSED_METADATA , "root_without_metadata" : {}}
62
67
)
63
68
64
69
def test_get_pages_in_subcategories_successfully (self ):
65
70
"""The method should successfully retrieve page metadata."""
66
- category_pages = utils .get_category_pages (Path ("category" ))
71
+ category_pages = utils .get_category_pages (Path (BASE_PATH , "category" ))
67
72
68
73
# Page metadata is properly retrieved
69
74
self .assertEqual (category_pages , {"with_metadata" : PARSED_METADATA })
@@ -84,10 +89,10 @@ def test_get_page(self):
84
89
85
90
for msg , page_path , expected_html , expected_metadata in cases :
86
91
with self .subTest (msg = msg ):
87
- html , metadata = utils .get_page (Path (page_path ))
92
+ html , metadata = utils .get_page (Path (BASE_PATH , page_path ))
88
93
self .assertEqual (html , expected_html )
89
94
self .assertEqual (metadata , expected_metadata )
90
95
91
96
def test_get_nonexistent_page_returns_404 (self ):
92
97
with self .assertRaises (Http404 ):
93
- utils .get_page (Path ("invalid" ))
98
+ utils .get_page (Path (BASE_PATH , "invalid" ))
0 commit comments