def test_realtime_notification(self):
        """
        User A creates a Foo, so should not receive a notification
        User B is online and should receive the notification
        User C is subscribed but currently showing as offline
        """
        connection_a = TestConnection(user=self.user_a)
        connection_b = TestConnection(user=self.user_b)
        connection_c = TestConnection(user=self.user_c)

        connection_a.subscribe('swampdragon-notifications', 'notifications',
                               {})
        connection_b.subscribe('swampdragon-notifications', 'notifications',
                               {})
        connection_c.subscribe('swampdragon-notifications', 'notifications',
                               {})

        # User C drops offline
        user_manager.remove_user(self.user_c.pk)
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users(User.objects.exclude(pk=self.user_a.pk),
                     foo,
                     notification_type='foo')

        self.assertIsNotNone(connection_b.last_pub)
        self.assertIsNone(connection_a.last_pub)
        self.assertIsNone(connection_c.last_pub)
 def test_notify_users(self):
     """
     Send one email to user a
     """
     foo = Foo.objects.create(name='foo', description='foo object')
     notify_users(User.objects.all(), foo, notification_type='foo')
     self.assertEqual(len(mail.outbox), 2)
 def test_notify_users(self):
     """
     Send one email to user a
     """
     foo = Foo.objects.create(name='foo', description='foo object')
     notify_users(User.objects.all(), foo, notification_type='foo')
     self.assertEqual(len(mail.outbox), 2)
    def test_notify_users(self):
        """
        Send a notification to each user
        """
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users(User.objects.all(), foo, notification_type='foo')

        self.assertTrue(Notification.objects.filter(user=self.user_a).exists())
        self.assertTrue(Notification.objects.filter(user=self.user_b).exists())
    def test_notify_users(self):
        """
        Send a notification to each user
        """
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users(User.objects.all(), foo, notification_type='foo')

        self.assertTrue(Notification.objects.filter(user=self.user_a).exists())
        self.assertTrue(Notification.objects.filter(user=self.user_b).exists())
    def test_notify_user(self):
        """
        Send one notification to user a
        """
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users([self.user_a], foo, notification_type='foo')

        self.assertTrue(Notification.objects.filter(user=self.user_a).exists())
        self.assertFalse(Notification.objects.filter(user=self.user_b).exists())
    def test_notify_user(self):
        """
        Send one notification to user a
        """
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users([self.user_a], foo, notification_type='foo')

        self.assertTrue(Notification.objects.filter(user=self.user_a).exists())
        self.assertFalse(
            Notification.objects.filter(user=self.user_b).exists())
    def test_realtime_notification(self):
        """
        User A creates a Foo, so should not receive a notification
        User B is online and should receive the notification
        User C is subscribed but currently showing as offline
        """
        connection_a = TestConnection(user=self.user_a)
        connection_b = TestConnection(user=self.user_b)
        connection_c = TestConnection(user=self.user_c)

        connection_a.subscribe('swampdragon-notifications', 'notifications', {})
        connection_b.subscribe('swampdragon-notifications', 'notifications', {})
        connection_c.subscribe('swampdragon-notifications', 'notifications', {})

        # User C drops offline
        user_manager.remove_user(self.user_c.pk)
        foo = Foo.objects.create(name='foo', description='foo object')
        notify_users(User.objects.exclude(pk=self.user_a.pk), foo, notification_type='foo')

        self.assertIsNotNone(connection_b.last_pub)
        self.assertIsNone(connection_a.last_pub)
        self.assertIsNone(connection_c.last_pub)
示例#9
0
 def notify_everyone_but_me(self, name):
     users = User.objects.exclude(pk=self.connection.user.pk)
     # foo = Foo.objects.create(name=name)
     notify_users(users, subject="hello everyone", notification_type='foo')
示例#10
0
 def notify_everyone(self, name):
     users = User.objects.all()
     # foo = Foo.objects.create(name=name)
     notify_users(users, subject="Hello", notification_type='foo')
示例#11
0
 def notify_everyone_but_me(self, name):
     users = CustomUser.objects.all()
     # users = CustomUser.objects.exclude(pk=self.connection.user.pk)
     foo = Notification.objects.create(name=name)
     notify_users(users, subject=foo, notification_type='foo')
示例#12
0
 def notify_everyone(self, name):
     users = User.objects.all()
     foo = Foo.objects.create(name=name)
     notify_users(users, subject=foo, notification_type='foo')