mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-04-20 21:20:59 +00:00
Added more tests to querysets
This commit is contained in:
parent
85e18811f0
commit
d971ce44e8
1 changed files with 129 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import pytest
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import override_settings
|
||||
from swapper import load_model
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ def test_sent_unsent_methods(emailed, method):
|
|||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_query_read_unread_methods(read, method):
|
||||
def test_read_unread_methods(read, method):
|
||||
NotificationFactory.create_batch(3, unread=read)
|
||||
assert method().count() == 3
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ def test_query_read_unread_methods(read, method):
|
|||
)
|
||||
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
|
||||
@pytest.mark.django_db
|
||||
def test_query_read_unread_with_deleted_notifications(read, method):
|
||||
def test_read_unread_with_deleted_notifications(read, method):
|
||||
NotificationFactory.create_batch(3, unread=read)
|
||||
assert method().count() == 3
|
||||
|
||||
|
|
@ -114,3 +115,129 @@ def test_mark_all_as_read_unread_with_recipient(status, method, check_method):
|
|||
|
||||
method(recipient=recipient)
|
||||
assert check_method().count() == 2
|
||||
|
||||
|
||||
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
|
||||
@pytest.mark.parametrize(
|
||||
"deleted,method",
|
||||
(
|
||||
(True, Notification.objects.deleted),
|
||||
(False, Notification.objects.active),
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_deleted_active_methods(deleted, method):
|
||||
NotificationFactory.create_batch(3, deleted=deleted)
|
||||
assert method().count() == 3
|
||||
|
||||
first_notification = Notification.objects.first()
|
||||
first_notification.deleted = not deleted
|
||||
first_notification.save()
|
||||
assert method().count() == 2
|
||||
|
||||
Notification.objects.all().update(deleted=not deleted)
|
||||
assert method().count() == 0
|
||||
|
||||
first_notification.deleted = deleted
|
||||
first_notification.save()
|
||||
assert method().count() == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method",
|
||||
(
|
||||
Notification.objects.deleted,
|
||||
Notification.objects.active,
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_deleted_active_methods_without_soft_delete(method):
|
||||
with pytest.raises(ImproperlyConfigured):
|
||||
assert method()
|
||||
|
||||
|
||||
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
|
||||
@pytest.mark.parametrize(
|
||||
"status,method,check_method",
|
||||
(
|
||||
(False, Notification.objects.mark_all_as_deleted, Notification.objects.deleted),
|
||||
(True, Notification.objects.mark_all_as_active, Notification.objects.active),
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_mark_all_as_deleted_active(status, method, check_method):
|
||||
NotificationFactory.create_batch(3, deleted=status)
|
||||
assert Notification.objects.count() == 3
|
||||
assert check_method().count() == 0
|
||||
|
||||
method()
|
||||
assert check_method().count() == 3
|
||||
|
||||
|
||||
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
|
||||
@pytest.mark.parametrize(
|
||||
"status,method,check_method",
|
||||
(
|
||||
(False, Notification.objects.mark_all_as_deleted, Notification.objects.deleted),
|
||||
(True, Notification.objects.mark_all_as_active, Notification.objects.active),
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_mark_all_as_deleted_active_with_recipient(status, method, check_method):
|
||||
recipient = Recipient()
|
||||
NotificationFactory.create_batch(2, deleted=status, recipient=recipient)
|
||||
NotificationFactory.create_batch(1, deleted=status)
|
||||
assert Notification.objects.count() == 3
|
||||
assert check_method().count() == 0
|
||||
|
||||
method(recipient=recipient)
|
||||
assert check_method().count() == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method",
|
||||
(
|
||||
Notification.objects.mark_all_as_deleted,
|
||||
Notification.objects.mark_all_as_active,
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_mark_all_as_deleted_active_without_soft_delete(method):
|
||||
with pytest.raises(ImproperlyConfigured):
|
||||
method()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"status,method,check_method",
|
||||
(
|
||||
(False, Notification.objects.mark_as_sent, Notification.objects.sent),
|
||||
(True, Notification.objects.mark_as_unsent, Notification.objects.unsent),
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_mark_as_sent_unsent_method(status, method, check_method):
|
||||
NotificationFactory.create_batch(3, emailed=status)
|
||||
assert Notification.objects.count() == 3
|
||||
assert check_method().count() == 0
|
||||
|
||||
method()
|
||||
assert check_method().count() == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"status,method,check_method",
|
||||
(
|
||||
(False, Notification.objects.mark_as_sent, Notification.objects.sent),
|
||||
(True, Notification.objects.mark_as_unsent, Notification.objects.unsent),
|
||||
),
|
||||
)
|
||||
@pytest.mark.django_db
|
||||
def test_mark_as_sent_unsent_with_recipient(status, method, check_method):
|
||||
recipient = Recipient()
|
||||
NotificationFactory.create_batch(2, emailed=status, recipient=recipient)
|
||||
NotificationFactory.create_batch(1, emailed=status)
|
||||
assert Notification.objects.count() == 3
|
||||
assert check_method().count() == 0
|
||||
|
||||
method(recipient=recipient)
|
||||
assert check_method().count() == 2
|
||||
|
|
|
|||
Loading…
Reference in a new issue