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
 
@@ -9,7 +9,8 @@ from pylons.i18n.translation import _get
 
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():
 
@@ -84,3 +85,19 @@ def set_test_settings():
 
        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
 
@@ -16,7 +16,7 @@ class TestAdminPermissionsController(Tes
 
        # 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),
0 comments (0 inline, 0 general)