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?
CodePudding user response:
After a few hours of debugging. I figured out what I did wrong. In my settings i have set
APPLICATION_ROOT = Path(__file__).parent.parent
I wrongly assumed APPLICATION_ROOT
to be the project root and it was returning a PositionPath object.