Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pythonpro/modules/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.db.models import Prefetch as _Prefetch
from django.urls import reverse


from pythonpro.modules.models import (
Chapter as _Chapter, Module as _Module, Section as _Section, Topic as _Topic,
)
Expand Down Expand Up @@ -50,7 +49,13 @@ def get_module_with_contents(slug):
queryset=_Section.objects.order_by('order').prefetch_related(
_Prefetch(
'chapter_set',
queryset=_Chapter.objects.order_by('order'),
queryset=_Chapter.objects.order_by('order').prefetch_related(
_Prefetch(
'topic_set',
queryset=_Topic.objects.order_by(
'order'),
to_attr='topics')
),
to_attr='chapters'
)
),
Expand Down Expand Up @@ -141,13 +146,13 @@ def get_tree(module):
sections = list(_Section.objects.filter(module=module).order_by('order').prefetch_related(
_Prefetch(
'chapter_set',
queryset=_Chapter.objects.order_by(
'order').prefetch_related(
queryset=_Chapter.objects.order_by('order').prefetch_related(
_Prefetch(
'topic_set',
queryset=_Topic.objects.order_by(
'order'),
to_attr='topics')),
to_attr='topics')
),
to_attr='chapters')))
module.sections = sections
return sections
Expand Down
17 changes: 14 additions & 3 deletions pythonpro/modules/templates/modules/module_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h1 class="mt-4 mb-3">{{ module.title }}</h1>
<dt>Duração: 4 semanas</dt>
<dd>
<ul>
<li><a class="btn-success btn" href="{% url 'modules:enrol' slug=module.slug %}">Quero receber minhas metas por email &raquo;</a></li>
<li><a class="btn-success btn" href="{% url 'modules:enrol' slug=module.slug %}">Quero
receber minhas metas por email &raquo;</a></li>
</ul>
</dd>
{% endif %}
Expand All @@ -44,15 +45,25 @@ <h1 class="mt-4 mb-3">{{ module.title }}</h1>
<ol>
{% for chapter in section.chapters %}
<li><a href="{{ chapter.get_absolute_url }}">{{ chapter.title }}</a></li>
<dd>
<ol>
{% for topic in chapter.topics %}
<li><a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a>
</li>
{% empty %}
<li>Nenhum Capítulo definido ainda</li>
{% endfor %}
</ol>
</dd>
{% empty %}
<li>Nenhum Capítulo definido ainda</li>
{% endfor %}
</ol>
</ol>
</dd>
{% empty %}
<li>Nenhuma seção definida ainda</li>
{% endfor %}
</ol>
</ol>
</dd>
</div>
</div>
Expand Down
31 changes: 27 additions & 4 deletions pythonpro/modules/tests/test_module_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains, dj_assert_template_used
from pythonpro.modules import facade
from pythonpro.modules.models import Chapter, Module, Section
from pythonpro.modules.models import Chapter, Module, Section, Topic


def generate_resp(slug, client):
Expand Down Expand Up @@ -97,10 +97,10 @@ def python_birds(modules):

@pytest.fixture
def resp_with_sections(client_with_lead, sections, python_birds):
return _resp_with_sections(client_with_lead, sections, python_birds)
return _resp_module_detail(client_with_lead, python_birds)


def _resp_with_sections(client_with_lead, sections, python_birds):
def _resp_module_detail(client_with_lead, python_birds):
"""Plain function to avoid _pytest.warning_types.RemovedInPytest4Warning: Fixture "resp" called directly."""
return client_with_lead.get(reverse('modules:detail', kwargs={'slug': python_birds.slug}))

Expand All @@ -125,7 +125,7 @@ def chapters(sections):

@pytest.fixture
def resp_with_chapters(client_with_lead, python_birds, sections, chapters):
return _resp_with_sections(client_with_lead, sections, python_birds)
return _resp_module_detail(client_with_lead, python_birds)


def test_chapter_titles(resp_with_chapters, chapters):
Expand All @@ -143,3 +143,26 @@ def test_enrol_user_tags(python_birds, client_with_lead, mocker, logged_user):
resp = client_with_lead.get(reverse('modules:enrol', kwargs={'slug': python_birds.slug}))
tag_as.assert_called_once_with(logged_user.email, logged_user.id, python_birds.slug)
assert resp.status_code == 200


@pytest.fixture
def topics(chapters):
result = []
for chapter in chapters:
result.extend(baker.make(Topic, 2, chapter=chapter))
return result


@pytest.fixture
def resp_with_topics(client_with_lead, python_birds, topics):
return _resp_module_detail(client_with_lead, python_birds)


def test_topic_titles(resp_with_topics, topics):
for topic in topics:
dj_assert_contains(resp_with_topics, topic.title)


def test_topic_urls(resp_with_topics, topics):
for topic in topics:
dj_assert_contains(resp_with_topics, topic.get_absolute_url())