<s> import os <EOL> import uuid <EOL> from django . test import TestCase , Client <EOL> from . import factories , config , mixins <EOL> from . . import version <EOL> class ScriptTestCase ( mixins . ScriptFactoryMixin , TestCase ) : <EOL> def test_multiple_choices ( self ) : <EOL> script = self . choice_script <EOL> multiple_choice_param = '<STR_LIT>' <EOL> single_choice_param = '<STR_LIT>' <EOL> optional_choice_param = '<STR_LIT>' <EOL> from . . models import ScriptParameter <EOL> param = ScriptParameter . objects . get ( slug = multiple_choice_param ) <EOL> self . assertTrue ( param . multiple_choice ) <EOL> self . assertEqual ( param . max_choices , <NUM_LIT:2> ) <EOL> param = ScriptParameter . objects . get ( slug = single_choice_param ) <EOL> self . assertFalse ( param . multiple_choice ) <EOL> self . assertEqual ( param . max_choices , <NUM_LIT:1> ) <EOL> param = ScriptParameter . objects . get ( slug = optional_choice_param ) <EOL> self . assertTrue ( param . multiple_choice ) <EOL> self . assertEqual ( param . max_choices , - <NUM_LIT:1> ) <EOL> class ScriptGroupTestCase ( TestCase ) : <EOL> def test_script_group_creation ( self ) : <EOL> group = factories . ScriptGroupFactory ( ) <EOL> class TestJob ( mixins . ScriptFactoryMixin , mixins . FileCleanupMixin , mixins . FileMixin , TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def get_local_url ( self , fileinfo ) : <EOL> from . . backend import utils <EOL> local_storage = utils . get_storage ( local = True ) <EOL> return local_storage . url ( fileinfo [ '<STR_LIT:object>' ] . filepath . name ) <EOL> def test_jobs ( self ) : <EOL> script = self . translate_script <EOL> from . . backend import utils <EOL> job = utils . create_wooey_job ( script_version_pk = script . pk , data = { '<STR_LIT>' : '<STR_LIT:abc>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:abc>' } ) <EOL> job = job . submit_to_celery ( ) <EOL> old_pk = job . pk <EOL> new_job = job . submit_to_celery ( resubmit = True ) <EOL> self . assertNotEqual ( old_pk , new_job . pk ) <EOL> from . . models import UserFile <EOL> old_output = sorted ( [ i . pk for i in UserFile . objects . filter ( job = new_job ) ] ) <EOL> new_job . submit_to_celery ( rerun = True ) <EOL> new_output = sorted ( [ i . pk for i in UserFile . objects . filter ( job = new_job ) ] ) <EOL> if version . DJANGO_VERSION >= version . DJ17 : <EOL> self . assertNotEqual ( old_output , new_output ) <EOL> self . assertEqual ( len ( old_output ) , len ( new_output ) ) <EOL> if version . DJANGO_VERSION >= version . DJ17 : <EOL> self . assertEqual ( [ ] , list ( UserFile . objects . filter ( pk__in = old_output ) ) ) <EOL> file_previews = utils . get_file_previews ( job ) <EOL> for group , files in file_previews . items ( ) : <EOL> for fileinfo in files : <EOL> response = Client ( ) . get ( self . get_local_url ( fileinfo ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> local_storage = utils . get_storage ( local = True ) <EOL> fasta_path = local_storage . save ( '<STR_LIT>' , open ( os . path . join ( config . WOOEY_TEST_DATA , '<STR_LIT>' ) ) ) <EOL> fasta_file = local_storage . open ( fasta_path ) <EOL> job = utils . create_wooey_job ( script_version_pk = script . pk , <EOL> data = { <EOL> '<STR_LIT>' : fasta_file , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' <EOL> } <EOL> ) <EOL> file_previews = utils . get_file_previews ( job ) <EOL> for group , files in file_previews . items ( ) : <EOL> for fileinfo in files : <EOL> response = Client ( ) . get ( self . get_local_url ( fileinfo ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_file_sharing ( self ) : <EOL> new_file = self . storage . open ( self . get_any_file ( ) ) <EOL> script_slug = '<STR_LIT>' <EOL> script = self . choice_script <EOL> from . . backend import utils <EOL> job = utils . create_wooey_job ( script_version_pk = script . pk , data = { '<STR_LIT>' : '<STR_LIT>' , script_slug : new_file } ) <EOL> job = job . submit_to_celery ( ) <EOL> job2 = utils . create_wooey_job ( script_version_pk = script . pk , data = { '<STR_LIT>' : '<STR_LIT>' , script_slug : new_file } ) <EOL> job2 = job2 . submit_to_celery ( ) <EOL> from . . models import UserFile <EOL> job1_files = [ i for i in UserFile . objects . filter ( job = job , parameter__isnull = False ) if i . parameter . parameter . slug == script_slug ] <EOL> job1_file = job1_files [ <NUM_LIT:0> ] <EOL> job2_files = [ i for i in UserFile . objects . filter ( job = job2 , parameter__isnull = False ) if i . parameter . parameter . slug == script_slug ] <EOL> job2_file = job2_files [ <NUM_LIT:0> ] <EOL> self . assertNotEqual ( job1_file . pk , job2_file . pk ) <EOL> self . assertEqual ( job1_file . system_file , job2_file . system_file ) <EOL> def test_multiplechoices ( self ) : <EOL> script = self . choice_script <EOL> choices = [ '<STR_LIT:2>' , '<STR_LIT:1>' , '<STR_LIT:3>' ] <EOL> choice_param = '<STR_LIT>' <EOL> from . . backend import utils <EOL> job = utils . create_wooey_job ( script_version_pk = script . pk , data = { '<STR_LIT>' : '<STR_LIT:abc>' , choice_param : choices } ) <EOL> choice_params = [ i . value for i in job . get_parameters ( ) if i . parameter . slug == choice_param ] <EOL> self . assertEqual ( choices , choice_params ) <EOL> job = job . submit_to_celery ( ) </s>
