Skip to content

Instantly share code, notes, and snippets.

@v1k45
Last active March 24, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v1k45/e056b530bd86a725735b to your computer and use it in GitHub Desktop.
Save v1k45/e056b530bd86a725735b to your computer and use it in GitHub Desktop.
tests for checking if issue #24 on django-notify-x is reproducible
from django.test import TestCase
from notify.signals import notify
from notify.models import Notification
from django.contrib.auth.models import User
from .models import Post
class NotificationCreateTestCase(TestCase):
def setUp(self):
self.user = User.objects.create_user(email='usr@usr.com',
username='usr',
password='usrpw')
self.assertTrue(User.objects.filter(username='usr').exists())
def test_notifications_created_without_target(self):
initial_notifications = Notification.objects.all()
self.assertEqual(initial_notifications.count(), 0)
for i in range(1000):
notify.send(User, recipient=self.user, actor_text='Actor',
verb='followed you')
updated_notifications = Notification.objects.all()
self.assertEqual(updated_notifications.count(), 1000)
def test_notifications_created_with_target(self):
initial_notifications = Notification.objects.all()
self.assertEqual(initial_notifications.count(), 0)
target = Post.objects.create(title='example title',
entry='example entry')
for i in range(1000):
notify.send(User, recipient=self.user, actor_text='Actor',
verb='followed you', target=target)
updated_notifications = Notification.objects.all()
self.assertEqual(updated_notifications.count(), 1000)
def test_notifications_created_with_target_and_actor(self):
initial_notifications = Notification.objects.all()
self.assertEqual(initial_notifications.count(), 0)
target = Post.objects.create(title='example title',
entry='example entry')
actor = User.objects.create_user(username='actor',
email='kewl@actor.com',
password='notsostrongpassword')
for i in range(1000):
notify.send(User, recipient=self.user, actor=actor,
verb='followed you', target=target)
updated_notifications = Notification.objects.all()
self.assertEqual(updated_notifications.count(), 1000)
def test_notifications_created_with_actor_and_same_target_and_obj(self):
initial_notifications = Notification.objects.all()
self.assertEqual(initial_notifications.count(), 0)
target = Post.objects.create(title='example title',
entry='example entry')
actor = User.objects.create_user(username='actor',
email='kewl@actor.com',
password='notsostrongpassword')
for i in range(1000):
notify.send(User, recipient=self.user, actor=actor,
verb='followed you', target=target,
obj=target)
updated_notifications = Notification.objects.all()
self.assertEqual(updated_notifications.count(), 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment