Changeset - e56d11a19d3c
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 9 years ago 2016-08-19 22:38:19
thomas.de.schampheleire@gmail.com
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.
1 file changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -9,13 +9,13 @@
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# 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 *
 
from kallithea.tests.fixture import Fixture
 
from kallithea.controllers.admin.users import UsersController
 
from kallithea.model.db import User, Permission, UserIpMap, UserApiKeys
 
@@ -25,12 +25,25 @@ from kallithea.model import validators
 
from kallithea.lib import helpers as h
 
from kallithea.model.meta import Session
 
from webob.exc import HTTPNotFound
 

	
 
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'
 

	
 
    @classmethod
 
    def teardown_class(cls):
 
@@ -198,20 +211,17 @@ class TestAdminUsersController(TestContr
 
        self.checkSessionFlash(response, 'Deleted repository %s' % reponame)
 

	
 
        response = self.app.post(url('delete_user', id=new_user.user_id),
 
            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),
 
            params={'_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'User "%s" still '
 
                               'owns 1 repository groups and cannot be removed. '
0 comments (0 inline, 0 general)