# HG changeset patch # User Thomas De Schampheleire # Date 1471639099 -7200 # Node ID e56d11a19d3c3924cbdea2d6bf41cb7a042d5746 # Parent 4d7dcd25c1491aafd6b3f5b0a2e6831de64f66fc tests: admin_users: make sure repo group is deleted test_delete_repo_group_err creates then deletes a repository group. However, if the delete fails the repository group remains. This later causes problems in the model tests. Introduce a pytest yield fixture to handle the creation _and_ deletion of the repository group (suggested by Søren Løvborg). The creation of the user needs to happen _before_ that of the user group, and we cannot share data between two pytest fixtures, so the user is created in the fixture as well. diff -r 4d7dcd25c149 -r e56d11a19d3c kallithea/tests/functional/test_admin_users.py --- a/kallithea/tests/functional/test_admin_users.py Wed Jul 06 17:56:14 2016 +0200 +++ b/kallithea/tests/functional/test_admin_users.py Fri Aug 19 22:38:19 2016 +0200 @@ -12,7 +12,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from sqlalchemy.orm.exc import NoResultFound +from sqlalchemy.orm.exc import NoResultFound, ObjectDeletedError import pytest from kallithea.tests import * @@ -28,6 +28,19 @@ fixture = Fixture() +@pytest.yield_fixture +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: + fixture.destroy_repo_group(repo_group) + except ObjectDeletedError: + # delete already succeeded in test body + pass class TestAdminUsersController(TestController): test_user_1 = 'testme' @@ -201,14 +214,11 @@ params={'_authentication_token': self.authentication_token()}) self.checkSessionFlash(response, 'Successfully deleted user') - def test_delete_repo_group_err(self): + def test_delete_repo_group_err(self, user_and_repo_group_fail): self.log_user() username = 'repogrouperr' groupname = u'repogroup_fail' - fixture.create_user(name=username) - fixture.create_repo_group(name=groupname, cur_user=username) - new_user = Session().query(User) \ .filter(User.username == username).one() response = self.app.post(url('delete_user', id=new_user.user_id),