Skip to content

Commit

Permalink
Limitado o acesso às aulas com o decorator "login_required"
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspdf committed Nov 21, 2023
1 parent 7f273e1 commit f57891e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions pypro/modulos/tests/test_aula_detalhe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -32,3 +32,14 @@ def test_vimeo(resp, aula: Aula):

def test_modulo_breadcrumb(resp, modulo: Modulo):
assert_contains(resp, f'<li class="breadcrumb-item"><a href="{modulo.get_absolute_url()}">{modulo.titulo}</a></li>')


@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'))
3 changes: 2 additions & 1 deletion pypro/modulos/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render

from django.contrib.auth.decorators import login_required
from pypro.modulos import facade


Expand All @@ -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})
2 changes: 1 addition & 1 deletion pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

AUTH_USER_MODEL = 'base.User'

LOGIN_URL = '/contas/login/'
LOGIN_REDIRECT_URL = '/modulos/'

LOGOUT_REDIRECT_URL = '/'

# Application definition
Expand Down

0 comments on commit f57891e

Please sign in to comment.