Changeset - 437b41b18420
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 9 years ago 2016-08-19 21:32:23
thomas.de.schampheleire@gmail.com
tests: admin_permissions: split test_delete_ips from test_add_ips

While it is not necessary to be pedantic and split each assert in a separate
test, it makes sense to create separate tests for separate logical actions.
This makes it easy to understand from a test summary what works and what
doesn't.

Add and delete are deemed two such separate logical actions. The original
test_add_ips test did both add and delete, but was not even named to cover
this.

Note that the 'add' in the delete test is not the same as the 'add' in the
add test, i.e. for the delete test direct method calls are made instead of
passing through self.app.get/post (which is a higher layer of abstraction).

Background of this commit: during the Turbogears2 port, delete actions were
not yet functional, and 'test_add_ips' failed as a result even though 'add'
was perfectly fine.
1 file changed with 22 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_admin_permissions.py
Show inline comments
 
import time
 

	
 
from kallithea.model.db import User, UserIpMap
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.tests import *
 

	
 
class TestAdminPermissionsController(TestController):
 
@@ -34,13 +36,29 @@ class TestAdminPermissionsController(Tes
 
        response.mustcontain('127.0.0.0/24')
 
        response.mustcontain('127.0.0.0 - 127.0.0.255')
 

	
 
        ## delete
 
    def test_delete_ips(self, auto_clear_ip_permissions):
 
        self.log_user()
 
        default_user_id = User.get_default_user().user_id
 
        del_ip_id = UserIpMap.query().filter(UserIpMap.user_id ==
 
                                             default_user_id).first().ip_id
 

	
 
        ## first add
 
        new_ip = '127.0.0.0/24'
 
        user_model = UserModel()
 
        ip_obj = user_model.add_extra_ip(default_user_id, new_ip)
 
        Session().commit()
 

	
 
        ## double check that add worked
 
        # IP permissions are cached, need to invalidate this cache explicitly
 
        invalidate_all_caches()
 
        self.app.get(url('admin_permissions_ips'), status=302)
 
        # REMOTE_ADDR must match 127.0.0.0/24
 
        response = self.app.get(url('admin_permissions_ips'),
 
                                extra_environ={'REMOTE_ADDR': '127.0.0.1'})
 
        response.mustcontain('127.0.0.0/24')
 
        response.mustcontain('127.0.0.0 - 127.0.0.255')
 

	
 
        ## now delete
 
        response = self.app.post(url('edit_user_ips_delete', id=default_user_id),
 
                                 params=dict(del_ip_id=del_ip_id,
 
                                 params=dict(del_ip_id=ip_obj.ip_id,
 
                                             _authentication_token=self.authentication_token()),
 
                                 extra_environ={'REMOTE_ADDR': '127.0.0.1'})
 

	
0 comments (0 inline, 0 general)