changeset 7700:ffdcf0dfe0e4

tests: make test_admin_users user_and_repo_group_fail() fixture more stable When adding authentication_token() to log_user(), database session lifetime will in some cases change: test_admin_users test_delete_repo_group_err() use the user_and_repo_group_fail() fixture. Before, it got ObjectDeletedError when trying to delete a deleted RepoGroup and moved on. After changing log_user(), py.test would emit a warning: kallithea/tests/functional/test_admin_users.py::TestAdminUsersController::()::test_delete_repo_group_err .../site-packages/sqlalchemy/orm/persistence.py:1340: SAWarning: DELETE statement on table 'groups' expected to delete 1 row(s); 0 were matched. Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning. % (table.description, expected, rows_matched) Instead, use RepoGroup.get_by_group_name to verify the group exists before trying to delete it.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 23 Jan 2019 00:56:18 +0100
parents 53a07d06344b
children 9c2fc1390291
files kallithea/tests/functional/test_admin_users.py
diffstat 1 files changed, 2 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/functional/test_admin_users.py	Wed Jan 23 01:49:30 2019 +0100
+++ b/kallithea/tests/functional/test_admin_users.py	Wed Jan 23 00:56:18 2019 +0100
@@ -18,7 +18,7 @@
 from kallithea.tests.base import *
 from kallithea.tests.fixture import Fixture
 from kallithea.controllers.admin.users import UsersController
-from kallithea.model.db import User, Permission, UserIpMap, UserApiKeys
+from kallithea.model.db import User, Permission, UserIpMap, UserApiKeys, RepoGroup
 from kallithea.lib.auth import check_password
 from kallithea.model.user import UserModel
 from kallithea.model import validators
@@ -39,11 +39,8 @@
     repo_group = fixture.create_repo_group(name=groupname, cur_user=username)
     yield user, repo_group
     # cleanup
-    try:
+    if RepoGroup.get_by_group_name(groupname):
         fixture.destroy_repo_group(repo_group)
-    except ObjectDeletedError:
-        # delete already succeeded in test body
-        pass
 
 
 class TestAdminUsersController(TestController):