Kludex/bump-testclient

won't work for me

vianmixtkz opened this issue · 8 comments

I am using:

uvicorn==0.20.0
starlette==0.25.0
fastapi==0.92.0
httpx==0.23.3
pytest==7.0.1
bump_testclient==0.3.0

I am following the instructions and just nothing happens. My tests are not updated

How are you using the tool?

Using the command suggested in the doc : python -m bump_testclient test_main.py

By "nothing happens" you mean that the code doesn't change?

What changes were you expecting to be changed?

There are places in my code where I was expecting data to be replaced by content among others

Can you give me a code example on what the expectation was?

@pytest.mark.signup
def test_signup_and_login(get_dummy_user):
    """Testes sign-up endpoint"""

    response = client.post("/users/sign-up", json=get_dummy_user)
    assert response.status_code == 201, response.text

    form = get_dummy_user
    form["username"]=form["email"]
    response = client.post("/users/login", data=form)

    assert response.status_code == 200, response.text

should become

@pytest.mark.signup
def test_signup_and_login(get_dummy_user):
    """Testes sign-up endpoint"""

    response = client.post("/users/sign-up", json=get_dummy_user)
    assert response.status_code == 201, response.text

    form = get_dummy_user
    form["username"]=form["email"]
    response = client.post("/users/login", content=form)

    assert response.status_code == 200, response.text

no ?

Yeah, for me it is also doesn't work.

I have the code:

    def test_upload_file_bad_type(self):
        file = io.BytesIO(str.encode(CSV_FILE_STR))

        response = self.client.post(
            f"{settings.API_V1_STR}/importer/configuration/{self.ipc_id}/files/"
            "building_config_file",
            files={"file": ("file", file, "image/png")},
            headers=auth_header(USER_READ_WRITE),
        )

        assert response.status_code == status.HTTP_415_UNSUPPORTED_MEDIA_TYPE
        assert "File must be one of the following formats" in (
            response.json().get("detail", {}).get("message")
        )

and it isn't adjusted when run you script with this file as a param @Kludex

Finally biting off the update for an older project myself, and finding the same thing: absolutely nothing happens when running this against a very simple test. I somewhat suspect it's because we're injecting our client as a pytest fixture; perhaps the tool can't tell what's a client and what isn't?