Files @ 9211cc737587
Branch filter:

Location: kallithea/kallithea/tests/functional/test_admin_permissions.py

Thomas De Schampheleire
pytest migration: search: use tmpdir fixture instead of 'current dir'

The test_empty_search method needs to refer to an existing directory that is
guaranteed to not contain a search index. The current implementation chose
the 'current' directory '.' but it is more of a hack than careful planning.
A temporary empty directory would be cleaner but was more involved to
create.

With the introduction of pytest-style test classes, this can very easily
be improved. Creating a temporary directory with pytest is as simple as
accepting the magic 'tmpdir' argument to the test method. This 'tmpdir' is
a fixture provided by pytest. The variable is initialized with a
py.path.local object referring a temporary directory. For details, see:
http://pytest.org/latest/tmpdir.html
from kallithea.model.db import User, UserIpMap
from kallithea.tests import *

class TestAdminPermissionsController(TestController):

    def test_index(self):
        self.log_user()
        response = self.app.get(url('admin_permissions'))
        # Test response...

    def test_index_ips(self):
        self.log_user()
        response = self.app.get(url('admin_permissions_ips'))
        # Test response...
        response.mustcontain('All IP addresses are allowed')

    def test_add_ips(self):
        self.log_user()
        default_user_id = User.get_default_user().user_id
        response = self.app.put(url('edit_user_ips', id=default_user_id),
                                 params=dict(new_ip='127.0.0.0/24',
                                 _authentication_token=self.authentication_token()))

        response = self.app.get(url('admin_permissions_ips'))
        response.mustcontain('127.0.0.0/24')
        response.mustcontain('127.0.0.0 - 127.0.0.255')

        ## delete
        default_user_id = User.get_default_user().user_id
        del_ip_id = UserIpMap.query().filter(UserIpMap.user_id ==
                                             default_user_id).first().ip_id

        response = self.app.post(url('edit_user_ips', id=default_user_id),
                                 params=dict(_method='delete',
                                             del_ip_id=del_ip_id,
                                             _authentication_token=self.authentication_token()))

        response = self.app.get(url('admin_permissions_ips'))
        response.mustcontain('All IP addresses are allowed')
        response.mustcontain(no=['127.0.0.0/24'])
        response.mustcontain(no=['127.0.0.0 - 127.0.0.255'])


    def test_index_overview(self):
        self.log_user()
        response = self.app.get(url('admin_permissions_perms'))
        # Test response...