Skip to content

0.20.2 broke our tests, but I think it's good (our use case + questions + feature request) #243

Closed
@macieyng

Description

@macieyng

Hi @lundberg 👋

I want to let you know that #240 (or 0.20.2 in general) broke our tests - but I think that's good. I want to tell you how we used it and what actually broke as I think that there's a room for small improvement.

We had our mocks defined as:

respx_mock.get("https://example.com/orders?storeId=1&status=paid&status=reviewed")

And change from #240 (or 0.20.2) made us rewrite them as

respx_mock.get(
    "https://example.com/orders",
    params={
        "storeId": "1",
        "status":[
            "paid",
            "reviewed"
        ]
    }
)

I believe that up until now, we used this bug to our advantage.

I inspected what was happening under the hood in 0.20.2 and it turns out that:

First one:

Request:  <Request('GET', 'https://example.com/api/orders?storeId=1&status=paid&status=reviewed')>
Pattern:  <Scheme eq 'https'> AND <Host eq 'example.com'> AND <Path eq '/api/orders?storeId=1&status=paid&status=reviewed'> AND <Method eq 'GET'>
Match:  <Match False>

and second one:

Request:  <Request('GET', 'https://example.com/orders?storeId=1&status=paid&status=reviewed')>
Pattern:  <Scheme eq 'https'> AND <Host eq 'example.com'> AND <Path eq '/api/orders'> AND <Method eq 'GET'> AND <Params contains QueryParams('storeId=1&status=paid&status=reviewed')>
Match:  <Match True>

These are obviously two different sets of patterns to match.

As a follow up to this issue I want to ask:

  • Can we document this in caveat section of documentation? I think there might be some folks doing the same error as we did and this could save them hours or days of debugging.
  • Was this behavior expected?
  • Do you plan to make querystrings produce identical set of patterns?
    • ie:
      when
      respx_mock.get("https://example.com/orders?storeId=1&status=paid&status=reviewed")
      then
      Request:  <Request('GET', 'https://example.com/orders?storeId=1&status=paid&status=reviewed')>
      Pattern:  <Scheme eq 'https'> AND <Host eq 'example.com'> AND <Path eq '/api/orders'> AND <Method eq 'GET'> AND <Params contains QueryParams('storeId=1&status=paid&status=reviewed')>
      Match:  <Match True>
      

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions