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

feature/create tests for next in login #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion apps/core/views/custom_login_required_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.mixins import AccessMixin
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.urls import reverse


class CustomLoginRequiredMixin(AccessMixin):
Expand Down
6 changes: 3 additions & 3 deletions apps/ride_manager/tests/factories/passenger_factory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import factory
from faker import Faker

from apps.ride_manager.models.passenger import Passenger
from apps.ride_manager.tests.factories.person_factory import PersonFactory
from apps.ride_manager.tests.factories.ride_factory import RideFactory
from apps.ride_manager.enums.passenger_status_choices import (
PassengerStatusChoices,
)
from apps.ride_manager.models.passenger import Passenger
from apps.ride_manager.tests.factories.person_factory import PersonFactory
from apps.ride_manager.tests.factories.ride_factory import RideFactory

fake = Faker("pt_BR")

Expand Down
53 changes: 53 additions & 0 deletions apps/ride_manager/tests/views/custom_login_view_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.urls import reverse

from apps.core.tests.base_test import FAKE_CPF, BaseTest
from apps.ride_manager.tests.factories.person_factory import PersonFactory
from apps.ride_manager.tests.factories.ride_factory import RideFactory


class CustomLoginViewTests(BaseTest):
Expand Down Expand Up @@ -70,3 +72,54 @@ def test_login_invalid_password(self):
# Then
self.assertEqual(response.status_code, 200)
self.assertIn(expected_message, response.content.decode())

def test_login_redirects_to_next(self):
# Given
cpf = FAKE_CPF
password = "testpassword"
next_url = reverse("my_rides")
url = f"{self.url}?next={next_url}"

# When
response = self.view_unauth_client.post(
url,
data={"cpf": cpf, "password": password},
)

# Then
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, next_url)

def test_login_redirects_to_home(self):
# Given
cpf = FAKE_CPF
password = "testpassword"

# When
response = self.view_unauth_client.post(
self.url,
data={"cpf": cpf, "password": password},
)

# Then
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("home"))

def test_login_redirects_to_detail_ride_view(self):
# Given
person = PersonFactory(user=self.user)
ride = RideFactory(driver=person)
cpf = FAKE_CPF
password = "testpassword"
next_url = reverse("ride_detail", args=[ride.uuid])
url = f"{self.url}?next={next_url}"

# When
response = self.view_unauth_client.post(
url,
data={"cpf": cpf, "password": password},
)

# Then
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, next_url)
6 changes: 3 additions & 3 deletions apps/ride_manager/tests/views/home_view_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from django.urls import reverse

from apps.core.tests.base_test import BaseTest
from apps.ride_manager.tests.factories.passenger_factory import PassengerFactory
from apps.ride_manager.tests.factories.person_factory import PersonFactory
from apps.ride_manager.tests.factories.ride_factory import RideFactory
from apps.ride_manager.enums.passenger_status_choices import (
PassengerStatusChoices,
)
from apps.ride_manager.tests.factories.passenger_factory import PassengerFactory
from apps.ride_manager.tests.factories.person_factory import PersonFactory
from apps.ride_manager.tests.factories.ride_factory import RideFactory


class HomeViewTests(BaseTest):
Expand Down
2 changes: 2 additions & 0 deletions apps/ride_manager/views/custom_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ class CustomLoginView(LoginView):

def get_success_url(self):
self.request.session["show_caution_modal"] = True
if self.request.GET.get("next"):
return self.request.GET.get("next")
return reverse_lazy("home")