def test_public_notifications(self):
        connection_a = TestConnection()
        connection_b = TestConnection()

        connection_a.subscribe('swampdragon-notifications', 'notifications',
                               {})
        connection_b.subscribe('swampdragon-notifications', 'notifications',
                               {})
    def __init__(self, methodName='runTest'):
        super(DragonTestCase, self).__init__(methodName)

        pub_sub._channels = []
        pub_sub._subscribers = {}
        self.connection = TestConnection()
        self.urls = discover_routes()
Beispiel #3
0
    def test_session_from_router(self):
        """
        Ensure that sessions are unique per connection
        """
        connection_a = TestConnection()
        connection_b = TestConnection()
        foo_router = FooRouter(connection_a)
        foo_router.write_session(**{'value': 'a value'})
        foo_router.read_session()
        self.assertEqual(connection_a.get_last_message()['data'], 'a value')

        foo_router = FooRouter(connection_b)
        foo_router.read_session()
        self.assertNotEqual(connection_b.get_last_message()['data'], 'a value')
    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)