Verified fakes with OpenAPI

When your code depends on an external (third-party) service, testing it can be challenging. It may be expensive, slow or unreliable to call that service in tests. A classic approach is to mock such service or its network calls. But then the challenge becomes keeping the mocks up to date with the third-party services. Using verified fakes allows us to replace a service while guaranteeing that it stays up to date. This can be achieved in different ways: using recent network recordings (e.g. [LINK:https://github.com/kevin1024/vcrpy] vcrpy ), running a test suite against the mock and the real service to compare the results, or relying on an API contract like OpenAPI, or avro. [LINK:https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md] OpenAPI is a specification that documents how a service API works and enforces it by validating requests and responses for the service. We can then check the mocks against the OpenAPI specification to make sure they are up to date. In this talk, I will explain how to set up such verified fakes with OpenAPI, and present a new open-source library, pyramid_mock_server. Here are the 3 main focuses: Quick introduction on OpenAPI and how to use it with bravado, the python OpenAPI client How to set up Verified Fakes: using pyramid_mock_server Usage @Yelp: usage of fakes and OpenAPI for unit tests, acceptance tests, and documentation The talk focuses on OpenAPI, but the learnings and methodology can be extended to any other API specification languages (or python web frameworks). The OpenAPI initiative is a cross-vendor consortium focused on creating, evolving and promoting a vendor neutral description format for APIs. As an open governance structure under the Linux Foundation, its members include Google, IBM, Atlassian and PayPal.

Lauris Jullien

I am a backend engineer @Yelp in Hamburg for 3 years. Before that I was working with robots @Aldebaran Robotics. And before that I was doing my own startup :) I like clean APIs, all you can do with data, and as a good French, wine.

Social card for talk: Verified fakes with OpenAPI