Changeset - 8fbcdfe364d4
[Not reviewed]
default
0 1 0
Mads Kiilerich - 7 years ago 2019-01-03 01:03:14
mads@kiilerich.com
tests: make test_forks teardown more stable

It would sometimes fail like:

kallithea/tests/functional/test_forks.py:35: in teardown_method
Session().delete(self.u1)
data/env/lib/python2.7/site-packages/sqlalchemy/orm/session.py:1871: in delete
self._delete_impl(state, instance, head=True)
data/env/lib/python2.7/site-packages/sqlalchemy/orm/session.py:1888: in _delete_impl
self.identity_map.add(state)
data/env/lib/python2.7/site-packages/sqlalchemy/orm/identity.py:149: in add
orm_util.state_str(state), state.key))
E InvalidRequestError: Can't attach instance <User at 0x7f93d2f81a10>; another instance with key (<class 'kallithea.model.db.User'>, (10,), None) is already present in this session.
1 file changed with 8 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_forks.py
Show inline comments
 
@@ -27,12 +27,12 @@ class _BaseTestCase(TestController):
 
    def setup_method(self, method):
 
        self.username = u'forkuser'
 
        self.password = u'qweqwe'
 
        self.u1 = fixture.create_user(self.username, password=self.password,
 
                                      email=u'fork_king@example.com')
 
        u1 = fixture.create_user(self.username, password=self.password, email=u'fork_king@example.com')
 
        self.u1_id = u1.user_id
 
        Session().commit()
 

	
 
    def teardown_method(self, method):
 
        Session().delete(self.u1)
 
        fixture.destroy_user(self.u1_id)
 
        Session().commit()
 

	
 
    def test_index(self):
 
@@ -46,6 +46,7 @@ class _BaseTestCase(TestController):
 
    def test_no_permissions_to_fork(self):
 
        usr = self.log_user(TEST_USER_REGULAR_LOGIN,
 
                            TEST_USER_REGULAR_PASS)['user_id']
 
        try:
 
        user_model = UserModel()
 
        user_model.revoke_perm(usr, 'hg.fork.repository')
 
        user_model.grant_perm(usr, 'hg.fork.none')
 
@@ -56,6 +57,10 @@ class _BaseTestCase(TestController):
 
        repo_name = self.REPO
 
        self.app.post(url(controller='forks', action='fork_create',
 
                          repo_name=repo_name), {'_authentication_token': self.authentication_token()}, status=403)
 
        finally:
 
            user_model.revoke_perm(usr, 'hg.fork.none')
 
            user_model.grant_perm(usr, 'hg.fork.repository')
 
            Session().commit()
 

	
 
    def test_index_with_fork(self):
 
        self.log_user()
0 comments (0 inline, 0 general)