def test_publish_to_scope(self): """ Make sure we can bulk publish to a number of users passing in a resultset from a Django ORM query """ register_user_scope_resolver("list_scope", TestListScopeResolver()) msg = NotificationMessage(namespace='test-runner', msg_type=self.msg_type, payload={'foo': 'bar'}) bulk_publish_notification_to_scope( scope_name="list_scope", # the TestListScopeResolver expects a "range" property in the context scope_context={"range": 5}, msg=msg) for user_id in range(4): # have to fudge this a bit as the contract on user_id # says > 0 only allowed user_id = user_id + 1 notifications = get_notifications_for_user(user_id) self.assertTrue(isinstance(notifications, list)) self.assertEqual(len(notifications), 1) self.assertTrue(isinstance(notifications[0], UserNotification))
def test_publish_to_scope(self): """ Make sure we can bulk publish to a number of users passing in a resultset from a Django ORM query """ register_user_scope_resolver("list_scope", TestListScopeResolver()) msg = NotificationMessage(namespace="test-runner", msg_type=self.msg_type, payload={"foo": "bar"}) bulk_publish_notification_to_scope( scope_name="list_scope", # the TestListScopeResolver expects a "range" property in the context scope_context={"range": 5}, msg=msg, ) for user_id in range(4): # have to fudge this a bit as the contract on user_id # says > 0 only allowed user_id = user_id + 1 notifications = get_notifications_for_user(user_id) self.assertTrue(isinstance(notifications, list)) self.assertEqual(len(notifications), 1) self.assertTrue(isinstance(notifications[0], UserNotification))
def test_publish_to_bad_scope(self): """ Assert that we can't publish to a scope which can not be resolved """ msg = NotificationMessage(namespace="test-runner", msg_type=self.msg_type, payload={"foo": "bar"}) with self.assertRaises(TypeError): bulk_publish_notification_to_scope( scope_name="bad-scope", # the TestListScopeResolver expects a "range" property in the context scope_context={"range": 5}, msg=msg, )
def test_publish_to_bad_scope(self): """ Assert that we can't publish to a scope which can not be resolved """ msg = NotificationMessage(namespace='test-runner', msg_type=self.msg_type, payload={'foo': 'bar'}) with self.assertRaises(TypeError): bulk_publish_notification_to_scope( scope_name="bad-scope", # the TestListScopeResolver expects a "range" property in the context scope_context={"range": 5}, msg=msg)