class AskViewTests(unittest.TestCase): def setUp(self): self.settings = get_appsettings('configs/development.virtuoso.ini', name='main') 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['upload_directory'] = os.path.join( os.path.dirname(__file__), "..", "test-data") self.temp_directory = tempfile.mkdtemp() self.it = InterfaceTPS(self.settings, self.request) self.askview = AskView(self.request) self.askview.settings = self.settings self.timestamp = str(time.time()) def tearDown(self): shutil.rmtree(self.temp_directory) def test_start_points(self): #load files self.it.empty() self.it.load_test2() data = self.askview.start_points() resAttendu = { 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne': { 'label': 'Personne', 'uri': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne' }, 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Instrument': { 'label': 'Instrument', 'uri': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Instrument' } } for elt in data["nodes"]: assert data["nodes"][elt] == resAttendu[elt] assert len(data["nodes"]) == 2 def test_statistics(self): #load files self.it.empty() self.it.load_test2() ql = QueryLauncher(self.settings, self.request.session) queryResults = ql.insert_data(':sujet :predicat :objet .', 'test', 'prefix :<test>') server = queryResults.info()['server'] self.request.json_body = {'namedGraphs': ['test']} self.askview.delete_graph() data = self.askview.statistics() assert data['ntriples'] == 279 assert data['nclasses'] == '6' assert data['nentities'] == '19' assert data['ngraphs'] == '5' assert data['class'] == { 'Personne': { 'count': '7' }, 'Sexe': { 'count': '2' }, 'Instrument': { 'count': '2' } } for key in data['metadata'].keys(): self.assertRegexpMatches( key, r'^urn:sparql:(instrument|enseigne|connait|joue|personne)\.tsv_[0-9]+\.[0-9]+$' ) for key2 in data['metadata'][key]: self.assertRegexpMatches( key2, r'^(version|username|filename|loadDate|server)$') if key2 == 'version': assert data['metadata'][key][key2] == '2.0' elif key2 == 'username': assert data['metadata'][key][key2] == getpass.getuser() elif key2 == 'filename': self.assertRegexpMatches( data['metadata'][key][key2], r'^(instrument|enseigne|connait|joue|personne)\.tsv$') elif key2 == 'loadDate': self.assertRegexpMatches(data['metadata'][key][key2], r'^[0-9]+\.[0-9]+$') elif key2 == 'server': assert data['metadata'][key][key2] == server def test_empty_database(self): self.it.empty() self.it.load_test2() self.askview.empty_database() def test_delete_graph(self): self.it.empty() self.it.load_test2() date = self.timestamp self.request.json_body = { 'namedGraphs': [ 'urn:sparql:personne.tsv_' + date, 'urn:sparql:enseigne.tsv_' + date, 'urn:sparql:connait.tsv_' + date, 'urn:sparql:instrument.tsv_' + date, 'urn:sparql:joue.tsv_' + date ] } self.askview.delete_graph() def test_get_list_named_graphs(self): self.it.empty() self.it.load_test2() namedGraphs = self.askview.get_list_named_graphs() date = self.timestamp resAttendu = [ 'urn:sparql:personne.tsv_' + date, 'urn:sparql:enseigne.tsv_' + date, 'urn:sparql:connait.tsv_' + date, 'urn:sparql:instrument.tsv_' + date, 'urn:sparql:joue.tsv_' + date ] assert namedGraphs.sort() == resAttendu.sort() def test_source_files_overview(self): data = self.askview.source_files_overview() def test_preview_ttl(self): self.request.json_body = { 'file_name': 'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns': [] } data = self.askview.preview_ttl() def test_check_existing_data(self): self.request.json_body = { 'file_name': 'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns': [] } data = self.askview.check_existing_data() # catch error self.request.json_body = { 'file_name': 'personneeee.tsv', 'col_types': {}, 'disabled_columns': 1 } data = self.askview.check_existing_data() def test_load_data_into_graph(self): self.request.json_body = { 'file_name': 'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns': [] } data = self.askview.load_data_into_graph() def test_getUserAbstraction(self): #load files self.it.empty() self.it.load_test1() data = self.askview.getUserAbstraction() def test_get_value(self): #load files self.it.empty() self.it.load_test1() self.request.json_body = { 'variates': ['?Personne1'], 'constraintesRelations': [[ '?URIPersonne1 rdf:type <http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne>', '?URIPersonne1 rdfs:label ?Personne1' ], ''], 'limit': 30, 'export': False, } data = self.askview.get_value() self.request.json_body['export'] = True data = self.askview.get_value() # manage an error self.request.json_body = {} data = self.askview.get_value() def test_get_valuetxtquery(self): #load files self.it.empty() self.it.load_test1() self.request.json_body = { 'variates': ['?Personne1'], 'constraintesRelations': [[ '?URIPersonne1 rdf:type <http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne>', '?URIPersonne1 rdfs:label ?Personne1' ], ''], 'limit': 30, 'export': False, } data = self.askview.getSparqlQueryInTextFormat() # manage an error self.request.json_body = {} data = self.askview.getSparqlQueryInTextFormat() def test_positionable_attr(self): self.it.empty() self.it.load_test3() self.request.json_body = { 'node': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#transcript', 'second_node': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#qtl', } resAttendu = { 'results': { 'position_ref': True, 'position_strand': False, 'position_taxon': True } } data = self.askview.positionable_attr() assert data == resAttendu
class AskViewTests(unittest.TestCase): def setUp( self ): self.settings = get_appsettings('configs/development.virtuoso.ini', name='main') 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['upload_directory'] = os.path.join( os.path.dirname( __file__ ), "..", "test-data") self.temp_directory = tempfile.mkdtemp() self.it = InterfaceTPS(self.settings,self.request) self.askview = AskView(self.request) self.askview.settings = self.settings self.timestamp = str(time.time()) def tearDown( self ): shutil.rmtree( self.temp_directory ) def test_start_points(self): #load files self.it.empty() self.it.load_test2() data = self.askview.start_points() resAttendu = { 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne': {'label': 'Personne', 'uri': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne'}, 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Instrument': {'label': 'Instrument', 'uri': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Instrument'} } for elt in data["nodes"]: assert data["nodes"][elt] == resAttendu[elt] assert len(data["nodes"]) == 2 def test_statistics(self): #load files self.it.empty() self.it.load_test2() ql = QueryLauncher(self.settings, self.request.session) queryResults = ql.insert_data(':sujet :predicat :objet .', 'test', 'prefix :<test>') server = queryResults.info()['server'] self.request.json_body = {'namedGraphs': ['test']} self.askview.delete_graph() data = self.askview.statistics() assert data['ntriples'] == 279 assert data['nclasses'] == '6' assert data['nentities'] == '19' assert data['ngraphs'] == '5' assert data['class'] == { 'Personne': {'count': '7'}, 'Sexe': {'count': '2'}, 'Instrument': {'count': '2'} } for key in data['metadata'].keys(): self.assertRegexpMatches(key, r'^urn:sparql:(instrument|enseigne|connait|joue|personne)\.tsv_[0-9]+\.[0-9]+$') for key2 in data['metadata'][key]: self.assertRegexpMatches(key2, r'^(version|username|filename|loadDate|server)$') if key2 == 'version': assert data['metadata'][key][key2] == '2.0' elif key2 == 'username': assert data['metadata'][key][key2] == getpass.getuser() elif key2 == 'filename': self.assertRegexpMatches(data['metadata'][key][key2], r'^(instrument|enseigne|connait|joue|personne)\.tsv$') elif key2 == 'loadDate': self.assertRegexpMatches(data['metadata'][key][key2], r'^[0-9]+\.[0-9]+$') elif key2 == 'server': assert data['metadata'][key][key2] == server def test_empty_database(self): self.it.empty() self.it.load_test2() self.askview.empty_database() def test_delete_graph(self): self.it.empty() self.it.load_test2() date = self.timestamp self.request.json_body = { 'namedGraphs': [ 'urn:sparql:personne.tsv_'+ date, 'urn:sparql:enseigne.tsv_'+ date, 'urn:sparql:connait.tsv_'+ date, 'urn:sparql:instrument.tsv_'+ date, 'urn:sparql:joue.tsv_'+ date ] } self.askview.delete_graph() def test_get_list_named_graphs(self): self.it.empty() self.it.load_test2() namedGraphs = self.askview.get_list_named_graphs() date = self.timestamp resAttendu = [ 'urn:sparql:personne.tsv_'+ date, 'urn:sparql:enseigne.tsv_'+ date, 'urn:sparql:connait.tsv_'+ date, 'urn:sparql:instrument.tsv_'+ date, 'urn:sparql:joue.tsv_'+ date ] assert namedGraphs.sort() == resAttendu.sort() def test_source_files_overview(self): data = self.askview.source_files_overview() def test_preview_ttl(self): self.request.json_body = { 'file_name':'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns':[] } data = self.askview.preview_ttl() def test_check_existing_data(self): self.request.json_body = { 'file_name':'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns':[] } data = self.askview.check_existing_data(); # catch error self.request.json_body = { 'file_name':'personneeee.tsv', 'col_types': {}, 'disabled_columns':1 } data = self.askview.check_existing_data(); def test_load_data_into_graph(self): self.request.json_body = { 'file_name':'personne.tsv', 'col_types': ['entity_start', 'text', 'category', 'numeric', 'text'], 'disabled_columns':[] } data = self.askview.load_data_into_graph(); def test_getUserAbstraction(self): #load files self.it.empty() self.it.load_test1() data = self.askview.getUserAbstraction(); def test_get_value(self): #load files self.it.empty() self.it.load_test1() self.request.json_body = { 'variates':['?Personne1'], 'constraintesRelations': [ ['?URIPersonne1 rdf:type <http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne>','?URIPersonne1 rdfs:label ?Personne1'],''], 'limit': 30, 'export': False, } data = self.askview.get_value() self.request.json_body['export'] = True data = self.askview.get_value() # manage an error self.request.json_body = { } data = self.askview.get_value() def test_get_valuetxtquery(self): #load files self.it.empty() self.it.load_test1() self.request.json_body = { 'variates':['?Personne1'], 'constraintesRelations': [['?URIPersonne1 rdf:type <http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#Personne>','?URIPersonne1 rdfs:label ?Personne1'],''], 'limit': 30, 'export': False, } data = self.askview.getSparqlQueryInTextFormat() # manage an error self.request.json_body = { } data = self.askview.getSparqlQueryInTextFormat() def test_positionable_attr(self): self.it.empty() self.it.load_test3() self.request.json_body = { 'node' : 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#transcript', 'second_node' : 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#qtl', } resAttendu = { 'results' : {'position_ref': True, 'position_strand': False, 'position_taxon': True} } data = self.askview.positionable_attr() assert data == resAttendu
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'}
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'}
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 }