Travis-CI POST tests returns self.open(*args, **kw) error


#1

I have an endpoint that allows a user to signup, this endpoint expects a json data payload and the method POST. I have some tests and the test runs well locally but on travis-ci it returns this error

 self = <app.test.v2.test_user.AuthTestCase testMethod=test_auth_signup>
def test_auth_signup(self):
    '''test signup'''
    response = self.client.post('api/v2/auth/signup',
                                data=json.dumps(self.signup),
                              content_type='application/json') #errortag
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/werkzeug/test.py:840: in post
return self.open(*args, **kw)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/testing.py:200: in open
follow_redirects=follow_redirects
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/werkzeug/test.py:803: in open
response = self.run_wsgi_app(environ, buffered=buffered)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/werkzeug/test.py:716: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/werkzeug/test.py:923: in run_wsgi_app
app_rv = app(environ, start_response)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:2309: in __call__
return self.wsgi_app(environ, start_response)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:2295: in wsgi_app
response = self.handle_exception(e)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:1741: in handle_exception
reraise(exc_type, exc_value, tb)
 ../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/_compat.py:35: in reraise
raise value
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:2292: in wsgi_app
response = self.full_dispatch_request()
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:1815: in full_dispatch_request
rv = self.handle_user_exception(e)
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:1718: in handle_user_exception
reraise(exc_type, exc_value, tb)
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/_compat.py:35: in reraise
raise value
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:1813: in full_dispatch_request
rv = self.dispatch_request()
../../../virtualenv/python3.6.3/lib/python3.6/site-packages/flask/app.py:1799: in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)

app/api/v2/utils/validation.py:38: in wrapper return func(*args, **kwargs)


 =============== 1 failed, 46 passed, 1 warnings in 1.23 seconds ================
 The command "py.test  --cov-report term --cov=app/api/" exited with 1.

This error originates from my client post declaration specifically content_type='application/json' as shown below

enter image description here

I have tried tweaking the test method with no success, class AuthTestCase;

 def setUp(self):
    '''set up testing env'''
    self.app = create_app('testing')
    self.client = self.app.test_client()
    queries = create_query()
    self.val = exec_queries(queries)
    self.signup = {
        "fullname": 'John Nyingi',
        "username": 'j0nimost',
        "email": 'j0ni@ke.com',
        "password": '**andela1',
        "confirmpassword": "**andela1"
    }

 def test_auth_signup(self):
    '''test signup'''
    response = self.client.post('api/v2/auth/signup',
                                data=json.dumps(self.signup),
                                content_type='application/json')

    self.assertEqual(response.status_code, 201)
    data = json.loads(response.data)
    self.assertEqual('j0nimost', data['data'][0]['user'][0]['username'])
    self.assertIsNotNone(data['data'][0]['token'])

I also have a custom validation decorator that runs prior to the method call;

def validate_input(schema):
'''
This is a decorator which will validate,
all input is entered.
'''
    def decorator(func):
        wraps(func)

        def wrapper(*args, **kwargs):
            '''deserialize to validate'''
            try:
                validate(request.json, config[schema])
            except ValidationError as e:
                if e.validator == 'pattern':
                    err_obj = {
                        "status": 400,
                        "error": 'unexpected pattern for ' + e.path[0]
                    }
                elif e.validator == 'minLength':
                    err_obj = {
                        "status": 400,
                        "error": 'unexpected {} too short'.format(e.path[0])
                    }
                else:
                    err_obj = {
                        "status": 400,
                        "error": 'unexpected ' + e.message
                    }
                return jsonify(err_obj), 400
            return func(*args, **kwargs)
        wrapper.__name__ = func.__name__
    return wrapper
return decorator

The last error shows a reference error originating from wrapper.__name__ = func.__name__. I still don’t know how to solve this error. I expect the test to pass.