<s> import json <EOL> from django . contrib . auth . models import User , Group <EOL> from django . utils import unittest <EOL> from guardian . shortcuts import assign_perm <EOL> import mockcache as memcache <EOL> from tastypie . test import ResourceTestCase <EOL> from core . api import AnalysisResource <EOL> from core . management . commands . init_refinery import create_public_group <EOL> from core . management . commands . create_user import init_user <EOL> from core . models import ( <EOL> NodeSet , create_nodeset , get_nodeset , delete_nodeset , update_nodeset , <EOL> ExtendedGroup , DataSet , InvestigationLink , Project , Analysis , Workflow , <EOL> WorkflowEngine , UserProfile , invalidate_cached_object , <EOL> AnalysisNodeConnection , Node ) <EOL> from file_store . models import FileExtension <EOL> import data_set_manager <EOL> from galaxy_connector . models import Instance <EOL> cache = memcache . Client ( [ "<STR_LIT>" ] ) <EOL> class UserCreateTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . username = "<STR_LIT>" <EOL> self . password = "<STR_LIT:password>" <EOL> self . email = "<STR_LIT>" <EOL> self . first_name = "<STR_LIT>" <EOL> self . last_name = "<STR_LIT>" <EOL> self . affiliation = "<STR_LIT>" <EOL> create_public_group ( ) <EOL> self . public_group_name = ExtendedGroup . objects . public_group ( ) . name <EOL> def tearDown ( self ) : <EOL> User . objects . all ( ) . delete ( ) <EOL> Group . objects . all ( ) . delete ( ) <EOL> def test_add_new_user_to_public_group ( self ) : <EOL> """<STR_LIT>""" <EOL> new_user = User . objects . create_user ( self . username ) <EOL> self . assertEqual ( <EOL> new_user . groups . filter ( name = self . public_group_name ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_init_user ( self ) : <EOL> """<STR_LIT>""" <EOL> init_user ( self . username , self . password , self . email , self . first_name , <EOL> self . last_name , self . affiliation ) <EOL> new_user = User . objects . get ( username = self . username ) <EOL> self . assertEqual ( <EOL> new_user . groups . filter ( name = self . public_group_name ) . count ( ) , <NUM_LIT:1> ) <EOL> class NodeSetTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . investigation = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . study = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation ) <EOL> self . assay = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study ) <EOL> self . query = json . dumps ( { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] <EOL> } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : True <EOL> } ) <EOL> def test_create_minimal_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> nodeset = create_nodeset ( name = name , study = self . study , assay = self . assay ) <EOL> self . assertIsInstance ( nodeset , NodeSet ) <EOL> self . assertEqual ( nodeset . name , name ) <EOL> self . assertEqual ( nodeset . summary , '<STR_LIT>' ) <EOL> self . assertEqual ( nodeset . solr_query , '<STR_LIT>' ) <EOL> def test_create_full_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> summary = '<STR_LIT>' <EOL> nodeset = create_nodeset ( name = name , study = self . study , assay = self . assay , <EOL> summary = summary , solr_query = self . query ) <EOL> self . assertIsInstance ( nodeset , NodeSet ) <EOL> self . assertEqual ( nodeset . name , name ) <EOL> self . assertEqual ( nodeset . summary , summary ) <EOL> self . assertEqual ( nodeset . solr_query , self . query ) <EOL> def test_get_nodeset_with_valid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> self . assertEqual ( get_nodeset ( nodeset . uuid ) , nodeset ) <EOL> def test_get_nodeset_with_invalid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> NodeSet . DoesNotExist , get_nodeset , uuid = '<STR_LIT>' <EOL> ) <EOL> def test_delete_nodeset_with_valid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> delete_nodeset ( nodeset . uuid ) <EOL> self . assertRaises ( <EOL> NodeSet . DoesNotExist , NodeSet . objects . get , uuid = nodeset . uuid <EOL> ) <EOL> def test_delete_nodeset_with_invalid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIsNone ( delete_nodeset ( uuid = '<STR_LIT>' ) ) <EOL> def test_update_nodeset_name ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> new_name = '<STR_LIT>' <EOL> update_nodeset ( uuid = nodeset . uuid , name = new_name ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . name , new_name <EOL> ) <EOL> def test_update_nodeset_summary ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> new_summary = '<STR_LIT>' <EOL> update_nodeset ( uuid = nodeset . uuid , summary = new_summary ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . summary , new_summary ) <EOL> def test_update_nodeset_study ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> new_study = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation ) <EOL> update_nodeset ( uuid = nodeset . uuid , study = new_study ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . study , new_study <EOL> ) <EOL> def test_update_nodeset_assay ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> new_assay = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study ) <EOL> update_nodeset ( uuid = nodeset . uuid , assay = new_assay ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . assay , new_assay <EOL> ) <EOL> def test_update_nodeset_with_solr_query ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay , solr_query = '<STR_LIT>' ) <EOL> update_nodeset ( uuid = nodeset . uuid , solr_query = self . query ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . solr_query , self . query <EOL> ) <EOL> def test_update_nodeset_with_blank_solr_query ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay , <EOL> solr_query = self . query ) <EOL> new_query = '<STR_LIT>' <EOL> update_nodeset ( uuid = nodeset . uuid , solr_query = new_query ) <EOL> self . assertEqual ( <EOL> NodeSet . objects . get ( uuid = nodeset . uuid ) . solr_query , new_query <EOL> ) <EOL> def test_update_nodeset_with_invalid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> NodeSet . DoesNotExist , update_nodeset , uuid = '<STR_LIT>' <EOL> ) <EOL> def make_api_uri ( resource_name , resource_id = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> base_url = '<STR_LIT>' <EOL> if resource_id : <EOL> return '<STR_LIT:/>' . join ( [ base_url , resource_name , resource_id ] ) + '<STR_LIT:/>' <EOL> else : <EOL> return '<STR_LIT:/>' . join ( [ base_url , resource_name ] ) + '<STR_LIT:/>' <EOL> class NodeSetResourceTest ( ResourceTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( NodeSetResourceTest , self ) . setUp ( ) <EOL> self . investigation = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . study = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation ) <EOL> self . assay = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study ) <EOL> self . investigation2 = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . study2 = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation ) <EOL> self . assay2 = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study2 ) <EOL> self . query = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] <EOL> } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : True <EOL> } <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( self . username , '<STR_LIT>' , self . password ) <EOL> self . username2 = self . password2 = '<STR_LIT>' <EOL> self . user2 = User . objects . create_user ( self . username2 , '<STR_LIT>' , <EOL> self . password2 ) <EOL> def get_credentials ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . api_client . client . login ( username = self . username , <EOL> password = self . password ) <EOL> def test_get_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> study = self . study , <EOL> assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' , nodeset . uuid ) <EOL> response = self . api_client . get ( <EOL> nodeset_uri , <EOL> format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) <EOL> ) <EOL> self . assertValidJSONResponse ( response ) <EOL> keys = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertKeys ( self . deserialize ( response ) , keys ) <EOL> def test_get_nodeset_list_for_given_study_and_assay ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset1 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset1 . _meta . module_name , self . user , nodeset1 <EOL> ) <EOL> nodeset2 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study2 , assay = self . assay2 , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset2 . _meta . module_name , self . user2 , nodeset2 <EOL> ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) , <EOL> data = { '<STR_LIT>' : self . study . uuid , <EOL> '<STR_LIT>' : self . assay . uuid } ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , nodeset1 . name ) <EOL> def test_get_sorted_nodeset_list ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset1 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset1 . _meta . module_name , self . user , nodeset1 <EOL> ) <EOL> nodeset2 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study2 , assay = self . assay2 , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset2 . _meta . module_name , self . user , nodeset2 <EOL> ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) , <EOL> data = { '<STR_LIT>' : '<STR_LIT:name>' } ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , nodeset1 . name ) <EOL> def test_get_empty_nodeset_list ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:0> ) <EOL> def test_get_nodeset_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' , nodeset . uuid ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' ) <EOL> self . assertHttpUnauthorized ( response ) <EOL> def test_get_nodeset_list_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset1 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset1 . _meta . module_name , self . user , nodeset1 ) <EOL> nodeset2 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset2 . _meta . module_name , self . user2 , nodeset2 <EOL> ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' ) <EOL> self . assertHttpUnauthorized ( response ) <EOL> def test_get_nodeset_with_invalid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = self . api_client . get ( nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertHttpNotFound ( response ) <EOL> def test_create_minimal_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> dataset = DataSet . objects . create ( ) <EOL> InvestigationLink . objects . create ( data_set = dataset , <EOL> investigation = self . investigation ) <EOL> assign_perm ( "<STR_LIT>" % dataset . _meta . module_name , self . user , dataset ) <EOL> nodeset_data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . study . uuid ) , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . assay . uuid ) , <EOL> '<STR_LIT>' : True <EOL> } <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . api_client . post ( nodeset_uri , format = '<STR_LIT>' , <EOL> data = nodeset_data , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertHttpCreated ( response ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> nodeset = NodeSet . objects . get ( name = nodeset_data [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( nodeset . get_owner ( ) , self . user ) <EOL> def test_create_minimal_nodeset_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:0> ) <EOL> nodeset_data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . study . uuid ) , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . assay . uuid ) , <EOL> '<STR_LIT>' : True <EOL> } <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . post ( nodeset_uri , format = '<STR_LIT>' , <EOL> data = nodeset_data ) <EOL> self . assertHttpUnauthorized ( response ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_create_minimal_nodeset_without_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:0> ) <EOL> nodeset_data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . study . uuid ) , <EOL> '<STR_LIT>' : make_api_uri ( '<STR_LIT>' , self . assay . uuid ) , <EOL> '<STR_LIT>' : True <EOL> } <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> response = self . api_client . post ( nodeset_uri , format = '<STR_LIT>' , <EOL> data = nodeset_data , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertHttpUnauthorized ( response ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_update_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( nodeset . name , '<STR_LIT>' ) <EOL> self . assertFalse ( nodeset . is_implicit ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset ) <EOL> new_nodeset_data = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : True } <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' , nodeset . uuid ) <EOL> self . api_client . put ( nodeset_uri , format = '<STR_LIT>' , data = new_nodeset_data , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> nodeset = NodeSet . objects . get ( uuid = nodeset . uuid ) <EOL> self . assertEqual ( nodeset . name , '<STR_LIT>' ) <EOL> self . assertTrue ( nodeset . is_implicit ) <EOL> def test_delete_nodeset ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( name = '<STR_LIT>' , study = self . study , <EOL> assay = self . assay ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset <EOL> ) <EOL> nodeset_uri = make_api_uri ( '<STR_LIT>' , nodeset . uuid ) <EOL> response = self . api_client . delete ( <EOL> nodeset_uri , format = '<STR_LIT>' , authentication = self . get_credentials ( ) <EOL> ) <EOL> self . assertHttpMethodNotAllowed ( response ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> class NodeSetListResourceTest ( ResourceTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( NodeSetListResourceTest , self ) . setUp ( ) <EOL> self . investigation = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . study = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation <EOL> ) <EOL> self . assay = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study <EOL> ) <EOL> self . investigation2 = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . study2 = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation <EOL> ) <EOL> self . assay2 = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study2 <EOL> ) <EOL> self . query = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] <EOL> } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : True <EOL> } <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( self . username , '<STR_LIT>' , self . password ) <EOL> self . username2 = self . password2 = '<STR_LIT>' <EOL> self . user2 = User . objects . create_user ( self . username2 , '<STR_LIT>' , <EOL> self . password2 ) <EOL> self . nodeset_uri = make_api_uri ( '<STR_LIT>' ) <EOL> def get_credentials ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . api_client . client . login ( username = self . username , <EOL> password = self . password ) <EOL> def test_get_sorted_nodeset_list ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset1 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , node_count = <NUM_LIT:1> , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset1 . _meta . module_name , self . user , nodeset1 <EOL> ) <EOL> nodeset2 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study2 , assay = self . assay2 , node_count = <NUM_LIT:1> , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset2 . _meta . module_name , self . user , nodeset2 <EOL> ) <EOL> response = self . api_client . get ( self . nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) , <EOL> data = { '<STR_LIT>' : '<STR_LIT:name>' } ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , nodeset1 . name ) <EOL> def test_get_nodeset_list_for_given_study_and_assay ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset1 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay , node_count = <NUM_LIT:1> , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset1 . _meta . module_name , self . user , nodeset1 <EOL> ) <EOL> nodeset2 = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study2 , assay = self . assay2 , node_count = <NUM_LIT:1> , <EOL> solr_query = json . dumps ( self . query ) ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset2 . _meta . module_name , self . user2 , nodeset2 <EOL> ) <EOL> response = self . api_client . get ( self . nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) , <EOL> data = { '<STR_LIT>' : self . study . uuid , <EOL> '<STR_LIT>' : self . assay . uuid } ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , nodeset1 . name ) <EOL> def test_get_empty_nodeset_list ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . api_client . get ( self . nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:0> ) <EOL> def test_get_nodeset_list_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . api_client . get ( self . nodeset_uri , format = '<STR_LIT>' ) <EOL> self . assertHttpUnauthorized ( response ) <EOL> def test_delete_nodeset_list ( self ) : <EOL> """<STR_LIT>""" <EOL> nodeset = NodeSet . objects . create ( <EOL> name = '<STR_LIT>' , study = self . study , assay = self . assay ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % nodeset . _meta . module_name , self . user , nodeset <EOL> ) <EOL> response = self . api_client . delete ( <EOL> self . nodeset_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) <EOL> ) <EOL> self . assertHttpMethodNotAllowed ( response ) <EOL> self . assertEqual ( NodeSet . objects . count ( ) , <NUM_LIT:1> ) <EOL> class AnalysisResourceTest ( ResourceTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( AnalysisResourceTest , self ) . setUp ( ) <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . password <EOL> ) <EOL> self . username2 = self . password2 = '<STR_LIT>' <EOL> self . user2 = User . objects . create_user ( <EOL> self . username2 , '<STR_LIT>' , self . password2 <EOL> ) <EOL> self . get_credentials ( ) <EOL> self . project = Project . objects . create ( ) <EOL> self . user_catch_all_project = UserProfile . objects . get ( <EOL> user = self . user <EOL> ) . catch_all_project <EOL> self . dataset = DataSet . objects . create ( ) <EOL> self . dataset2 = DataSet . objects . create ( ) <EOL> self . galaxy_instance = Instance . objects . create ( ) <EOL> self . workflow_engine = WorkflowEngine . objects . create ( <EOL> instance = self . galaxy_instance <EOL> ) <EOL> self . workflow = Workflow . objects . create ( <EOL> workflow_engine = self . workflow_engine <EOL> ) <EOL> def tearDown ( self ) : <EOL> FileExtension . objects . all ( ) . delete ( ) <EOL> def get_credentials ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . api_client . client . login ( <EOL> username = self . username , <EOL> password = self . password <EOL> ) <EOL> def test_get_analysis ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dataset . set_owner ( self . user ) <EOL> analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis . set_owner ( self . user ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , analysis . uuid ) <EOL> response = self . api_client . get ( <EOL> analysis_uri , <EOL> format = '<STR_LIT>' <EOL> ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) <EOL> self . assertKeys ( data , AnalysisResource . Meta . fields ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] , analysis . uuid ) <EOL> def test_get_analysis_list ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dataset . set_owner ( self . user ) <EOL> analysis1 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> assign_perm ( <EOL> '<STR_LIT>' % Analysis . _meta . module_name , <EOL> self . user , <EOL> analysis1 <EOL> ) <EOL> analysis2 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> assign_perm ( <EOL> '<STR_LIT>' % Analysis . _meta . module_name , <EOL> self . user , <EOL> analysis2 <EOL> ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name ) <EOL> response = self . api_client . get ( <EOL> analysis_uri , <EOL> format = '<STR_LIT>' <EOL> ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , analysis2 . name ) <EOL> def test_get_analysis_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> self . api_client . client . logout ( ) <EOL> analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis . set_owner ( self . user ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , analysis . uuid ) <EOL> response = self . api_client . get ( analysis_uri , format = '<STR_LIT>' ) <EOL> self . assertHttpNotFound ( response ) <EOL> def test_get_analysis_without_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis . set_owner ( self . user2 ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , analysis . uuid ) <EOL> response = self . api_client . get ( <EOL> analysis_uri , <EOL> format = '<STR_LIT>' <EOL> ) <EOL> self . assertHttpNotFound ( response ) <EOL> def test_get_analysis_with_invalid_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> analysis = Analysis . objects . create ( project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % Analysis . _meta . module_name , self . user , analysis <EOL> ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , '<STR_LIT>' ) <EOL> response = self . api_client . get ( analysis_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertHttpNotFound ( response ) <EOL> def test_get_analysis_list_for_given_dataset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dataset . set_owner ( self . user ) <EOL> analysis1 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis1 . set_owner ( self . user ) <EOL> analysis2 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset2 , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis2 . set_owner ( self . user ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name ) <EOL> response = self . api_client . get ( <EOL> analysis_uri , <EOL> format = '<STR_LIT>' , <EOL> data = { '<STR_LIT>' : self . dataset . uuid } <EOL> ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , analysis1 . name ) <EOL> def test_get_sorted_analysis_list ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dataset . set_owner ( self . user ) <EOL> self . dataset2 . set_owner ( self . user ) <EOL> analysis1 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis1 . set_owner ( self . user ) <EOL> analysis2 = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> project = self . user_catch_all_project , <EOL> data_set = self . dataset2 , <EOL> workflow = self . workflow <EOL> ) <EOL> analysis2 . set_owner ( self . user ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name ) <EOL> response = self . api_client . get ( <EOL> analysis_uri , <EOL> format = '<STR_LIT>' , <EOL> data = { '<STR_LIT>' : '<STR_LIT:name>' } <EOL> ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , analysis1 . name ) <EOL> def test_get_empty_analysis_list ( self ) : <EOL> """<STR_LIT>""" <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name ) <EOL> response = self . api_client . get ( analysis_uri , format = '<STR_LIT>' , <EOL> authentication = self . get_credentials ( ) ) <EOL> self . assertValidJSONResponse ( response ) <EOL> data = self . deserialize ( response ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:0> ) <EOL> def test_delete_analysis ( self ) : <EOL> """<STR_LIT>""" <EOL> analysis = Analysis . objects . create ( project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow ) <EOL> self . assertEqual ( Analysis . objects . count ( ) , <NUM_LIT:1> ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % Analysis . _meta . module_name , <EOL> self . user , <EOL> analysis <EOL> ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , analysis . uuid ) <EOL> response = self . api_client . delete ( <EOL> analysis_uri , format = '<STR_LIT>' , authentication = self . get_credentials ( ) <EOL> ) <EOL> self . assertHttpMethodNotAllowed ( response ) <EOL> self . assertEqual ( Analysis . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_delete_analysis_without_login ( self ) : <EOL> """<STR_LIT>""" <EOL> analysis = Analysis . objects . create ( project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow ) <EOL> self . assertEqual ( Analysis . objects . count ( ) , <NUM_LIT:1> ) <EOL> assign_perm ( <EOL> "<STR_LIT>" % Analysis . _meta . module_name , <EOL> self . user , <EOL> analysis <EOL> ) <EOL> analysis_uri = make_api_uri ( Analysis . _meta . module_name , analysis . uuid ) <EOL> response = self . api_client . delete ( analysis_uri , format = '<STR_LIT>' ) <EOL> self . assertHttpMethodNotAllowed ( response ) <EOL> self . assertEqual ( Analysis . objects . count ( ) , <NUM_LIT:1> ) <EOL> class BaseResourceSlugTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> for index , item in enumerate ( range ( <NUM_LIT:0> , <NUM_LIT:10> ) ) : <EOL> DataSet . objects . create ( slug = "<STR_LIT>" % index ) <EOL> Project . objects . create ( name = "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> DataSet . objects . all ( ) . delete ( ) <EOL> Project . objects . all ( ) . delete ( ) <EOL> def test_duplicate_slugs ( self ) : <EOL> DataSet . objects . create ( slug = "<STR_LIT>" ) <EOL> self . assertEqual ( DataSet . objects . filter ( slug = "<STR_LIT>" ) <EOL> . count ( ) , <NUM_LIT:1> ) <EOL> def test_empty_slug ( self ) : <EOL> self . assertTrue ( DataSet . objects . create ( slug = "<STR_LIT>" ) ) <EOL> def test_edit_existing_slug ( self ) : <EOL> instance = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> instance . summary = "<STR_LIT>" <EOL> instance . save ( ) <EOL> self . assertTrue ( DataSet . objects . get ( summary = "<STR_LIT>" ) ) <EOL> def test_save_slug_no_change ( self ) : <EOL> instance = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> instance_again = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> instance_again . save ( ) <EOL> self . assertEqual ( instance , instance_again ) <EOL> def test_save_slug_with_change ( self ) : <EOL> instance = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> instance_again = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> instance_again . slug = "<STR_LIT>" <EOL> instance_again . save ( ) <EOL> self . assertNotEqual ( instance . slug , instance_again . slug ) <EOL> def test_save_slug_when_another_model_with_same_slug_exists ( self ) : <EOL> project_instance = Project . objects . get ( name = "<STR_LIT>" ) <EOL> project_instance . slug = "<STR_LIT>" <EOL> project_instance . save ( ) <EOL> self . assertTrue ( DataSet . objects . create ( slug = "<STR_LIT>" ) ) <EOL> class CachingTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . username = self . password = '<STR_LIT>' <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . password <EOL> ) <EOL> self . username1 = self . password1 = '<STR_LIT>' <EOL> self . user1 = User . objects . create_user ( <EOL> self . username1 , '<STR_LIT>' , self . password1 <EOL> ) <EOL> create_public_group ( ) <EOL> self . public_group_name = ExtendedGroup . objects . public_group ( ) . name <EOL> for index , item in enumerate ( range ( <NUM_LIT:0> , <NUM_LIT:6> ) ) : <EOL> DataSet . objects . create ( slug = "<STR_LIT>" % index ) <EOL> cache . add ( "<STR_LIT>" . format ( self . user . id ) , DataSet . objects . all ( ) ) <EOL> self . initial_cache = cache . get ( "<STR_LIT>" . format ( self . user . id ) ) <EOL> def tearDown ( self ) : <EOL> self . cache = invalidate_cached_object ( DataSet . objects . get ( <EOL> slug = "<STR_LIT>" ) , True ) <EOL> DataSet . objects . all ( ) . delete ( ) <EOL> User . objects . all ( ) . delete ( ) <EOL> Group . objects . all ( ) . delete ( ) <EOL> ExtendedGroup . objects . all ( ) . delete ( ) <EOL> def test_verify_cache_invalidation ( self ) : <EOL> ds = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> self . cache = invalidate_cached_object ( ds , True ) <EOL> self . assertIsNone ( self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) ) <EOL> def test_verify_data_after_save ( self ) : <EOL> ds = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> ds . slug = "<STR_LIT>" <EOL> ds . save ( ) <EOL> self . cache = invalidate_cached_object ( ds , True ) <EOL> self . cache . add ( "<STR_LIT>" . format ( self . user . id ) , <EOL> DataSet . objects . all ( ) ) <EOL> new_cache = self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) <EOL> self . assertTrue ( new_cache ) <EOL> self . assertNotEqual ( self . initial_cache , new_cache ) <EOL> self . assertTrue ( DataSet . objects . get ( slug = "<STR_LIT>" ) ) <EOL> def test_verify_data_after_delete ( self ) : <EOL> ds = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> ds . delete ( ) <EOL> self . cache = invalidate_cached_object ( DataSet . objects . get ( <EOL> slug = "<STR_LIT>" ) , True ) <EOL> self . assertFalse ( self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) ) <EOL> self . cache . add ( "<STR_LIT>" . format ( self . user . id ) , <EOL> DataSet . objects . all ( ) ) <EOL> new_cache = self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) <EOL> self . assertTrue ( new_cache ) <EOL> self . assertNotEqual ( self . initial_cache , new_cache ) <EOL> def test_verify_data_after_perms_change ( self ) : <EOL> ds = DataSet . objects . get ( slug = "<STR_LIT>" ) <EOL> ds . share ( group = Group . objects . get ( name = "<STR_LIT>" ) ) <EOL> self . cache = invalidate_cached_object ( DataSet . objects . get ( <EOL> slug = "<STR_LIT>" ) , True ) <EOL> self . assertFalse ( self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) ) <EOL> self . cache . add ( "<STR_LIT>" . format ( self . user . id ) , <EOL> DataSet . objects . all ( ) ) <EOL> new_cache = self . cache . get ( "<STR_LIT>" . format ( self . user . id ) ) <EOL> self . assertTrue ( new_cache ) <EOL> self . assertNotEqual ( self . initial_cache , new_cache ) <EOL> class WorkflowDeletionTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . password <EOL> ) <EOL> self . project = Project . objects . create ( ) <EOL> self . galaxy_instance = Instance . objects . create ( ) <EOL> self . workflow_engine = WorkflowEngine . objects . create ( <EOL> instance = self . galaxy_instance <EOL> ) <EOL> self . workflow = Workflow . objects . create ( <EOL> name = "<STR_LIT>" , workflow_engine = self . workflow_engine ) <EOL> self . dataset = DataSet . objects . create ( ) <EOL> def tearDown ( self ) : <EOL> User . objects . all ( ) . delete ( ) <EOL> Project . objects . all ( ) . delete ( ) <EOL> WorkflowEngine . objects . all ( ) . delete ( ) <EOL> Workflow . objects . all ( ) . delete ( ) <EOL> DataSet . objects . all ( ) . delete ( ) <EOL> Instance . objects . all ( ) . delete ( ) <EOL> Analysis . objects . all ( ) . delete ( ) <EOL> def test_verify_workflow_used_by_analysis ( self ) : <EOL> analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow , <EOL> status = "<STR_LIT>" <EOL> ) <EOL> analysis . set_owner ( self . user ) <EOL> self . assertEqual ( analysis . workflow . name , "<STR_LIT>" ) <EOL> def test_verify_no_deletion_if_workflow_used_in_analysis ( self ) : <EOL> analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset , <EOL> workflow = self . workflow , <EOL> status = "<STR_LIT>" <EOL> ) <EOL> analysis . set_owner ( self . user ) <EOL> self . workflow . delete ( ) <EOL> self . assertFalse ( self . workflow . is_active ) <EOL> def test_verify_deletion_if_workflow_not_used_in_analysis ( self ) : <EOL> self . assertEqual ( self . workflow . delete ( ) , None ) <EOL> class DataSetDeletionTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . password <EOL> ) <EOL> self . project = Project . objects . create ( ) <EOL> self . galaxy_instance = Instance . objects . create ( ) <EOL> self . workflow_engine = WorkflowEngine . objects . create ( <EOL> instance = self . galaxy_instance <EOL> ) <EOL> self . workflow = Workflow . objects . create ( <EOL> name = "<STR_LIT>" , workflow_engine = self . workflow_engine ) <EOL> self . dataset_with_analysis = DataSet . objects . create ( ) <EOL> self . dataset_without_analysis = DataSet . objects . create ( ) <EOL> self . analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset_with_analysis , <EOL> workflow = self . workflow , <EOL> status = "<STR_LIT>" <EOL> ) <EOL> self . analysis . set_owner ( self . user ) <EOL> def tearDown ( self ) : <EOL> User . objects . all ( ) . delete ( ) <EOL> Project . objects . all ( ) . delete ( ) <EOL> WorkflowEngine . objects . all ( ) . delete ( ) <EOL> Workflow . objects . all ( ) . delete ( ) <EOL> DataSet . objects . all ( ) . delete ( ) <EOL> Instance . objects . all ( ) . delete ( ) <EOL> Analysis . objects . all ( ) . delete ( ) <EOL> UserProfile . objects . all ( ) . delete ( ) <EOL> Node . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Study . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Assay . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Investigation . objects . all ( ) . delete ( ) <EOL> AnalysisNodeConnection . objects . all ( ) . delete ( ) <EOL> InvestigationLink . objects . all ( ) . delete ( ) <EOL> def test_verify_dataset_deletion_if_no_analysis_run_upon_it ( self ) : <EOL> self . assertEqual ( self . dataset_without_analysis . delete ( ) , None ) <EOL> def test_verify_no_dataset_deletion_if_analysis_run_upon_it ( self ) : <EOL> self . dataset_with_analysis . delete ( ) <EOL> self . assertNotEqual ( self . dataset_with_analysis , None ) <EOL> class AnalysisDeletionTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . username = self . password = '<STR_LIT:user>' <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . password <EOL> ) <EOL> self . project = Project . objects . create ( ) <EOL> self . project1 = Project . objects . create ( ) <EOL> self . galaxy_instance = Instance . objects . create ( ) <EOL> self . workflow_engine = WorkflowEngine . objects . create ( <EOL> instance = self . galaxy_instance <EOL> ) <EOL> self . workflow = Workflow . objects . create ( <EOL> name = "<STR_LIT>" , workflow_engine = self . workflow_engine ) <EOL> self . workflow1 = Workflow . objects . create ( <EOL> name = "<STR_LIT>" , workflow_engine = self . workflow_engine ) <EOL> self . dataset_with_analysis = DataSet . objects . create ( ) <EOL> self . dataset_with_analysis1 = DataSet . objects . create ( ) <EOL> self . dataset_without_analysis = DataSet . objects . create ( ) <EOL> self . analysis = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project , <EOL> data_set = self . dataset_with_analysis , <EOL> workflow = self . workflow , <EOL> status = "<STR_LIT>" <EOL> ) <EOL> self . analysis_with_node_analyzed_further = Analysis . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> summary = '<STR_LIT>' , <EOL> project = self . project1 , <EOL> data_set = self . dataset_with_analysis1 , <EOL> workflow = self . workflow1 , <EOL> status = "<STR_LIT>" <EOL> ) <EOL> self . analysis . set_owner ( self . user ) <EOL> self . analysis_with_node_analyzed_further . set_owner ( self . user ) <EOL> self . investigation = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . investigation_link = InvestigationLink . objects . create ( <EOL> investigation = self . investigation , <EOL> data_set = self . dataset_with_analysis ) <EOL> self . investigation1 = data_set_manager . models . Investigation . objects . create ( ) <EOL> self . investigation_link1 = InvestigationLink . objects . create ( <EOL> investigation = self . investigation1 , <EOL> data_set = self . dataset_with_analysis1 ) <EOL> self . study = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation ) <EOL> self . assay = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study ) <EOL> self . study1 = data_set_manager . models . Study . objects . create ( <EOL> investigation = self . investigation1 ) <EOL> self . assay1 = data_set_manager . models . Assay . objects . create ( <EOL> study = self . study1 ) <EOL> self . node = Node . objects . create ( assay = self . assay , study = self . study , <EOL> analysis_uuid = self . analysis . uuid ) <EOL> self . node2 = Node . objects . create ( assay = self . assay1 , study = self . study1 , <EOL> analysis_uuid = self . <EOL> analysis_with_node_analyzed_further <EOL> . uuid ) <EOL> self . analysis_node_connection = AnalysisNodeConnection . objects . create ( analysis = self . analysis , <EOL> node = self . node , step = <NUM_LIT:1> , <EOL> direction = "<STR_LIT>" ) <EOL> self . analysis_node_connection_with_node_analyzed_further = AnalysisNodeConnection . objects . create ( <EOL> analysis = self . analysis_with_node_analyzed_further , <EOL> node = self . node2 , step = <NUM_LIT:2> , <EOL> direction = "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> User . objects . all ( ) . delete ( ) <EOL> Project . objects . all ( ) . delete ( ) <EOL> WorkflowEngine . objects . all ( ) . delete ( ) <EOL> Workflow . objects . all ( ) . delete ( ) <EOL> DataSet . objects . all ( ) . delete ( ) <EOL> Instance . objects . all ( ) . delete ( ) <EOL> Analysis . objects . all ( ) . delete ( ) <EOL> UserProfile . objects . all ( ) . delete ( ) <EOL> Node . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Study . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Assay . objects . all ( ) . delete ( ) <EOL> data_set_manager . models . Investigation . objects . all ( ) . delete ( ) <EOL> AnalysisNodeConnection . objects . all ( ) . delete ( ) <EOL> InvestigationLink . objects . all ( ) . delete ( ) <EOL> def test_verify_analysis_deletion_if_nodes_not_analyzed_further ( self ) : <EOL> self . assertEqual ( self . analysis . delete ( ) , None ) <EOL> def test_verify_analysis_remains_if_nodes_analyzed_further ( self ) : <EOL> self . analysis_with_node_analyzed_further . delete ( ) <EOL> self . assertNotEqual ( self . analysis_with_node_analyzed_further , None ) </s>
