-
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 or update
- Loading branch information
1 parent
23d1386
commit c5387b7
Showing
3 changed files
with
71 additions
and
0 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
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 | ||
|