Exemplo n.º 1
0
class AskViewTests(unittest.TestCase):
    """Test for Askview

    Contain all the tests for the askView class
    """

    def setUp(self):
        """Set up the configuration to access the triplestore

        Use the config file test.virtuoso.ini to not interfere with
        production data
        """

        self.settings = get_appsettings('configs/tests.ini', name='main')
        self.settings['askomics.upload_user_data_method'] = 'insert'

        self.request = testing.DummyRequest()

        self.config = testing.setUp(request=self.request)
        self.config.add_route('load_data_into_graph', '/load_data_into_graph')
        self.config.scan()

        self.request.session['user_id'] = 1
        self.request.session['username'] = '******'
        self.request.session['email'] = '*****@*****.**'
        self.request.session['admin'] = True
        self.request.session['blocked'] = False
        self.request.session['graph'] = 'urn:sparql:test_askomics:jdoe'

        self.request.host_url = 'http://*****:*****@example.com',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        data = self.askview.signup()

        assert data == {'error': [], 'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': True, 'blocked': False, 'galaxy': None}

    def test_checkuser(self):
        """Test checkuser method"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        data = self.askview.checkuser()

        assert data == {'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': False, 'blocked': False, 'galaxy': None}


    def test_logout(self):
        """Test logout method"""

        self.tps.clean_up()

        self.askview.logout()

        assert self.request.session == {}


    def test_login(self):
        """Test login method"""

        self.tps.clean_up()

        #first, create a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # then, logout this user
        self.askview.logout()

        # and then, test login
        self.request.json_body = {
            'username_email': 'jdoe',
            'password': '******'
        }

        data = self.askview.login()

        assert data == {'error': [], 'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': True, 'blocked': False, 'galaxy': None}

    def test_login_api(self):
        """Test login_api method"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        self.request.GET['key'] = 'jdoe_apikey'

        data = self.askview.login_api()

        assert data == {'error': '', 'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': False, 'blocked': False, 'galaxy': None}

    def test_login_api_gie(self):
        """Test login_api_gie method"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        self.request.GET['key'] = 'jdoe_apikey'

        self.askview.login_api()

    def test_get_users_infos(self):
        """Test get_users_infos"""

        self.tps.clean_up()
        # first test with non admin
        try :
            data = self.askview.get_users_infos()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.get_users_infos()

        assert data == {'result': [], 'me': 'jdoe'} #result is empty cause there is no user

        #test with user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        # get dir size
        pm = ParamManager(self.settings, self.request.session)
        dir_size = pm.get_size(pm.get_user_dir_path())
        human_dir_size = humanize.naturalsize(dir_size)

        self.askview.signup()

        data = self.askview.get_users_infos()

        assert data == {'result': [{'ldap': False, 'username': '******', 'email': '*****@*****.**', 'admin': True, 'blocked': False, 'gurl': None, 'nquery': 0, 'nintegration': 0, 'dirsize': dir_size, 'hdirsize': human_dir_size}], 'me': 'jdoe', 'error': [], 'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': True, 'blocked': False, 'galaxy': None}

    def test_lock_user(self):
        """Test lock_user method"""

        self.tps.clean_up()

        self.request.json_body = {
            'username': '******',
            'lock': True
        }

        # first test with non admin

        try:
            data = self.askview.lock_user()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.lock_user()

        assert data == 'success'


    def test_set_admin(self):
        """Test set_admin_method"""

        self.tps.clean_up()

        self.request.json_body = {
            'username': '******',
            'admin': True
        }

        try:
            data = self.askview.set_admin()
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.set_admin()

        assert data == 'success'

    def test_delete_user(self):
        """Test delete_user method"""

        self.tps.clean_up()

        # Insert a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # test the deletion
        self.request.json_body = {
            'username': '******',
            'passwd': 'iamjohndoe',
            'passwd_conf': 'iamjohndoe'
        }

        self.request.session['blocked'] = False
        self.request.session['admin'] = False
        self.request.session['username'] = '******'

        data = self.askview.delete_user()

        assert data == 'success'


    def test_get_my_infos(self):
        """Test get_my_infos"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # get my infos
        data = self.askview.get_my_infos()

        assert data == {'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': False, 'blocked': False, 'apikey': 'jdoe_apikey', 'galaxy': None, 'ldap': False}

    def test_update_mail(self):
        """Test update_mail"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # And change my email
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**'
        }

        data = self.askview.update_mail()

        assert data == {'success': 'success'}

    def test_update_passwd(self):
        """Test update_passwd method"""

        self.tps.clean_up()

        # First, insert me
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # And update my password
        self.request.json_body = {
            'username': '******',
            'current_passwd': 'iamjohndoe',
            'passwd': 'mynewpassword',
            'passwd2': 'mynewpassword',
        }

        data = self.askview.update_passwd()

        assert data == {'error': [], 'user_id': 1, 'username': '******', 'email': '*****@*****.**', 'admin': True, 'blocked': False, 'galaxy': None, 'success': 'success'}
Exemplo n.º 2
0
class AskViewTests(unittest.TestCase):
    """Test for Askview

    Contain all the tests for the askView class
    """

    def setUp(self):
        """Set up the configuration to access the triplestore

        Use the config file test.virtuoso.ini to not interfere with
        production data
        """

        self.settings = get_appsettings('configs/test.virtuoso.ini', name='main')
        self.settings['askomics.upload_user_data_method'] = 'insert'

        self.request = testing.DummyRequest()

        self.config = testing.setUp(request=self.request)
        self.config.add_route('load_data_into_graph', '/load_data_into_graph')
        self.config.scan()

        self.request.session['username'] = '******'
        self.request.session['blocked'] = False
        self.request.session['group'] = 'base'
        self.request.session['graph'] = 'urn:sparql:test_askomics:jdoe'

        self.request.host_url = 'http://*****:*****@example.com',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        data = self.askview.signup()

        assert data == {'error': [], 'blocked': False, 'admin': True, 'username': '******'}

    def test_checkuser(self):
        """Test checkuser method"""

        self.tps.clean_up()

        data = self.askview.checkuser()

        assert data == {'admin': False, 'username': '******', 'blocked': False, 'galaxy': False}


    def test_logout(self):
        """Test logout method"""

        self.tps.clean_up()

        self.askview.logout()

        assert self.request.session == {}


    def test_login(self):
        """Test login method"""

        self.tps.clean_up()

        #first, create a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # then, logout this user
        self.askview.logout()

        # and then, test login
        self.request.json_body = {
            'username_email': 'jdoe',
            'password': '******'
        }

        data = self.askview.login()

        assert data == {'blocked': False, 'admin': True, 'error': [], 'username': '******'}

    def test_get_users_infos(self):
        """Test get_users_infos"""

        self.tps.clean_up()
        # first test with non admin
        try :
            data = self.askview.get_users_infos()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.get_users_infos()

        assert data == {'result': []} #result is empty cause there is no user

        #test with user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        data = self.askview.get_users_infos()

        assert data == {'result': [], 'error': [], 'admin': True, 'blocked': False, 'username': '******'}

    def test_lock_user(self):
        """Test lock_user method"""

        self.tps.clean_up()

        self.request.json_body = {
            'username': '******',
            'lock': True
        }

        # first test with non admin

        try:
            data = self.askview.lock_user()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.lock_user()

        assert data == 'success'


    def test_set_admin(self):
        """Test set_admin_method"""

        self.tps.clean_up()

        self.request.json_body = {
            'username': '******',
            'admin': True
        }

        try:
            data = self.askview.set_admin()
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.set_admin()

        assert data == 'success'

    def test_delete_user(self):
        """Test delete_user method"""

        self.tps.clean_up()

        # Insert a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # test the deletion
        self.request.json_body = {
            'username': '******',
            'passwd': 'iamjohndoe',
            'passwd_conf': 'iamjohndoe'
        }

        self.request.session['blocked'] = False
        self.request.session['admin'] = False
        self.request.session['username'] = '******'

        data = self.askview.delete_user()

        assert data == 'success'


    def test_get_my_infos(self):
        """Test get_my_infos"""

        self.tps.clean_up()

        # First, insert me
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # get my infos
        data = self.askview.get_my_infos()

        assert data == {'email': '*****@*****.**', 'username': '******', 'apikeys': [], 'blocked': False, 'admin': True}

    def test_update_mail(self):
        """Test update_mail"""

        self.tps.clean_up()

        # First, insert me
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # And change my email
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**'
        }

        data = self.askview.update_mail()

        assert data == {'username': '******', 'error': [], 'success': 'success', 'blocked': False, 'admin': True}

    def test_update_passwd(self):
        """Test update_passwd method"""

        self.tps.clean_up()

        # First, insert me
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # And update my password
        self.request.json_body = {
            'username': '******',
            'current_passwd': 'iamjohndoe',
            'passwd': 'mynewpassword',
            'passwd2': 'mynewpassword',
        }

        data = self.askview.update_passwd()

        assert data == {'error': [], 'admin': True, 'blocked': False, 'username': '******', 'success': 'success'}
Exemplo n.º 3
0
class AskViewTests(unittest.TestCase):
    """Test for Askview

    Contain all the tests for the askView class
    """
    def setUp(self):
        """Set up the configuration to access the triplestore

        Use the config file test.virtuoso.ini to not interfere with
        production data
        """

        self.settings = get_appsettings('configs/tests.ini', name='main')
        self.settings['askomics.upload_user_data_method'] = 'insert'

        self.request = testing.DummyRequest()

        self.config = testing.setUp(request=self.request)
        self.config.add_route('load_data_into_graph', '/load_data_into_graph')
        self.config.scan()

        self.request.session['username'] = '******'
        self.request.session['blocked'] = False
        self.request.session['group'] = 'base'
        self.request.session['graph'] = 'urn:sparql:test_askomics:jdoe'

        self.request.host_url = 'http://*****:*****@example.com',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        data = self.askview.signup()

        assert data == {
            'error': [],
            'blocked': False,
            'admin': True,
            'username': '******',
            'galaxy': False
        }

    def test_checkuser(self):
        """Test checkuser method"""

        self.tps.clean_up()

        data = self.askview.checkuser()

        assert data == {
            'admin': False,
            'username': '******',
            'blocked': False,
            'galaxy': False
        }

    def test_logout(self):
        """Test logout method"""

        self.tps.clean_up()

        self.askview.logout()

        assert self.request.session == {}

    def test_login(self):
        """Test login method"""

        self.tps.clean_up()

        #first, create a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # then, logout this user
        self.askview.logout()

        # and then, test login
        self.request.json_body = {
            'username_email': 'jdoe',
            'password': '******'
        }

        data = self.askview.login()

        assert data == {
            'blocked': False,
            'admin': True,
            'error': [],
            'username': '******',
            'galaxy': False
        }

    def test_login_api(self):
        """Test login_api method"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # then, try to log with API key
        self.request.json_body = {'apikey': 'jdoe_apikey'}

        data = self.askview.login_api()

        assert data == {
            'admin': False,
            'blocked': False,
            'username': '******',
            'error': ''
        }

    def test_login_api_gie(self):
        """Test login_api_gie method"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # then, try to log with API key
        self.request.json_body = {'apikey': 'jdoe_apikey'}

        self.askview.login_api()

    def test_get_users_infos(self):
        """Test get_users_infos"""

        self.tps.clean_up()
        # first test with non admin
        try:
            data = self.askview.get_users_infos()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.get_users_infos()

        assert data == {'result': []}  #result is empty cause there is no user

        #test with user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        data = self.askview.get_users_infos()

        assert data == {
            'result': [{
                'username': '******',
                'email': '*****@*****.**',
                'admin': True,
                'blocked': False
            }],
            'error': [],
            'username':
            '******',
            'admin':
            True,
            'blocked':
            False,
            'galaxy':
            False
        }

    def test_lock_user(self):
        """Test lock_user method"""

        self.tps.clean_up()

        self.request.json_body = {'username': '******', 'lock': True}

        # first test with non admin

        try:
            data = self.askview.lock_user()
            assert False
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.lock_user()

        assert data == 'success'

    def test_set_admin(self):
        """Test set_admin_method"""

        self.tps.clean_up()

        self.request.json_body = {'username': '******', 'admin': True}

        try:
            data = self.askview.set_admin()
        except Exception as e:
            assert True

        # then, is user is admin
        self.request.session['admin'] = True

        data = self.askview.set_admin()

        assert data == 'success'

    def test_delete_user(self):
        """Test delete_user method"""

        self.tps.clean_up()

        # Insert a user
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # test the deletion
        self.request.json_body = {
            'username': '******',
            'passwd': 'iamjohndoe',
            'passwd_conf': 'iamjohndoe'
        }

        self.request.session['blocked'] = False
        self.request.session['admin'] = False
        self.request.session['username'] = '******'

        data = self.askview.delete_user()

        assert data == 'success'

    def test_get_my_infos(self):
        """Test get_my_infos"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # get my infos
        data = self.askview.get_my_infos()

        assert data == {
            'email': '*****@*****.**',
            'username': '******',
            'apikey': 'jdoe_apikey',
            'blocked': False,
            'admin': False
        }

    def test_update_mail(self):
        """Test update_mail"""

        self.tps.clean_up()
        self.tps.add_jdoe_in_users()

        # And change my email
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**'
        }

        data = self.askview.update_mail()

        assert data == {'success': 'success'}

    def test_update_passwd(self):
        """Test update_passwd method"""

        self.tps.clean_up()

        # First, insert me
        self.request.json_body = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'iamjohndoe'
        }

        self.askview.signup()

        # And update my password
        self.request.json_body = {
            'username': '******',
            'current_passwd': 'iamjohndoe',
            'passwd': 'mynewpassword',
            'passwd2': 'mynewpassword',
        }

        data = self.askview.update_passwd()

        assert data == {
            'error': [],
            'admin': True,
            'blocked': False,
            'username': '******',
            'success': 'success',
            'galaxy': False
        }