|
@@ -7,9 +7,11 @@ from django.urls import reverse
|
|
from django.utils import timezone
|
|
from django.utils import timezone
|
|
from django.utils.encoding import smart_str
|
|
from django.utils.encoding import smart_str
|
|
|
|
|
|
-from misago.acl.testutils import override_acl
|
|
|
|
from misago.categories.models import Category
|
|
from misago.categories.models import Category
|
|
from misago.threads import testutils
|
|
from misago.threads import testutils
|
|
|
|
+from misago.threads.test import (
|
|
|
|
+ patch_category_acl, patch_other_user_category_acl
|
|
|
|
+)
|
|
from misago.users.testutils import AuthenticatedUserTestCase
|
|
from misago.users.testutils import AuthenticatedUserTestCase
|
|
|
|
|
|
|
|
|
|
@@ -25,7 +27,6 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
category=self.category,
|
|
category=self.category,
|
|
started_on=timezone.now() - timedelta(seconds=5),
|
|
started_on=timezone.now() - timedelta(seconds=5),
|
|
)
|
|
)
|
|
- self.override_acl()
|
|
|
|
|
|
|
|
self.api_link = reverse(
|
|
self.api_link = reverse(
|
|
'misago:api:thread-post-list', kwargs={
|
|
'misago:api:thread-post-list', kwargs={
|
|
@@ -33,37 +34,9 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
- self.other_user = UserModel.objects.create_user('Bob', 'bob@boberson.com', 'pass123')
|
|
|
|
-
|
|
|
|
- def override_acl(self):
|
|
|
|
- new_acl = deepcopy(self.user.acl_cache)
|
|
|
|
- new_acl['categories'][self.category.pk].update({
|
|
|
|
- 'can_see': 1,
|
|
|
|
- 'can_browse': 1,
|
|
|
|
- 'can_start_threads': 1,
|
|
|
|
- 'can_reply_threads': 1,
|
|
|
|
- 'can_edit_posts': 1,
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- override_acl(self.user, new_acl)
|
|
|
|
-
|
|
|
|
- def override_other_user_acl(self, hide=False):
|
|
|
|
- new_acl = deepcopy(self.other_user.acl_cache)
|
|
|
|
- new_acl['categories'][self.category.pk].update({
|
|
|
|
- 'can_see': 1,
|
|
|
|
- 'can_browse': 1,
|
|
|
|
- 'can_start_threads': 1,
|
|
|
|
- 'can_reply_threads': 1,
|
|
|
|
- 'can_edit_posts': 1,
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- if hide:
|
|
|
|
- new_acl['categories'][self.category.pk].update({
|
|
|
|
- 'can_browse': False,
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- override_acl(self.other_user, new_acl)
|
|
|
|
|
|
+ self.other_user = UserModel.objects.create_user('BobBobertson', 'bob@boberson.com')
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_no_subscriptions(self):
|
|
def test_no_subscriptions(self):
|
|
"""no emails are sent because noone subscibes to thread"""
|
|
"""no emails are sent because noone subscibes to thread"""
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
@@ -75,6 +48,7 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_poster_not_notified(self):
|
|
def test_poster_not_notified(self):
|
|
"""no emails are sent because only poster subscribes to thread"""
|
|
"""no emails are sent because only poster subscribes to thread"""
|
|
self.user.subscription_set.create(
|
|
self.user.subscription_set.create(
|
|
@@ -93,6 +67,7 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_other_user_no_email_subscription(self):
|
|
def test_other_user_no_email_subscription(self):
|
|
"""no emails are sent because subscriber has e-mails off"""
|
|
"""no emails are sent because subscriber has e-mails off"""
|
|
self.other_user.subscription_set.create(
|
|
self.other_user.subscription_set.create(
|
|
@@ -111,6 +86,8 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
|
|
+ @patch_other_user_category_acl({"can_see": False})
|
|
def test_other_user_no_permission(self):
|
|
def test_other_user_no_permission(self):
|
|
"""no emails are sent because subscriber has no permission to read thread"""
|
|
"""no emails are sent because subscriber has no permission to read thread"""
|
|
self.other_user.subscription_set.create(
|
|
self.other_user.subscription_set.create(
|
|
@@ -119,7 +96,6 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
last_read_on=timezone.now(),
|
|
last_read_on=timezone.now(),
|
|
send_email=True,
|
|
send_email=True,
|
|
)
|
|
)
|
|
- self.override_other_user_acl(hide=True)
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.api_link, data={
|
|
self.api_link, data={
|
|
@@ -130,6 +106,29 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
|
|
+ def test_moderation_queue(self):
|
|
|
|
+ """no emails are sent because new post is moderated"""
|
|
|
|
+ self.category.require_replies_approval = True
|
|
|
|
+ self.category.save()
|
|
|
|
+
|
|
|
|
+ self.other_user.subscription_set.create(
|
|
|
|
+ thread=self.thread,
|
|
|
|
+ category=self.category,
|
|
|
|
+ last_read_on=timezone.now(),
|
|
|
|
+ send_email=True,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ self.api_link, data={
|
|
|
|
+ 'post': 'This is test response!',
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
+
|
|
|
|
+ self.assertEqual(len(mail.outbox), 0)
|
|
|
|
+
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_other_user_not_read(self):
|
|
def test_other_user_not_read(self):
|
|
"""no emails are sent because subscriber didn't read previous post"""
|
|
"""no emails are sent because subscriber didn't read previous post"""
|
|
self.other_user.subscription_set.create(
|
|
self.other_user.subscription_set.create(
|
|
@@ -138,7 +137,6 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
last_read_on=timezone.now(),
|
|
last_read_on=timezone.now(),
|
|
send_email=True,
|
|
send_email=True,
|
|
)
|
|
)
|
|
- self.override_other_user_acl()
|
|
|
|
|
|
|
|
testutils.reply_thread(self.thread, posted_on=timezone.now())
|
|
testutils.reply_thread(self.thread, posted_on=timezone.now())
|
|
|
|
|
|
@@ -151,6 +149,7 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_other_notified(self):
|
|
def test_other_notified(self):
|
|
"""email is sent to subscriber"""
|
|
"""email is sent to subscriber"""
|
|
self.other_user.subscription_set.create(
|
|
self.other_user.subscription_set.create(
|
|
@@ -159,7 +158,6 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
last_read_on=timezone.now(),
|
|
last_read_on=timezone.now(),
|
|
send_email=True,
|
|
send_email=True,
|
|
)
|
|
)
|
|
- self.override_other_user_acl()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.api_link, data={
|
|
self.api_link, data={
|
|
@@ -183,6 +181,7 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
last_post = self.thread.post_set.order_by('id').last()
|
|
last_post = self.thread.post_set.order_by('id').last()
|
|
self.assertIn(last_post.get_absolute_url(), message)
|
|
self.assertIn(last_post.get_absolute_url(), message)
|
|
|
|
|
|
|
|
+ @patch_category_acl({"can_reply_threads": True})
|
|
def test_other_notified_after_reading(self):
|
|
def test_other_notified_after_reading(self):
|
|
"""email is sent to subscriber that had sub updated by read api"""
|
|
"""email is sent to subscriber that had sub updated by read api"""
|
|
self.other_user.subscription_set.create(
|
|
self.other_user.subscription_set.create(
|
|
@@ -191,7 +190,6 @@ class EmailNotificationTests(AuthenticatedUserTestCase):
|
|
last_read_on=self.thread.last_post_on,
|
|
last_read_on=self.thread.last_post_on,
|
|
send_email=True,
|
|
send_email=True,
|
|
)
|
|
)
|
|
- self.override_other_user_acl()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.api_link, data={
|
|
self.api_link, data={
|