# HG changeset patch # User Thomas De Schampheleire # Date 1469822693 -7200 # Node ID 1ba7e0c0d3b3e62a936d2ac9ee35aab75a5fd1e0 # Parent ee88c8c07111d4395b082739b7347926d0228582 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. diff -r ee88c8c07111 -r 1ba7e0c0d3b3 kallithea/tests/conftest.py --- a/kallithea/tests/conftest.py Fri Aug 19 20:50:26 2016 +0200 +++ b/kallithea/tests/conftest.py Fri Jul 29 22:04:53 2016 +0200 @@ -9,7 +9,8 @@ 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 @@ 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() diff -r ee88c8c07111 -r 1ba7e0c0d3b3 kallithea/tests/functional/test_admin_permissions.py --- a/kallithea/tests/functional/test_admin_permissions.py Fri Aug 19 20:50:26 2016 +0200 +++ b/kallithea/tests/functional/test_admin_permissions.py Fri Jul 29 22:04:53 2016 +0200 @@ -16,7 +16,7 @@ # 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),