Changeset - 1ba7e0c0d3b3
[Not reviewed]
default
0 2 0
Thomas De Schampheleire - 9 years ago 2016-07-29 22:04:53
thomas.de.schampheleire@gmail.com
tests: admin_permissions: make sure all custom IP permissions are cleared

test_add_ips 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.

Attempt a direct delete to the database without relying on the application
post/get interface.
2 files changed with 19 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/conftest.py
Show inline comments
 
@@ -6,13 +6,14 @@ import pkg_resources
 
from paste.deploy import loadapp
 
import pylons.test
 
from pylons.i18n.translation import _get_translator
 
import pytest
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.db import Setting, User
 
from kallithea.model.db import Setting, User, UserIpMap
 
from kallithea.tests import invalidate_all_caches
 

	
 

	
 
def pytest_configure():
 
    path = os.getcwd()
 
    sys.path.insert(0, path)
 
    pkg_resources.working_set.add_entry(path)
 
@@ -81,6 +82,22 @@ def set_test_settings():
 
    for k, v, t in settings_snapshot:
 
        if t == 'list' and hasattr(v, '__iter__'):
 
            v = ','.join(v) # Quirk: must format list value manually.
 
        s = Setting.create_or_update(k, v, t)
 
        session.add(s)
 
    session.commit()
 

	
 
@pytest.yield_fixture
 
def auto_clear_ip_permissions():
 
    """Fixture that provides nothing but clearing IP permissions upon test
 
    exit. This clearing is needed to avoid other test failing to make fake http
 
    accesses."""
 
    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)
 

	
 
    # IP permissions are cached, need to invalidate this cache explicitly
 
    invalidate_all_caches()
kallithea/tests/functional/test_admin_permissions.py
Show inline comments
 
@@ -13,13 +13,13 @@ class TestAdminPermissionsController(Tes
 
    def test_index_ips(self):
 
        self.log_user()
 
        response = self.app.get(url('admin_permissions_ips'))
 
        # Test response...
 
        response.mustcontain('All IP addresses are allowed')
 

	
 
    def test_add_ips(self):
 
    def test_add_ips(self, auto_clear_ip_permissions):
 
        self.log_user()
 
        default_user_id = User.get_default_user().user_id
 
        response = self.app.post(url('edit_user_ips_update', id=default_user_id),
 
                                 params=dict(new_ip='127.0.0.0/24',
 
                                 _authentication_token=self.authentication_token()))
 

	
0 comments (0 inline, 0 general)