Mercurial > kallithea
changeset 6143:4d7dcd25c149
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.
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Wed, 06 Jul 2016 17:56:14 +0200 |
parents | 437b41b18420 |
children | e56d11a19d3c |
files | kallithea/tests/conftest.py kallithea/tests/functional/test_admin_users.py |
diffstat | 2 files changed, 11 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/tests/conftest.py Fri Aug 19 21:32:23 2016 +0200 +++ b/kallithea/tests/conftest.py Wed Jul 06 17:56:14 2016 +0200 @@ -10,7 +10,7 @@ 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 @@ 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()
--- a/kallithea/tests/functional/test_admin_users.py Fri Aug 19 21:32:23 2016 +0200 +++ b/kallithea/tests/functional/test_admin_users.py Wed Jul 06 17:56:14 2016 +0200 @@ -394,7 +394,7 @@ ('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 @@ 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