What is the best way to create unit tests for scripts using the MI Python STK, without accessing external databases?
Unit tests should be able to run without a live connection to a database required, and shouldn't rely on a database's state to pass. But if a script makes extensive use of the MI STK then it is challenging to get started with unit tests. Mocking MI objects is not easy, since so many of them cannot be directly instantiated, have properties that make database calls, or are simply too complex to recreate. This results in more time making mocks of the STK than actually testing the script.
The best way I have found to add unit tests to complex scripts is to use the STK only where required. For example, instead of a function accepting a granta.Record instance as an argument, it could accept a record identity and a dictionary of attribute names to attribute values. Or I can create my own custom.Record class that contains all the relevant information, and convert it to/from a granta.Record where needed.
However, this feels like circumnavigating the well-designed Streamlined STK and recreating objects unnecessarily, potentially introducing errors. For an ETL script, it would be easier to keep the same record objects throughout the transform.
Is there an easy way to create unit tests for sufficiently complex MI scripts? Is there a good way to mock MI objects?
Thanks!