def create(self, req, user_id): """Called for POST requests to /user/{id}/notifications Sends a notification to the given user""" user = models.User.get(key=user_id) messaging.send(user, json.loads(req.body)) response = {} return Response(json.dumps(response))
def test_send(self): user = utils.get_test_user() info = {'service': 'service_id', 'state': 'normal', 'previous_state': 'unexpected high'} with mock.patch('surveilr.messaging._get_driver') as _get_driver: messaging.send(user, info) # Check that _get_driver gets called with the user as its argument _get_driver.assert_called_with(user) # Check that _get_driver's return value (i.e. the driver) # gets its .send() method called with user and info as its # arguments _get_driver.return_value.send.assert_called_with(user, info)