Mercurial > kallithea
changeset 6141:1ba7e0c0d3b3
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.
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Fri, 29 Jul 2016 22:04:53 +0200 |
parents | ee88c8c07111 |
children | 437b41b18420 |
files | kallithea/tests/conftest.py kallithea/tests/functional/test_admin_permissions.py |
diffstat | 2 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- 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),