Usually the workflow I have is as follows:

Perform SQL query on database, 
Load it into memory
Transform data based on logic foo()
Insert the transformed data to a table in a database.

How should unit test be written for this kind of workflow? I'm really new to testing.
Anyway, I'm using Python 3.4.
One way to test this kind of workflow is by using a special database just for testing. The test database mirrors the structure of your production database, but is otherwise completely empty (i.e. no data is in the tables). The routine is then as follows

Connect to the test database (and and maybe reload its structure)
For every testcase, do the following:


Load the minimal set of data into the database necessary to test your routine
Run your function to test and grab its output (if any)
Perform some tests to see that your function did what you expected it to do.
Drop all data from the database before the next test case runs

After all your tests are done, disconnect from the database
How should unit test be written for data transformation?