ScanAPI Automated Integration Testing and Live Documentation for - - PowerPoint PPT Presentation

scanapi
SMART_READER_LITE
LIVE PREVIEW

ScanAPI Automated Integration Testing and Live Documentation for - - PowerPoint PPT Presentation

ScanAPI Automated Integration Testing and Live Documentation for your API Camila Maia EuroPython 2020 1 Motivation Everything started in a week which I as Firefighter 2 I work at... 3 Who am I? - Brazilian Backend


slide-1
SLIDE 1

ScanAPI

Automated Integration Testing and Live Documentation for your API

Camila Maia

1

EuroPython 2020

slide-2
SLIDE 2

Motivation

Everything started in a week which I as Firefighter 🔦

2

฀฀ 🚓

slide-3
SLIDE 3

I work at...

3

slide-4
SLIDE 4

Who am I?

4

  • Brazilian Backend Developer
  • Bachelor of Computer Information System
  • Coding since 2010
  • Python and Ruby
  • Events: Pyjamas and EuroPython
slide-5
SLIDE 5

Motivation

Everything started in a week which I as Firefighter 🔦

5

฀฀ 🚓

slide-6
SLIDE 6

Motivation

Integration Errors 💦

6

  • Client sending fields

different than what’s expected

  • Frontend receiving fields

different than what’s expected

slide-7
SLIDE 7

Motivation

Outdated documentation 📝

7

  • Missing endpoints
  • Missing fields
  • Misinformation
slide-8
SLIDE 8

Motivation

Hard to recreate scenarios 😥

8

/reserve/:seat_id flight_id? airplane_id? passenger_id? Is the airplane available? ????

slide-9
SLIDE 9

Motivation

Hard to recreate scenarios 😥

9

slide-10
SLIDE 10
slide-11
SLIDE 11

Proposal

11

  • Open Source Framework
  • Written in Python

1. Provide a Live Documentation 2. Tool to implement integration tests

slide-12
SLIDE 12

PokéAPI: https://pokeapi.co $ http https://pokeapi.co/api/v2/pokemon/

How does it work?

Example: PokéAPI

12

slide-13
SLIDE 13

13

slide-14
SLIDE 14

14

slide-15
SLIDE 15

How does it work?

Example: PokéAPI

15

Installing: $ pip install scanapi

slide-16
SLIDE 16

# api.yaml api: endpoints:

  • name: pokeapi

path: https://pokeapi.co/api/v2/ endpoints:

  • name: pokemon

path: pokemon requests:

  • name: list_all

method: get path: /

How does it work?

Example: PokéAPI

16

slide-17
SLIDE 17

How does it work?

Example: PokéAPI

17

Running

slide-18
SLIDE 18

How does it work?

Documentation 📅

18

slide-19
SLIDE 19

19

slide-20
SLIDE 20

20

slide-21
SLIDE 21

21

slide-22
SLIDE 22

How does it work?

Integration tests ✅

22 ... requests:

  • name: list_all

method: get path: / tests:

  • name: status_code_is_200

assert: ${{ response.status_code == 200 }}

  • name: response_time_is_under_half_second

assert: ${{ response.elapsed.total_seconds() < 0.5 }}

https://requests.readthedocs.io

  • name: count_is_964

assert: ${{ response.json()["count"] == 964 }}

slide-23
SLIDE 23

23

slide-24
SLIDE 24

How does it work?

Chaining Requests ⛓

24

  • Get details of a Pokémon
  • In this case, the data is “static”, but it might not be.
  • https://pokeapi.co/api/v2/pokemon/bulbasaur
slide-25
SLIDE 25

How does it work?

Chaining requests ⛓

25 requests:

  • name: pokemon

path: pokemon requests:

  • name: list_all

method: get path: / vars: pokemon_name: ${{ response.json()["results"][0]["name"] }} tests: ...

pokemon/${pokemon_name}

  • name: details

method: get path: ${pokemon_name}

slide-26
SLIDE 26

26

slide-27
SLIDE 27

Adding ScanAPI to a project

27

slide-28
SLIDE 28

Adding ScanAPI to a project

28

slide-29
SLIDE 29

... scanapi: docker:

  • image:

camilamaia/scanapi:1.0.5 steps:

  • checkout
  • run:

name: Run ScanAPI command: | scanapi scanapi/api.yaml

  • c scanapi/.scanapi.yaml
  • o scanapi/report.html
  • store_artifacts:

path: scanapi/report.html

29

  • build-push:

name: build-push-staging env: staging requires:

  • scanapi

filters: branches:

  • nly:
  • master

workflows: version: 2 main: jobs:

  • scanapi:

filters: branches:

  • nly:
  • master
slide-30
SLIDE 30

How does it work?

And there is more 🎊

30

  • Language-independent
  • It also accepts API spec in JSON
  • Environment variables
  • Hide sensitive info in the report
  • Multiple files API specification
  • Custom templates
slide-31
SLIDE 31

Can I start using it?

For sure! 👎

31

slide-32
SLIDE 32

scanapi.dev

32

slide-33
SLIDE 33

Next Steps

What about the future? 🔯

33

  • Missing HTTP methods (current: GET, POST, PUT, PATCH, DELETE)
  • JSON visualization
  • Docs + Tutorials
  • Website improvements
  • GitHub Action

And what if….

  • OpenAPI
slide-34
SLIDE 34

Why to contribute?

Join us! 🚁

34

  • Backend, frontend, automation, design
  • “Pure Python”
  • Understand how a lib works
  • Test coverage > 90%
  • Issues with labels - i.e: good first issue
slide-35
SLIDE 35

Why to contribute?

Join us! 🚁

35 How Open Source Changed My Life with Max Stoiber

slide-36
SLIDE 36

Sprint Session

36

  • Sprint session on this

weekend - July 25th and 26th (free!) #sprint-scanapi More information

slide-37
SLIDE 37

github.com/scanapi ⭐

37

slide-38
SLIDE 38

We are hiring!

Loadsmart

38

Direct Link

slide-39
SLIDE 39

THANK YOU

@cmaiacd camilamaia

#talk-scanapi #sprint-scanapi