<s> """<STR_LIT>""" <EOL> import datetime <EOL> from mock import patch <EOL> from django . core . exceptions import ValidationError <EOL> from moztrap . model . execution . models import Run <EOL> from tests import case <EOL> class RunTest ( case . DBTestCase ) : <EOL> def test_unicode ( self ) : <EOL> r = self . F . RunFactory ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( unicode ( r ) , u"<STR_LIT>" ) <EOL> def test_invalid_dates ( self ) : <EOL> """<STR_LIT>""" <EOL> today = datetime . date ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> r = self . F . RunFactory ( <EOL> start = today , <EOL> end = today - datetime . timedelta ( days = <NUM_LIT:1> ) ) <EOL> with self . assertRaises ( ValidationError ) : <EOL> r . full_clean ( ) <EOL> def test_valid_dates ( self ) : <EOL> """<STR_LIT>""" <EOL> today = datetime . date ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> r = self . F . RunFactory ( <EOL> start = today , <EOL> end = today + datetime . timedelta ( days = <NUM_LIT:1> ) ) <EOL> r . full_clean ( ) <EOL> def test_parent ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory ( ) <EOL> self . assertIs ( r . parent , r . productversion ) <EOL> def test_own_team ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( has_team = True ) <EOL> u = self . F . UserFactory . create ( ) <EOL> r . own_team . add ( u ) <EOL> self . assertEqual ( list ( r . team . all ( ) ) , [ u ] ) <EOL> def test_inherit_team ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( has_team = False ) <EOL> u = self . F . UserFactory . create ( ) <EOL> r . productversion . team . add ( u ) <EOL> self . assertEqual ( list ( r . team . all ( ) ) , [ u ] ) <EOL> def test_clone ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( name = "<STR_LIT>" ) <EOL> new = r . clone ( ) <EOL> self . assertNotEqual ( new , r ) <EOL> self . assertIsInstance ( new , type ( r ) ) <EOL> self . assertEqual ( new . name , "<STR_LIT>" ) <EOL> def test_clone_sets_draft ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> new = r . clone ( ) <EOL> self . assertEqual ( new . status , "<STR_LIT>" ) <EOL> def test_clone_for_series ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" , is_series = True ) <EOL> new = r . clone_for_series ( build = "<STR_LIT>" ) <EOL> self . assertEqual ( new . status , "<STR_LIT>" ) <EOL> self . assertEqual ( new . name , "<STR_LIT>" ) <EOL> self . assertEqual ( new . is_series , False ) <EOL> self . assertEqual ( new . series , r ) <EOL> self . assertEqual ( new . build , "<STR_LIT>" ) <EOL> def test_default_draft ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( ) <EOL> self . assertEqual ( r . status , "<STR_LIT>" ) <EOL> def test_clone_included_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> rs = self . F . RunSuiteFactory . create ( ) <EOL> new = rs . run . clone ( ) <EOL> self . assertNotEqual ( new . runsuites . get ( ) , rs ) <EOL> def test_clone_no_run_caseversions ( self ) : <EOL> """<STR_LIT>""" <EOL> rcv = self . F . RunCaseVersionFactory . create ( ) <EOL> new = rcv . run . clone ( ) <EOL> self . assertEqual ( new . runcaseversions . count ( ) , <NUM_LIT:0> ) <EOL> def test_clone_environments ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory ( environments = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> new = r . clone ( ) <EOL> self . assertEqual ( len ( new . environments . all ( ) ) , <NUM_LIT:2> ) <EOL> def test_clone_environments_narrowed ( self ) : <EOL> """<STR_LIT>""" <EOL> envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> pv = self . F . ProductVersionFactory ( environments = envs ) <EOL> r = self . F . RunFactory ( productversion = pv , environments = envs [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( len ( r . environments . all ( ) ) , <NUM_LIT:1> ) <EOL> new = r . clone ( ) <EOL> self . assertEqual ( len ( new . environments . all ( ) ) , <NUM_LIT:1> ) <EOL> def test_clone_team ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory ( team = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> new = r . clone ( ) <EOL> self . assertEqual ( len ( new . team . all ( ) ) , <NUM_LIT:2> ) <EOL> def test_gets_productversion_envs ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( <EOL> environments = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> r = self . F . RunFactory . create ( productversion = pv ) <EOL> self . assertEqual ( set ( r . environments . all ( ) ) , set ( pv . environments . all ( ) ) ) <EOL> def test_inherits_env_removal ( self ) : <EOL> """<STR_LIT>""" <EOL> envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> pv = self . F . ProductVersionFactory . create ( environments = envs ) <EOL> run = self . F . RunFactory . create ( productversion = pv ) <EOL> pv . remove_envs ( envs [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( set ( run . environments . all ( ) ) , set ( envs [ <NUM_LIT:1> : ] ) ) <EOL> def test_draft_run_inherits_env_addition ( self ) : <EOL> """<STR_LIT>""" <EOL> envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> pv = self . F . ProductVersionFactory . create ( environments = envs [ <NUM_LIT:1> : ] ) <EOL> run = self . F . RunFactory . create ( productversion = pv , status = "<STR_LIT>" ) <EOL> pv . add_envs ( envs [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( set ( run . environments . all ( ) ) , set ( envs ) ) <EOL> def test_active_run_does_not_inherit_env_addition ( self ) : <EOL> """<STR_LIT>""" <EOL> envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> pv = self . F . ProductVersionFactory . create ( environments = envs [ <NUM_LIT:1> : ] ) <EOL> run = self . F . RunFactory . create ( productversion = pv , status = "<STR_LIT>" ) <EOL> pv . add_envs ( envs [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( set ( run . environments . all ( ) ) , set ( envs [ <NUM_LIT:1> : ] ) ) <EOL> def test_result_summary ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory ( ) <EOL> rcv1 = self . F . RunCaseVersionFactory ( run = r ) <EOL> rcv2 = self . F . RunCaseVersionFactory ( run = r ) <EOL> self . F . ResultFactory ( runcaseversion = rcv1 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv2 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv1 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv2 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv1 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv1 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv2 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv1 , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( runcaseversion = rcv2 , status = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> r . result_summary ( ) , <EOL> { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:3> <EOL> } <EOL> ) <EOL> def test_result_summary_specific ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory ( ) <EOL> rcv = self . F . RunCaseVersionFactory ( run = r ) <EOL> self . F . ResultFactory ( runcaseversion = rcv , status = "<STR_LIT>" ) <EOL> r2 = self . F . RunFactory ( ) <EOL> self . assertEqual ( <EOL> r2 . result_summary ( ) , <EOL> { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } <EOL> ) <EOL> def test_completion_percentage ( self ) : <EOL> """<STR_LIT>""" <EOL> envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> pv = self . F . ProductVersionFactory ( environments = envs ) <EOL> run = self . F . RunFactory ( productversion = pv ) <EOL> rcv1 = self . F . RunCaseVersionFactory ( <EOL> run = run , caseversion__productversion = pv ) <EOL> rcv2 = self . F . RunCaseVersionFactory ( <EOL> run = run , caseversion__productversion = pv ) <EOL> self . F . ResultFactory ( <EOL> runcaseversion = rcv1 , environment = envs [ <NUM_LIT:0> ] , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( <EOL> runcaseversion = rcv1 , environment = envs [ <NUM_LIT:0> ] , status = "<STR_LIT>" ) <EOL> self . F . ResultFactory ( <EOL> runcaseversion = rcv2 , environment = envs [ <NUM_LIT:1> ] , status = "<STR_LIT>" ) <EOL> self . assertEqual ( run . completion ( ) , <NUM_LIT> ) <EOL> def test_completion_percentage_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> run = self . F . RunFactory ( ) <EOL> self . assertEqual ( run . completion ( ) , <NUM_LIT:0> ) <EOL> class RunActivationTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> self . p = self . F . ProductFactory . create ( ) <EOL> self . pv8 = self . F . ProductVersionFactory . create ( <EOL> product = self . p , version = "<STR_LIT>" , environments = self . envs ) <EOL> self . pv9 = self . F . ProductVersionFactory . create ( <EOL> product = self . p , version = "<STR_LIT>" , environments = self . envs ) <EOL> def assertCaseVersions ( self , run , caseversions ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> set ( [ rcv . caseversion . id for rcv in run . runcaseversions . all ( ) ] ) , <EOL> set ( [ cv . id for cv in caseversions ] ) <EOL> ) <EOL> def assertOrderedCaseVersions ( self , run , caseversions ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> [ rcv . caseversion . id for rcv in run . runcaseversions . all ( ) ] , <EOL> [ cv . id for cv in caseversions ] <EOL> ) <EOL> def test_productversion ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv1 = self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv9 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ tcv1 ] ) <EOL> def test_draft_not_included ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_soft_deleted_not_included ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> cv . delete ( ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_only_active_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> ts1 = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts1 , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_wrong_product_version_not_included ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv9 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_no_environments_in_common ( self ) : <EOL> """<STR_LIT>""" <EOL> self . pv8 . environments . add ( * self . envs ) <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv1 = self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> tcv1 . remove_envs ( * self . envs [ : <NUM_LIT:2> ] ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> r . remove_envs ( * self . envs [ <NUM_LIT:2> : ] ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_ordering ( self ) : <EOL> """<STR_LIT>""" <EOL> tc1 = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv1 = self . F . CaseVersionFactory . create ( <EOL> case = tc1 , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> tc2 = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv2 = self . F . CaseVersionFactory . create ( <EOL> case = tc2 , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> tc3 = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv3 = self . F . CaseVersionFactory . create ( <EOL> case = tc3 , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> tc4 = self . F . CaseFactory . create ( product = self . p ) <EOL> tcv4 = self . F . CaseVersionFactory . create ( <EOL> case = tc4 , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts1 = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts1 , case = tc3 , order = <NUM_LIT:1> ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts1 , case = tc4 , order = <NUM_LIT:2> ) <EOL> ts2 = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts2 , case = tc1 , order = <NUM_LIT:1> ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts2 , case = tc2 , order = <NUM_LIT:2> ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> self . F . RunSuiteFactory . create ( suite = ts2 , run = r , order = <NUM_LIT:1> ) <EOL> self . F . RunSuiteFactory . create ( suite = ts1 , run = r , order = <NUM_LIT:2> ) <EOL> r . activate ( ) <EOL> self . assertOrderedCaseVersions ( r , [ tcv1 , tcv2 , tcv3 , tcv4 ] ) <EOL> def test_sets_status_active ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> r . activate ( ) <EOL> self . assertEqual ( self . refresh ( r ) . status , "<STR_LIT>" ) <EOL> def test_already_active ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_run_series_no_runcaseversions ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> is_series = True ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> def test_disabled ( self ) : <EOL> """<STR_LIT>""" <EOL> tc = self . F . CaseFactory . create ( product = self . p ) <EOL> self . F . CaseVersionFactory . create ( <EOL> case = tc , productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = tc ) <EOL> r = self . F . RunFactory . create ( <EOL> productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertCaseVersions ( r , [ ] ) <EOL> self . assertEqual ( self . refresh ( r ) . status , "<STR_LIT>" ) <EOL> def test_removes_duplicate_runcaseversions ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> ) <EOL> rcv1 = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion = cv , <EOL> ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv1 ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv1 ) <EOL> rcv2 = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion = cv , <EOL> ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv2 ) <EOL> rcv3 = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> caseversion__name = "<STR_LIT>" , <EOL> ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv1 . caseversion . case ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv3 . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> rcv = r . runcaseversions . all ( ) <EOL> self . assertEqual ( rcv . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( set ( rcv ) , set ( [ rcv2 , rcv3 ] ) ) <EOL> def test_removes_unused_runcaseversions ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> rcv1 = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> rcv1 . environments . remove ( self . envs [ <NUM_LIT:1> ] ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv1 ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv1 ) <EOL> rcv2 = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv2 ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv1 . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . environments . remove ( self . envs [ <NUM_LIT:0> ] ) <EOL> r . activate ( ) <EOL> rcv = r . runcaseversions . get ( ) <EOL> self . assertEqual ( set ( rcv . environments . all ( ) ) , set ( self . envs [ <NUM_LIT:1> : ] ) ) <EOL> self . assertEqual ( rcv . results . count ( ) , <NUM_LIT:2> ) <EOL> def test_updates_envs_on_previously_included_rcv ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> rcv = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> rcv . caseversion . environments . remove ( self . envs [ <NUM_LIT:0> ] ) <EOL> r . activate ( ) <EOL> self . assertEqual ( set ( rcv . environments . all ( ) ) , set ( self . envs [ <NUM_LIT:1> : ] ) ) <EOL> def test_removes_draft_caseversions_and_their_results ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> rcv = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . activate ( ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( <EOL> self . model . Result . objects . filter ( runcaseversion__run = r ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( <EOL> self . model . Result . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_removes_no_env_overlap_caseversions ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> rcv = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> rcv . caseversion . environments . remove ( self . envs [ <NUM_LIT:0> ] ) <EOL> r . environments . remove ( * self . envs [ <NUM_LIT:1> : ] ) <EOL> r . activate ( ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:0> ) <EOL> def test_query_count_on_activate ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 ) <EOL> old_cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . RunCaseVersionFactory ( run = r , caseversion = old_cv ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> cv_needed = [ ] <EOL> for num in range ( <NUM_LIT:6> ) : <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" + str ( num ) , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = cv . case ) <EOL> cv_needed . append ( cv ) <EOL> existing_rcv = self . F . RunCaseVersionFactory ( run = r , <EOL> caseversion = cv_needed [ <NUM_LIT:3> ] , <EOL> order = <NUM_LIT:0> , <EOL> ) <EOL> old_env = self . F . EnvironmentFactory . create_set ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ) [ <NUM_LIT:0> ] <EOL> self . F . model . RunCaseVersion . environments . through ( <EOL> runcaseversion = existing_rcv , <EOL> environment = old_env , <EOL> ) . save ( ) <EOL> from django . conf import settings <EOL> from django . db import connection <EOL> settings . DEBUG = True <EOL> connection . queries = [ ] <EOL> try : <EOL> with self . assertNumQueries ( <NUM_LIT> ) : <EOL> r . activate ( ) <EOL> selects = [ x [ "<STR_LIT>" ] for x in connection . queries if x [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) ] <EOL> inserts = [ x [ "<STR_LIT>" ] for x in connection . queries if x [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) ] <EOL> updates = [ x [ "<STR_LIT>" ] for x in connection . queries if x [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) ] <EOL> deletes = [ x [ "<STR_LIT>" ] for x in connection . queries if x [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) ] <EOL> self . assertEqual ( len ( selects ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( inserts ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( updates ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( deletes ) , <NUM_LIT:3> ) <EOL> except AssertionError as e : <EOL> raise e <EOL> finally : <EOL> settings . DEBUG = False <EOL> self . refresh ( r ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( <EOL> self . F . model . RunCaseVersion . environments . through . objects . count ( ) , <EOL> <NUM_LIT> , <EOL> ) <EOL> self . assertEqual ( <EOL> self . F . model . RunCaseVersion . objects . filter ( <EOL> run = r , <EOL> caseversion = old_cv , <EOL> ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_run_refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( <EOL> productversion = self . pv8 ) <EOL> r . activate ( ) <EOL> old_cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . RunCaseVersionFactory ( run = r , caseversion = old_cv ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> cv_needed = [ ] <EOL> for num in range ( <NUM_LIT:6> ) : <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" + str ( num ) , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = cv . case ) <EOL> cv_needed . append ( cv ) <EOL> existing_rcv = self . F . RunCaseVersionFactory ( <EOL> run = r , <EOL> caseversion = cv_needed [ <NUM_LIT:3> ] , <EOL> order = <NUM_LIT:0> , <EOL> ) <EOL> old_env = self . F . EnvironmentFactory . create_set ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ) [ <NUM_LIT:0> ] <EOL> self . F . model . RunCaseVersion . environments . through ( <EOL> runcaseversion = existing_rcv , <EOL> environment = old_env , <EOL> ) . save ( ) <EOL> r . refresh ( ) <EOL> self . refresh ( r ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( <EOL> self . F . model . RunCaseVersion . environments . through . objects . count ( ) , <EOL> <NUM_LIT> , <EOL> ) <EOL> self . assertEqual ( self . F . model . RunCaseVersion . objects . filter ( <EOL> run = r , <EOL> caseversion = old_cv , <EOL> ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_run_refresh_draft_no_op ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( productversion = self . pv8 , status = "<STR_LIT>" ) <EOL> rcv = self . F . RunCaseVersionFactory . create ( <EOL> run = r , <EOL> caseversion__productversion = self . pv8 , <EOL> caseversion__status = "<STR_LIT>" , <EOL> ) <EOL> self . F . ResultFactory . create ( runcaseversion = rcv ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = rcv . caseversion . case ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> r . refresh ( ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> self . model . Result . objects . filter ( runcaseversion__run = r ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> self . model . Result . objects . count ( ) , <NUM_LIT:1> ) <EOL> class RefreshTransactionTest ( case . TransactionTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . envs = self . F . EnvironmentFactory . create_full_set ( <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> self . p = self . F . ProductFactory . create ( ) <EOL> self . pv8 = self . F . ProductVersionFactory . create ( <EOL> product = self . p , version = "<STR_LIT>" , environments = self . envs ) <EOL> self . pv9 = self . F . ProductVersionFactory . create ( <EOL> product = self . p , version = "<STR_LIT>" , environments = self . envs ) <EOL> def create_run_needing_refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( <EOL> productversion = self . pv8 ) <EOL> r . activate ( ) <EOL> deleteme_cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . RunCaseVersionFactory ( run = r , caseversion = deleteme_cv ) <EOL> ts = self . F . SuiteFactory . create ( product = self . p , status = "<STR_LIT>" ) <EOL> self . F . RunSuiteFactory . create ( suite = ts , run = r ) <EOL> cv_needed = [ ] <EOL> for num in range ( <NUM_LIT:6> ) : <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> name = "<STR_LIT>" + str ( num ) , <EOL> productversion = self . pv8 , <EOL> status = "<STR_LIT>" , <EOL> ) <EOL> self . F . SuiteCaseFactory . create ( suite = ts , case = cv . case ) <EOL> cv_needed . append ( cv ) <EOL> keepme_rcv = self . F . RunCaseVersionFactory ( <EOL> run = r , <EOL> caseversion = cv_needed [ <NUM_LIT:3> ] , <EOL> order = <NUM_LIT:0> , <EOL> ) <EOL> deleteme_env = self . F . EnvironmentFactory . create_set ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ) [ <NUM_LIT:0> ] <EOL> self . F . model . RunCaseVersion . environments . through ( <EOL> runcaseversion = keepme_rcv , <EOL> environment = deleteme_env , <EOL> ) . save ( ) <EOL> return { <EOL> "<STR_LIT:r>" : r , <EOL> "<STR_LIT>" : deleteme_cv , <EOL> "<STR_LIT>" : ts , <EOL> "<STR_LIT>" : cv_needed , <EOL> "<STR_LIT>" : keepme_rcv , <EOL> "<STR_LIT>" : deleteme_env , <EOL> } <EOL> def assert_rolled_back ( self , test_data ) : <EOL> r = test_data [ "<STR_LIT:r>" ] <EOL> self . refresh ( r ) <EOL> self . assertEqual ( r . runcaseversions . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> self . F . model . RunCaseVersion . environments . through . objects . count ( ) , <EOL> <NUM_LIT:9> , <EOL> ) <EOL> self . assertEqual ( self . F . model . RunCaseVersion . objects . filter ( <EOL> run = r , <EOL> caseversion = test_data [ "<STR_LIT>" ] , <EOL> ) . count ( ) , <NUM_LIT:1> ) <EOL> def do_rollback_test ( self , new_func ) : <EOL> """<STR_LIT>""" <EOL> test_data = self . create_run_needing_refresh ( ) <EOL> class SurpriseException ( RuntimeError ) : <EOL> pass <EOL> def raise_exception ( * args , ** kwargs ) : <EOL> raise SurpriseException ( "<STR_LIT>" ) <EOL> new_func . side_effect = raise_exception <EOL> with self . assertRaises ( SurpriseException ) : <EOL> test_data [ "<STR_LIT:r>" ] . refresh ( ) <EOL> self . assert_rolled_back ( test_data ) <EOL> @ patch . object ( Run , '<STR_LIT>' ) <EOL> def test_exception_in_delete_runcaseversions ( self , new_func ) : <EOL> """<STR_LIT>""" <EOL> self . do_rollback_test ( new_func ) <EOL> @ patch . object ( Run , '<STR_LIT>' ) <EOL> def test_exception_in_bulk_insert_new_rcv ( self , new_func ) : <EOL> """<STR_LIT>""" <EOL> self . do_rollback_test ( new_func ) <EOL> @ patch . object ( Run , '<STR_LIT>' ) <EOL> def test_exception_in_bulk_update_rcv_envs ( self , new_func ) : <EOL> """<STR_LIT>""" <EOL> self . do_rollback_test ( new_func ) <EOL> @ patch . object ( Run , '<STR_LIT>' ) <EOL> def test_exception_after_complete ( self , new_func ) : <EOL> """<STR_LIT>""" <EOL> self . do_rollback_test ( new_func ) </s>
