Testing

As the shared data pattern focuses on the storage layer, we will have layers of extremely simple tests, where unit tests and functional tests are enough. Let's look at a brief example.

In the file FamousNewsService tests.py, there's a bunch of interesting tests to run. First, let's declare our import statements. The highlight is flask_testing, which will be the basis of all our tests. This tool provides a couple of interesting functionalities—including how to access the settings of the Flask and HTTP clients:

import json 
import unittest 
from app import app 
from flask_testing import TestCase

Now, we write the base class for our functional tests. We use the TestingConfig setting for this task:

class BaseTestCase(TestCase): def create_app(self): ...

Get Microservice Patterns and Best Practices 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.