# HG changeset patch # User domruf # Date 2016-06-17 19:22:53 # Node ID 77bd10c410ed423aa6d7012af9ad5c72fbd18b79 # Parent a69bcf8b28b383dc1e508ab26fdbe87fa3353fa8 tests: fix 'a foreign key constraint fails' when running tests on mysql UserNotification needs to be deleted before Notification because there are foreign key references in UserNotification to Notification. diff --git a/kallithea/tests/__init__.py b/kallithea/tests/__init__.py --- a/kallithea/tests/__init__.py +++ b/kallithea/tests/__init__.py @@ -175,11 +175,12 @@ class TestController(object): logging.getLogger("kallithea").addHandler(h) def remove_all_notifications(self): - Notification.query().delete() + # query().delete() does not (by default) trigger cascades + # ( http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes ) + # so delete the UserNotification first to ensure referential integrity. + UserNotification.query().delete() - # Because query().delete() does not (by default) trigger cascades. - # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes - UserNotification.query().delete() + Notification.query().delete() Session().commit() def log_user(self, username=TEST_USER_ADMIN_LOGIN,