How to check manual DB transaction code in Django?

I am transferring data from an old system to Django. To ensure the integrity of the current database, I do everything manually.

However, when writing unit tests, transactions will not roll back properly. Since TestCase probably uses transactions, is there a way to properly validate code in Django that relies on transactions?

 @transaction.commit_manually def import_records(): # initial prep try: import_data() except Exception as error: rollback = True except (KeyboardInterrupt, SystemExit): sys.stdout.write("Import canceled\n") rollback = True if rollback is True: transaction.rollback() # save history of import 
+6
source share
1 answer

I believe that you are looking for a TransactionTestCase that handles customization and reversal differently than regular TestCase .

+10
source

All Articles