Mercurial > kallithea
changeset 6144:e56d11a19d3c
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.
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Fri, 19 Aug 2016 22:38:19 +0200 |
parents | 4d7dcd25c149 |
children | b1fc5a98952c |
files | kallithea/tests/functional/test_admin_users.py |
diffstat | 1 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 <http://www.gnu.org/licenses/>. -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),