'Trying to test Flask endpoint. AttributeError: 'PosixPath' object has no attribute 'lstrip'

I'm trying to test my Flask API with pytest, but i'm strugling with this error: AttributeError: 'PosixPath' object has no attribute 'lstrip'. It's being raised when I do a post request to /authentication/users. The endpoint works perfectly when I use Postman and the unit tests im my User model works too (they don't use client). Here is my code:

# conftest.py

# ... imports here ...

@pytest.fixture
def client():
    app.config.from_object(TestSettings)
    with app.test_client() as client:
        with app.app_context():
            # starts connection with tests db
            db = MongoEngine(app)

        yield client  # Do the tests

        with app.app_context():
            # drop db after tests
            db.connection.drop_database('test')

My test that use client

# integrations/test_auth_endpoints.py
def test_create_user(client):
    """
    GIVEN the /authentication/users endpoint
    WHEN a POST request is made
    THEN check the status code, message and data of response
    """
    usr_data = {
        "nome": "ana",
        "cpf": "12345678913",
        "email": "[email protected]",
        "password": "my-secret.@"
    }
    req = client.post('/authentication/users', data=usr_data)  # <-- AttributeError here
    assert req.status == 201

So what i'm doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source