Testing an api wrapper

Hi there, currently I’m trying to write tests for an api wrapper I created. Of course I don’t want to actually call the RestAPI during testing. Luckily I discovered BrokenRecord.jl which is working nicely. But unfortunately I can’t figure out a nice way to test uploads, because

ERROR: Request body does not match

And with looking into what is changing, I detected the ‘body.boundary’ (with body beeing a HTTP.Forms.Form struct) is changing on each time, even if I always use the same file.

Did someone encounter that problem / situation already? Do I overlook an obvious solution (hopefully)? Are there any recommondations?

I’d be happy for every hint, comment, answers…

Hi folks! I am reviving this question from @knbrt as I am also curious about how best to test an API when one has developed a Julia-based wrapper for that API.

Here’s an example of some Julia code I have written for my wrapper:

using IPUMS

api = IPUMSAPI("https://api.ipums.org/", Dict("Authorization" => "Your_Key"))

test_extract_definition = "test/testdata/example_extract_request.json"

res = extract_submit(api, "nhgis", test_extract_definition)

metadata, defn, msg = extract_info(api, res.number, "nhgis")

extract_list(api, "nhgis")

As you can see, all these commands hit the API endpoint I have provided. I don’t want to have to actually hit the API endpoint every single time I run my test suite. Any thoughts about how to handle this?

Thanks!

~ tcp :deciduous_tree:

P.S. CCing @bauglir as I am curious how you do API testing with Kroki.jl (which is quite a neat package!)