Changeset - 4d7dcd25c149
[Not reviewed]
default
0 2 0
Thomas De Schampheleire - 9 years ago 2016-07-06 17:56:14
thomas.de.schampheleire@gmail.com
tests: admin_users: make sure all custom IP permissions are cleared

test_delete_ip changes IP permissions and at the end tries to clean up by
deleting it again. When the delete fails, there is still a restricted IP
permission configuration, causing other tests to fail.
Use the recently added pytest fixture auto_clear_ip_permissions to fix this.
The fixture is extended to not only clear IP permissions for the default
user, but also for the 'regular' test user.

Similar cleanup code in test_add_ip is deleted because it serves the same
purpose, but would fail to execute if something went wrong earlier in the
test method.

This commit is very similar to an earlier commit that covers similar
add/delete IP functionality for the default user, in test_permissions.py.
2 files changed with 11 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/conftest.py
Show inline comments
 
@@ -10,7 +10,7 @@ import pytest
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.db import Setting, User, UserIpMap
 
from kallithea.tests import invalidate_all_caches
 
from kallithea.tests import invalidate_all_caches, TEST_USER_REGULAR_LOGIN
 

	
 

	
 
def pytest_configure():
 
@@ -94,10 +94,14 @@ def auto_clear_ip_permissions():
 
    yield
 
    # cleanup
 
    user_model = UserModel()
 
    default_user_id = User.get_default_user().user_id
 
    for ip in UserIpMap.query().filter(UserIpMap.user_id ==
 
                                       default_user_id):
 
        user_model.delete_extra_ip(default_user_id, ip.ip_id)
 

	
 
    user_ids = []
 
    user_ids.append(User.get_default_user().user_id)
 
    user_ids.append(User.get_by_username(TEST_USER_REGULAR_LOGIN).user_id)
 

	
 
    for user_id in user_ids:
 
        for ip in UserIpMap.query().filter(UserIpMap.user_id == user_id):
 
            user_model.delete_extra_ip(user_id, ip.ip_id)
 

	
 
    # IP permissions are cached, need to invalidate this cache explicitly
 
    invalidate_all_caches()
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -394,7 +394,7 @@ class TestAdminUsersController(TestContr
 
        ('127_bad_mask', '127.0.0.1/99', '127.0.0.1 - 127.0.0.1', True),
 
        ('127_bad_ip', 'foobar', 'foobar', True),
 
    ])
 
    def test_add_ip(self, test_name, ip, ip_range, failure):
 
    def test_add_ip(self, test_name, ip, ip_range, failure, auto_clear_ip_permissions):
 
        self.log_user()
 
        user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
 
        user_id = user.user_id
 
@@ -413,12 +413,7 @@ class TestAdminUsersController(TestContr
 
            response.mustcontain(ip)
 
            response.mustcontain(ip_range)
 

	
 
        ## cleanup
 
        for del_ip in UserIpMap.query().filter(UserIpMap.user_id == user_id).all():
 
            Session().delete(del_ip)
 
            Session().commit()
 

	
 
    def test_delete_ip(self):
 
    def test_delete_ip(self, auto_clear_ip_permissions):
 
        self.log_user()
 
        user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
 
        user_id = user.user_id
0 comments (0 inline, 0 general)