Changeset - ffdcf0dfe0e4
[Not reviewed]
default
0 1 0
Mads Kiilerich - 7 years ago 2019-01-23 00:56:18
mads@kiilerich.com
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.
1 file changed with 2 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -15,13 +15,13 @@
 
from sqlalchemy.orm.exc import NoResultFound, ObjectDeletedError
 

	
 
import pytest
 
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
 
from kallithea.lib import helpers as h
 
from kallithea.model.meta import Session
 
from webob.exc import HTTPNotFound
 
@@ -36,17 +36,14 @@ def user_and_repo_group_fail():
 
    username = 'repogrouperr'
 
    groupname = u'repogroup_fail'
 
    user = fixture.create_user(name=username)
 
    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):
 
    test_user_1 = 'testme'
 

	
 
    @classmethod
0 comments (0 inline, 0 general)