How to do it...

  1. Create the database access module. This module will have the ElasticClient class definition. It will also have any additional definitions that this class needs.
  2. This recipe will use unittest and doctest to create a unified suite of tests. It will use the Mock class from unittest.mock, as well as json. Since this module is separate from the unit under test, it needs to import ch11_r08_load, which has the class definitions that will be tested:
        import unittest 
        from unittest.mock import * 
        import doctest 
        import json 
        import ch11_r08_load 
  1. Here's the overall framework for a test case. We'll fill in the setUp() and runTest() methods of this test below. The name shows that we're given an instance of ElasticClient, when we invoke ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.