Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cutting off the Internet: Testing Applications that Use Requests

Cutting off the Internet: Testing Applications that Use Requests

A brief and opinionated view of testing applications and libraries that use requests by a core-developer of requests. You will receive an overview of testing with responses, vcr, httpretty, mock, and betamax. (Video: https://www.youtube.com/watch?v=YHbKxFcDltM)

Ian Cordasco

April 14, 2015
Tweet

More Decks by Ian Cordasco

Other Decks in Programming

Transcript

  1. @sigmavirus24 c u t t i n g Testing Applications

    that Use Requests o f f the Internet @sigmavirus24
  2. @sigmavirus24 url = url_from(resource) kw = {‘headers’: headers, ‘params’: params}

    resp = session.get(url, **kw) if resp.ok: return resp resp.raise_for_status()
  3. @sigmavirus24 I m i t a t i o n

    i s t h e s i n c e r e s t f o r m o f F l a t t e r y
  4. @sigmavirus24 P r e t e n d t o

    b e T h e N . S . A .
  5. @sigmavirus24 session = requests.Session() cassette = ‘vcrexample.yml’ with vcr.use_cassette(cassette): resp

    = get_resource( session, ‘users’) assert resp.ok users = resp.json() assert len(users) > 0
  6. @sigmavirus24 session = requests.Session() cassette = ‘vcrexample.yml’ with vcr.use_cassette(cassette): resp

    = get_resource( session, ‘users’) assert resp.ok users = resp.json() assert len(users) > 0
  7. @sigmavirus24 session = requests.Session() cassette = ‘vcrexample.yml’ with vcr.use_cassette(cassette): resp

    = get_resource( session, ‘users’) assert resp.ok users = resp.json() assert len(users) > 0