#147 Mocking out AWS APIs

Python Bytes - A podcast by Michael Kennedy and Brian Okken - Lunedì

Categorie:

Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: rapidtables

  • rapidtables … converts lists of dictionaries to pre-formatted tables. And it does the job as fast as possible.”
  • Also can do color formatting if used in conjunction with termcolor.colored, but I’m mostly excited about really easily generating tabular data with print.
  • Can also format to markdown or reStructured text, and can do alignment, …

Michael #2: httpx

  • A next generation HTTP client for Python. 🦋
  • HTTPX builds on the well-established usability of requests, and gives you:
    • A requests-compatible API.
    • HTTP/2 and HTTP/1.1 support.
    • Support for issuing HTTP requests in parallel. (Coming soon)
    • Standard synchronous interface, but with [async](https://www.encode.io/httpx/async/)/[await](https://www.encode.io/httpx/async/) support if you need it.
    • Ability to make requests directly to WSGI or ASGI applications.
      • This is particularly useful for two main use-cases:
        • Using httpx as a client, inside test cases.
        • Mocking out external services, during tests or in dev/staging environments.
    • Strict timeouts everywhere.
    • Fully type annotated.
    • 100% test coverage.
  • Lovely support for “parallel requests” without full asyncio (at the API level).
    • Also pairs with async / await with async client.
  • Plus all the requests features

Brian #3: Quick and dirty mock service with Starlette

  • Matt Layman
  • Mock out / fake a third party service in a testing environment.
  • Starlette looks fun, but the process can be used with other API producing server packages.
  • We tell people to do things like this all the time, but there are few examples showing how to.
  • This example also introduces a delay because the service used in production takes over a minute and part of the testing is to make sure the system under test handles that delay gracefully.
  • Very cool, easy to follow write up. (Should probably have Matt on a Test & Code episode to talk about this strategy.)

Michael #4: Mocking out AWS APIs

  • via Giuseppe Cunsolo
  • A library that allows you to easily mock out tests based on AWS infrastructure.
  • Lovely use of a decorator to mock out S3
  • Moto isn't just for Python code and it isn't just for S3. Look at the standalone server mode for more information about running Moto with other languages.
  • Be sure to check out very important note.

Brian #5: μMongo: sync/async ODM

  • “μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM and the difficulty to do document (un)serialization with existing ODMs.”
  • works with common mongo drivers such as PyMongo, TxMongo, motor_asyncio, and mongomock. (Hadn’t heard of mongomock before, I’ll have to try that out.)
  • Note: We’ve discussed MongoEngine before. (I’m curious what Michael has to say about uMongo.)

Michael #6: Single Responsibility Principle in Python

Extras

Michael:

Jokes

  • Q: What do you get when you cross a computer and a life guard?
  • A: A screensaver!

  • Q: What do you get when you cross a computer with an elephant?

  • A: Lots of memory!

via https://github.com/wesbos/dad-jokes

Anti-joke (we ready for those yet?): A Python developer, a PHP developer, a C# developer, and a Go developer went to lunch together. They had a nice lunch and got along fine.

Visit the podcast's native language site