55
66from pythonpro .django_assertions import dj_assert_contains , dj_assert_not_contains , dj_assert_template_used
77from pythonpro .modules import facade
8- from pythonpro .modules .models import Chapter , Module , Section
8+ from pythonpro .modules .models import Chapter , Module , Section , Topic
99
1010
1111def generate_resp (slug , client ):
@@ -97,10 +97,10 @@ def python_birds(modules):
9797
9898@pytest .fixture
9999def resp_with_sections (client_with_lead , sections , python_birds ):
100- return _resp_with_sections (client_with_lead , sections , python_birds )
100+ return _resp_module_detail (client_with_lead , python_birds )
101101
102102
103- def _resp_with_sections (client_with_lead , sections , python_birds ):
103+ def _resp_module_detail (client_with_lead , python_birds ):
104104 """Plain function to avoid _pytest.warning_types.RemovedInPytest4Warning: Fixture "resp" called directly."""
105105 return client_with_lead .get (reverse ('modules:detail' , kwargs = {'slug' : python_birds .slug }))
106106
@@ -125,7 +125,7 @@ def chapters(sections):
125125
126126@pytest .fixture
127127def resp_with_chapters (client_with_lead , python_birds , sections , chapters ):
128- return _resp_with_sections (client_with_lead , sections , python_birds )
128+ return _resp_module_detail (client_with_lead , python_birds )
129129
130130
131131def test_chapter_titles (resp_with_chapters , chapters ):
@@ -143,3 +143,26 @@ def test_enrol_user_tags(python_birds, client_with_lead, mocker, logged_user):
143143 resp = client_with_lead .get (reverse ('modules:enrol' , kwargs = {'slug' : python_birds .slug }))
144144 tag_as .assert_called_once_with (logged_user .email , logged_user .id , python_birds .slug )
145145 assert resp .status_code == 200
146+
147+
148+ @pytest .fixture
149+ def topics (chapters ):
150+ result = []
151+ for chapter in chapters :
152+ result .extend (baker .make (Topic , 2 , chapter = chapter ))
153+ return result
154+
155+
156+ @pytest .fixture
157+ def resp_with_topics (client_with_lead , python_birds , topics ):
158+ return _resp_module_detail (client_with_lead , python_birds )
159+
160+
161+ def test_topic_titles (resp_with_topics , topics ):
162+ for topic in topics :
163+ dj_assert_contains (resp_with_topics , topic .title )
164+
165+
166+ def test_topic_urls (resp_with_topics , topics ):
167+ for topic in topics :
168+ dj_assert_contains (resp_with_topics , topic .get_absolute_url ())
0 commit comments