-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05e6c36
commit 334f141
Showing
3 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from django.urls import reverse | ||
from machina.core.loading import get_class | ||
from pytest_django.asserts import assertContains, assertNotContains | ||
|
||
from django.core import mail | ||
from lacommunaute.forum_member.factories import ForumProfileFactory | ||
from lacommunaute.forum_member.models import ForumProfile | ||
from lacommunaute.forum_member.shortcuts import get_forum_member_display_name | ||
|
@@ -16,6 +16,7 @@ | |
from django.utils.encoding import force_bytes | ||
from django.utils.http import urlsafe_base64_encode | ||
from django.contrib.auth.tokens import default_token_generator | ||
from lacommunaute.forum_member.views import send_magic_link | ||
|
||
PermissionHandler = get_class("forum_permission.handler", "PermissionHandler") | ||
assign_perm = get_class("forum_permission.shortcuts", "assign_perm") | ||
|
@@ -71,6 +72,29 @@ def test_show_linkedin_link(self, client, db): | |
assertContains(response, forum_profile.linkedin) | ||
|
||
|
||
class TestSendMagicLink: | ||
def test_send_magic_link(self, client, db, snapshot): | ||
user = UserFactory(first_name="Samuel", last_name="Jackson") | ||
next_url = "/topics/" | ||
send_magic_link(client, user, next_url) | ||
|
||
assert len(mail.outbox) == 1 | ||
email = mail.outbox[0] | ||
assert email.subject == "Votre lien pour vous connecter à la communauté de l'inclusion" | ||
assert email.to == [user.email] | ||
assert email.from_email == "[email protected]" | ||
|
||
expected_magic_link = reverse( | ||
"members:login_with_link", | ||
kwargs={ | ||
"uidb64": urlsafe_base64_encode(force_bytes(user.pk)), | ||
"token": default_token_generator.make_token(user), | ||
}, | ||
) | ||
assert expected_magic_link in email.body | ||
assert email.body.replace(expected_magic_link, "MAGIC_LINK") == snapshot(name="send_magic_link_email_body") | ||
|
||
|
||
class TestLoginView: | ||
@pytest.mark.parametrize("next", [None, "/", "/topics/"]) | ||
def test_content(self, client, db, next, snapshot): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters