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):
app.config.from_object('config.TestingConfig')
return app
We then declare the unit tests of our configuration layer:
class TestDevelopmentConfig(TestCase): def create_app(self): app.config.from_object('config...