changeset 5984:77bd10c410ed

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.
author domruf <dominikruf@gmail.com>
date Fri, 17 Jun 2016 19:22:53 +0200
parents a69bcf8b28b3
children 05c67c3ef222
files kallithea/tests/__init__.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/__init__.py	Wed Jun 15 18:33:27 2016 +0200
+++ b/kallithea/tests/__init__.py	Fri Jun 17 19:22:53 2016 +0200
@@ -175,11 +175,12 @@
         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,