def test_send_ts_task_fails_on_many_when_expecting_one(celery): # assert with pytest.raises(SchemaError): # act with patch.object(celery, 'send_task') as mock_send_task: send_ts_task('foo.bar', FooSchema(many=False), [{'foo': 'bar'}]) # assert assert not mock_send_task.called
def test_send_ts_task_raises_SchemaError_on_schema_validation_deserilization( celery): # assert with pytest.raises(SchemaError): # act with patch.object(celery, 'send_task') as mock_send_task: send_ts_task('foo.bar', FooSchema(many=False), {'baz': 'foo'}) # assert assert not mock_send_task.called
def test_send_ts_task_with_many(celery): # act with patch.object(celery, 'send_task') as mock_send_task: send_ts_task('foo.bar', FooSchema(many=True), [{'foo': 'bar'}]) # assert mock_send_task.assert_called_once_with('handle_foo_bar', ({ 'data': [{ 'foo': 'bar' }] }, ), exchange='ts.messaging', routing_key='foo.bar')
def process_response(self, req, res, resource, req_succeeded): if not self.auditing: return try: user = req.context.get( USER_CONTEXT_KEY) or User.from_decoded_token( self._decode_token(req)) except TokenError as exc: logger.warning('AUDIT -- {}'.format(exc)) else: message = { 'method': req.method, 'action': '{}_{}_{}'.format(resource.__class__.__name__, req.method, req.path), 'endpoint': req.path, 'username': user.username, 'organization_uuid': user.organization, 'roles': user.roles, 'groups': user.groups, 'status': res.status } try: send_ts_task('audit.data', AuditSchema(), message, expires=self.audit_msg_exp) except SchemaError as ex: logger.error( 'Error sending audit message, please contact the Thunderstorm team if you see this message: {}' .format(ex))