diff --git a/pypro/modulos/tests/test_aula_detalhe.py b/pypro/modulos/tests/test_aula_detalhe.py index 550c410..edbab21 100644 --- a/pypro/modulos/tests/test_aula_detalhe.py +++ b/pypro/modulos/tests/test_aula_detalhe.py @@ -17,8 +17,8 @@ def aula(modulo): @pytest.fixture -def resp(client, aula): - resp = client.get(reverse('modulos:aula', kwargs={'slug': aula.slug})) +def resp(client_com_usuario_logado, aula): + resp = client_com_usuario_logado.get(reverse('modulos:aula', kwargs={'slug': aula.slug})) return resp @@ -32,3 +32,14 @@ def test_vimeo(resp, aula: Aula): def test_modulo_breadcrumb(resp, modulo: Modulo): assert_contains(resp, f'') + + +@pytest.fixture +def resp_sem_usuario(client, aula): + resp = client.get(reverse('modulos:aula', kwargs={'slug': aula.slug})) + return resp + + +def test_usuario_nao_logado_redirect(resp_sem_usuario): + assert resp_sem_usuario.status_code == 302 + assert resp_sem_usuario.url.startswith(reverse('login')) diff --git a/pypro/modulos/views.py b/pypro/modulos/views.py index 5bf6de2..85ee234 100644 --- a/pypro/modulos/views.py +++ b/pypro/modulos/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render - +from django.contrib.auth.decorators import login_required from pypro.modulos import facade @@ -14,6 +14,7 @@ def indice(request): return render(request, 'modulos/indice.html', ctx) +@login_required def aula(request, slug): aula = facade.encontrar_aula(slug) return render(request, 'modulos/aula_detalhe.html', {'aula': aula}) diff --git a/pypro/settings.py b/pypro/settings.py index 6e95de5..ca570e9 100644 --- a/pypro/settings.py +++ b/pypro/settings.py @@ -36,8 +36,8 @@ AUTH_USER_MODEL = 'base.User' +LOGIN_URL = '/contas/login/' LOGIN_REDIRECT_URL = '/modulos/' - LOGOUT_REDIRECT_URL = '/' # Application definition