Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stackable expectations #46

Open
csernazs opened this issue Oct 18, 2020 · 2 comments
Open

Stackable expectations #46

csernazs opened this issue Oct 18, 2020 · 2 comments

Comments

@csernazs
Copy link
Owner

In many cases, the parameters for expect_request() is very long, especially when multiple headers are specified or the request have a long data or json in its body.
In such case the expect_request() call can be very long. If it bothers the developer, it needs to be shortened, for example by moving the literals to variables and then specifying the variables for the expect_request() call.
In some cases, there are common expectations specified for each request, such as the content-type header is set to application/json.

It would be great to somehow bake a command, similar to the sh package's bake method.

So, it would look like:

server = httpserver.bake(headers={"content-type": "application/json"}) # and probably other common kwargs
server.expect_request("/foo", json={"foo": "bar"}).respond_with_json({"foo": "bar"})

Here, the bake is similar to the functools.partial function so it creates a new httpserver-like object whose defaults are changed.

@funkyfuture
Copy link

i wonder whether this could be realized on the fixture level, so that the definition of these common properties happens in the conftest.py.

@csernazs
Copy link
Owner Author

I think this could be done easily:
conftest.py:

@pytest.fixture()
def myserver(httpserver):
    return httpserver.bake(headers={"content-type": "application/json"})

test_foo.py:

def test_foo(myserver):
    server.expect_request("/foo", json={"foo": "bar"}).respond_with_json({"foo": "bar"})

At the moment it is just an idea, it is not implemented yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants