Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criados botões de login e logout close #49 #50

Merged
merged 1 commit into from
Nov 21, 2023
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
20 changes: 18 additions & 2 deletions pypro/base/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
<button aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler"
data-target="#navbarSupportedContent" data-toggle="collapse" type="button">
<span class="navbar-toggler-icon"></span>

</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#"
id="navbarDropdown" role="button">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Módulos
</a>
<div aria-labelledby="navbarDropdown" class="dropdown-menu">
Expand All @@ -40,6 +41,21 @@
</div>
</li>
</ul>
{% if user.is_authenticated %}
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{{ user.first_name }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<button type="button" class="dropdown-item">Sair</button>
</div>
</li>
</ul>
{% else %}
<a class="btn btn-light my-2" href="{% url 'login' %}">Entrar</a>
{% endif %}
</div>
</nav>

Expand Down
36 changes: 36 additions & 0 deletions pypro/base/tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.urls import reverse
from model_mommy import mommy

from pypro.django_assertions import assert_contains, assert_not_contains


@pytest.fixture
def resp(client, db):
Expand Down Expand Up @@ -30,3 +32,37 @@ def resp_post(client, usuario):
def test_login_redirect(resp_post):
assert resp_post.status_code == 302
assert resp_post.url == reverse('modulos:indice')


@pytest.fixture
def resp_home(client, db):
return client.get(reverse('base:home'))


def test_botao_entrar_disponivel(resp_home):
assert_contains(resp_home, 'Entrar')


def test_link_de_login_disponivel(resp_home):
assert_contains(resp_home, reverse('login'))


@pytest.fixture
def resp_home_com_usuario_logado(client_com_usuario_logado, db):
return client_com_usuario_logado.get(reverse('base:home'))


def test_botao_entrar_indisponivel(resp_home_com_usuario_logado):
assert_not_contains(resp_home_com_usuario_logado, 'Entrar')


def test_link_de_login_indisponivel(resp_home_com_usuario_logado):
assert_not_contains(resp_home_com_usuario_logado, reverse('login'))


def test_botao_sair_disponivel(resp_home_com_usuario_logado):
assert_contains(resp_home_com_usuario_logado, 'Sair')


def test_nome_usuario_logado_disponivel(resp_home_com_usuario_logado, usuario_logado):
assert_contains(resp_home_com_usuario_logado, usuario_logado.first_name)
14 changes: 14 additions & 0 deletions pypro/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from model_mommy import mommy


@pytest.fixture
def usuario_logado(db, django_user_model):
usuario_modelo = mommy.make(django_user_model, first_name='Fulano')
return usuario_modelo


@pytest.fixture
def client_com_usuario_logado(usuario_logado, client):
client.force_login(usuario_logado)
return client
1 change: 1 addition & 0 deletions pypro/django_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
_test_case = TestCase()

assert_contains = _test_case.assertContains
assert_not_contains = _test_case.assertNotContains
Loading