From 62aa201a96a4977d93874cb00e415846047c958d Mon Sep 17 00:00:00 2001 From: Thiago Garcia Date: Fri, 12 Apr 2024 17:29:15 -0300 Subject: [PATCH] =?UTF-8?q?Criado=20p=C3=A1gina=20de=20detalhamento=20do?= =?UTF-8?q?=20m=C3=B3dulo=20close=20#82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypro/modulos/facade.py | 4 +++ .../templates/modulos/modulo_detalhe.html | 18 ++++++++++++ pypro/modulos/tests/test_modulo_detalhe.py | 29 +++++++++++++++++++ pypro/modulos/views.py | 5 +++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pypro/modulos/templates/modulos/modulo_detalhe.html create mode 100644 pypro/modulos/tests/test_modulo_detalhe.py diff --git a/pypro/modulos/facade.py b/pypro/modulos/facade.py index dd84fe1..44b7abe 100644 --- a/pypro/modulos/facade.py +++ b/pypro/modulos/facade.py @@ -10,3 +10,7 @@ def listar_modulos_ordenados() -> List[Modulo]: """ return list(Modulo.objects.order_by('order').all()) + + +def encontrar_modulo(slug: str) -> Modulo: + return Modulo.objects.get(slug=slug) diff --git a/pypro/modulos/templates/modulos/modulo_detalhe.html b/pypro/modulos/templates/modulos/modulo_detalhe.html new file mode 100644 index 0000000..b795fc5 --- /dev/null +++ b/pypro/modulos/templates/modulos/modulo_detalhe.html @@ -0,0 +1,18 @@ +{% extends 'base/base.html' %} +{% block title %}{{ modulo.titulo }}{% endblock title %} +{% block description %}Página com detalhes do módulo {{ modulo.titulo }}{% endblock description %} +{% block body %} +
+
+
+

{{ modulo.titulo }}

+
+
Público
+
{{ modulo.publico }}
+
Descrição
+
{{ modulo.descricao }}
+
+
+
+
+{% endblock body %} \ No newline at end of file diff --git a/pypro/modulos/tests/test_modulo_detalhe.py b/pypro/modulos/tests/test_modulo_detalhe.py new file mode 100644 index 0000000..47b2a10 --- /dev/null +++ b/pypro/modulos/tests/test_modulo_detalhe.py @@ -0,0 +1,29 @@ +from django.urls import reverse +import pytest +from pypro.django_assertions import assert_contains +from model_bakery import baker + +from pypro.modulos.models import Modulo + + +@pytest.fixture +def modulo(db): + return baker.make(Modulo) + + +@pytest.fixture +def resp(client, modulo): + resp = client.get(reverse('modulos:detalhe', kwargs={'slug': modulo.slug})) + return resp + + +def test_titulo(resp, modulo: Modulo): + assert_contains(resp, modulo.titulo) + + +def test_descricao(resp, modulo: Modulo): + assert_contains(resp, modulo.descricao) + + +def test_publico(resp, modulo: Modulo): + assert_contains(resp, modulo.publico) diff --git a/pypro/modulos/views.py b/pypro/modulos/views.py index e0e6c96..a3bda63 100644 --- a/pypro/modulos/views.py +++ b/pypro/modulos/views.py @@ -1,5 +1,8 @@ from django.shortcuts import render +from pypro.modulos import facade + def detalhe(request, slug): - pass + modulo = facade.encontrar_modulo(slug) + return render(request, 'modulos/modulo_detalhe.html', {'modulo': modulo})