6
我正在将遗留系统的数据传输到Django中。为了确保当前数据库的完整性,我正在手动提交所有内容。如何在Django中测试手动DB事务代码?
但是,编写单元测试时,事务将不能正确回滚。由于TestCase
可能使用了事务,有没有什么办法可以正确测试依赖事务的Django中的代码?
@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
太棒了 - 非常感谢!有关交易的文档没有提及如何正确测试。 https://docs.djangoproject.com/en/1.5/topics/db/transactions/ – strongriley 2013-04-12 21:56:05