Coder Social home page Coder Social logo

Use `httptest` for API mocking about webchem HOT 7 OPEN

Aariq avatar Aariq commented on August 18, 2024
Use `httptest` for API mocking

from webchem.

Comments (7)

Aariq avatar Aariq commented on August 18, 2024 1

Played around with httptest a bit (#410) and it quickly became clear that dealing with the long file paths was going to be a pain. Just sticking with vcr is going to be loads easier I think.

from webchem.

Aariq avatar Aariq commented on August 18, 2024 1

Thanks @maelle. I did follow the guide to fix non-portable file paths and it just didn't go super smoothly.
https://github.com/ropensci/webchem/pull/410/files#diff-a74e30985354d9f5007abd4f0d76acf8927bbfc2abbfe69a4fc80e11dcbc54d9

There are a lot of different API endpoints that webchem hits, so I was finding it to be a lot of work. vcr won't work for all of the functions in webchem, but it'll be easier to set up. Still deciding which is best.

from webchem.

stitam avatar stitam commented on August 18, 2024

Hi @Aariq, thanks for looking into this, if you start working on API mocking I'll join in.

What I'm wondering about is the advantage of httptest2 over vcr. I have some experience with vcr but no experience with httptest2. I know vcr is an rOpensci package, I don't know about httptest2. Cranlogs counts 11k downloads per month for vcr, and 1.5k for httptest2. I'm not against httptest2 but I do remember liking vcr. Maybe we could discuss this a bit more or implement both for a single webservice each and see which one is easier to maintain over time?

Selecting the API: PubChem and ChemSpider are the slowest (many tests) and for ChemSpider there is also the monthly limit. I think ChemSpider would be the best candidate.

from webchem.

Aariq avatar Aariq commented on August 18, 2024

The major downside of httrtest is that it (by default) creates long folder paths (same as API URL) to store the API snapshots, which CRAN doesn't like. There is additional setup to make it not do that. vcr just stores all the snapshots in folders that you decide the name of.

from webchem.

Aariq avatar Aariq commented on August 18, 2024

First, httptest is the testing package that goes with the httr package and httptest2 goes with httr2. httptest and vcr have a very similar interface and functionality—with vcr, you wrap tests or functions inside of tests with use_cassette() and with httptest you wrap them with with_mock_dir(). Learning httptest was @maelle's suggestion (#306 (comment)).

from webchem.

maelle avatar maelle commented on August 18, 2024

if you use httptest and then later switch from httr to httr2, it'll be very easy to switch to httptest2.

from webchem.

maelle avatar maelle commented on August 18, 2024

@Aariq it's a reasonable choice but if the beginning of each file paths it's the same, you can edit the configuration. (you'd need httptest latest version as the former one had a bug nealrichardson/httptest#82)

Happy to help if needed, and absolutely no pressure to switch to httptest.

from webchem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.