Integrity Tests
Learn about integrity tests in this lesson.
We'll cover the following...
Let’s write some data check methods and exercise them in a test. To do this, we’ll start with three new ORM classes that are complicated enough to require some out-of-database constraint checks.
Writing in some complex data
The idea in this example is that we have employees that work for us and projects we need to be done. There is a many-to-many relationship between employees and projects which describes who has been assigned to what project. These assignments are captured in a separate Assignment table.
We create a function to add records and call it from the __main__ clause. In Python, if evaluates true only when the script is run directly and not when it is imported. It’s convenient to have a file do double-duty as both a module to import and as a script that we can run.
Checking the data
We’ve chosen to leave the skill needs for each project as space-separated words, mainly for brevity. We could have created a separate field need_server, ...