Data-driven migration testing with REST APIs and Python

Akshay Maldhure
Quick Code
Published in
2 min readMay 27, 2019

Data migration is the process of transferring information (data) from one system to a new system.

Image courtesy: https://www.cobalt.net

Background

After migrating the data by running the migration scripts on a database, it is important to ensure that the migrated data lands “correctly” into the database, especially in cases where the correctness of data is the top concern and any issues with this data could be expensive, e.g. transactional records involving valuable data, sensitive information, data derived from the migrated data based on some complex business logic, etc.

Problem Statement

Consider this simple example where we intend to migrate the data from multiple CSV files to the database, the data from which gets massaged at the API layer in a bank account management system. This system has different users with distinct phone numbers.

Here, we have two CSVs (users.csv containing the primary details of the bank account holders and user_account_details.csv containing the details of the balance and bonus amounts for different users in their respective accounts). In a real world scenario, there could be much more such CSV files. In fact, there could be another database(s) instead of the CSVs altogether.

As mentioned earlier, it is essential to ensure this data lands “correctly” into the database. As such, testing the migration scripts along with the business logic in the API layer becomes important. Since the correctness of the actual data is the top concern here, merely doing some simple tests like asserting on the count of the migrated data records against that of the reference data records from CSV may not be sufficient (in fact, it won’t be!).

Approach

So I used the data-driven testing capabilities of a test framework/runner like lemoncheesecake with the Python programming language. There would be a lemoncheesecake test suite that would have parameterised test(s) that would run over different records from a reference CSV (this CSV may essentially be the same file which was fed to the migration scripts for migrating the data) and validate different data points by making the actual relevant REST API calls.

Here’s how the test suite looks like. Of course, there would be many more validations that could be achieved by asserting the values from the returned API responses in the real world.

--

--

Akshay Maldhure
Quick Code

Indian • Music lover • Technologist at Gojek • Husband • Father • An ardent TBBT fan • Loves planes 😄