-
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.
update EmailLastSeen on Topic/Post create, we do not track updates
- Loading branch information
1 parent
f981573
commit 7c972f3
Showing
4 changed files
with
82 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -27,7 +27,9 @@ | |
from lacommunaute.forum_moderation.factories import BlockedDomainNameFactory, BlockedEmailFactory | ||
from lacommunaute.forum_upvote.factories import UpVoteFactory | ||
from lacommunaute.notification.factories import NotificationFactory | ||
from lacommunaute.users.enums import EmailLastSeenKind | ||
from lacommunaute.users.factories import UserFactory | ||
from lacommunaute.users.models import EmailLastSeen | ||
from lacommunaute.utils.testing import parse_response_to_soup | ||
|
||
|
||
|
@@ -39,6 +41,12 @@ | |
assign_perm = get_class("forum_permission.shortcuts", "assign_perm") | ||
|
||
|
||
def check_email_last_seen(email): | ||
return EmailLastSeen.objects.filter( | ||
email=email, last_seen_kind__in=[EmailLastSeenKind.POST, EmailLastSeenKind.LOGGED] | ||
).exists() | ||
|
||
|
||
class TopicCreateViewTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
|
@@ -116,6 +124,8 @@ def test_topic_create_as_anonymous_user(self, *args): | |
self.assertTrue(topic.approved) | ||
self.assertTrue(topic.first_post.approved) | ||
|
||
self.assertTrue(check_email_last_seen(self.post_data["username"])) | ||
|
||
def test_topic_create_as_unapproved_anonymous_user(self, *args): | ||
self.post_data["username"] = faker.email() | ||
BlockedEmailFactory(email=self.post_data["username"]) | ||
|
@@ -133,6 +143,8 @@ def test_topic_create_as_unapproved_anonymous_user(self, *args): | |
) | ||
self.assertEqual(Topic.objects.count(), 0) | ||
|
||
self.assertFalse(check_email_last_seen(self.post_data["username"])) | ||
|
||
def test_topic_create_with_nonfr_content(self, *args): | ||
self.client.force_login(self.poster) | ||
self.post_data["content"] = "популярные лучшие песни слушать онлайн" | ||
|
@@ -183,6 +195,8 @@ def test_topic_create_as_anonymous_user_with_blocked_domain_name(self, *args): | |
) | ||
self.assertEqual(Topic.objects.count(), 0) | ||
|
||
self.assertFalse(check_email_last_seen(self.post_data["username"])) | ||
|
||
def test_topic_create_as_authenticated_user(self, *args): | ||
self.client.force_login(self.poster) | ||
|
||
|
@@ -196,6 +210,8 @@ def test_topic_create_as_authenticated_user(self, *args): | |
self.assertTrue(Topic.objects.first().approved) | ||
self.assertTrue(Topic.objects.first().posts.first().approved) | ||
|
||
self.assertTrue(check_email_last_seen(self.poster.email)) | ||
|
||
def test_tags_checkbox_are_displayed(self, *args): | ||
Tag.objects.bulk_create([Tag(name=f"tag_x{i}", slug=f"tag_x{i}") for i in range(2)]) | ||
self.client.force_login(self.poster) | ||
|
@@ -329,6 +345,7 @@ def test_selected_tags_are_checked(self): | |
|
||
def test_update_by_anonymous_user(self): | ||
topic = AnonymousTopicFactory(with_post=True, forum=self.forum) | ||
EmailLastSeen.objects.all().delete() | ||
session = self.client.session | ||
session["_anonymous_forum_key"] = topic.first_post.anonymous_key | ||
session.save() | ||
|
@@ -359,6 +376,9 @@ def test_update_by_anonymous_user(self): | |
), | ||
) | ||
|
||
self.assertFalse(check_email_last_seen("[email protected]")) | ||
self.assertFalse(check_email_last_seen(topic.first_post.username)) | ||
|
||
def test_topic_update_with_nonfr_content(self, *args): | ||
self.client.force_login(self.poster) | ||
post_data = {"subject": "s", "content": "популярные лучшие песни слушать онлайн"} | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import pytest | ||
from django.conf import settings | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.test import RequestFactory, TestCase | ||
|
@@ -6,6 +7,7 @@ | |
from machina.core.db.models import get_model | ||
from machina.core.loading import get_class | ||
|
||
from lacommunaute.forum.factories import ForumFactory | ||
from lacommunaute.forum_conversation.factories import CertifiedPostFactory, PostFactory, TopicFactory | ||
from lacommunaute.forum_conversation.forms import PostForm | ||
from lacommunaute.forum_conversation.models import CertifiedPost, Topic | ||
|
@@ -15,7 +17,9 @@ | |
from lacommunaute.forum_moderation.models import BlockedPost | ||
from lacommunaute.forum_upvote.factories import UpVoteFactory | ||
from lacommunaute.notification.factories import NotificationFactory | ||
from lacommunaute.users.enums import EmailLastSeenKind | ||
from lacommunaute.users.factories import UserFactory | ||
from lacommunaute.users.models import EmailLastSeen | ||
|
||
|
||
faker = Faker(settings.LANGUAGE_CODE) | ||
|
@@ -424,6 +428,33 @@ def test_create_post_with_blocked_domain_name(self): | |
assert blocked_post.block_reason == BlockedPostReason.BLOCKED_DOMAIN | ||
|
||
|
||
class TestPostFeedCreateView: | ||
@pytest.mark.parametrize("logged", [True, False]) | ||
def test_email_last_seen_is_updated(self, client, db, logged): | ||
topic = TopicFactory(with_post=True, forum=ForumFactory(with_public_perms=True)) | ||
url = reverse( | ||
"forum_conversation_extension:post_create", | ||
kwargs={ | ||
"forum_pk": topic.forum.pk, | ||
"forum_slug": topic.forum.slug, | ||
"pk": topic.pk, | ||
"slug": topic.slug, | ||
}, | ||
) | ||
data = {"content": faker.paragraph(nb_sentences=5)} | ||
|
||
if logged: | ||
client.force_login(topic.poster) | ||
else: | ||
data["username"] = "[email protected]" | ||
|
||
response = client.post(url, data=data) | ||
assert response.status_code == 200 | ||
|
||
email = topic.poster.email if logged else data["username"] | ||
assert EmailLastSeen.objects.filter(email=email, last_seen_kind=EmailLastSeenKind.POST).exists() | ||
|
||
|
||
# vincentporte : not to futur self, rewrite it in pytest style | ||
class CertifiedPostViewTest(TestCase): | ||
@classmethod | ||
|