<s> """<STR_LIT>""" <EOL> from datetime import date <EOL> from django . core . exceptions import ValidationError <EOL> from tests import case <EOL> class EditRunFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . runs . forms import EditRunForm <EOL> return EditRunForm <EOL> def test_edit_run ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory . create ( productversion__product = pv . product ) <EOL> u = self . F . UserFactory . create ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> user = u ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( run . productversion , pv ) <EOL> self . assertEqual ( run . name , "<STR_LIT>" ) <EOL> self . assertEqual ( run . description , "<STR_LIT>" ) <EOL> self . assertEqual ( run . start , date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( run . end , date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( run . modified_by , u ) <EOL> def test_add_suites ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory . create ( productversion__product = pv . product ) <EOL> s = self . F . SuiteFactory . create ( product = pv . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : r . name , <EOL> "<STR_LIT:description>" : r . description , <EOL> "<STR_LIT:start>" : r . start . strftime ( "<STR_LIT>" ) , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( s . id ) ] , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( set ( run . suites . all ( ) ) , set ( [ s ] ) ) <EOL> def test_add_bad_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory . create ( productversion__product = pv . product ) <EOL> s = self . F . SuiteFactory . create ( product = pv . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : r . name , <EOL> "<STR_LIT:description>" : r . description , <EOL> "<STR_LIT:start>" : r . start . strftime ( "<STR_LIT>" ) , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( s . id + <NUM_LIT:1> ) ] , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> self . assertEqual ( <EOL> f . errors [ "<STR_LIT>" ] , <EOL> [ u"<STR_LIT>" ] <EOL> ) <EOL> def test_edit_suites ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory . create ( productversion__product = pv . product ) <EOL> self . F . RunSuiteFactory . create ( run = r ) <EOL> s = self . F . SuiteFactory . create ( product = pv . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : r . name , <EOL> "<STR_LIT:description>" : r . description , <EOL> "<STR_LIT:start>" : r . start . strftime ( "<STR_LIT>" ) , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( s . id ) ] , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( set ( run . suites . all ( ) ) , set ( [ s ] ) ) <EOL> def test_no_change_product_option ( self ) : <EOL> """<STR_LIT>""" <EOL> self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory ( ) <EOL> f = self . form ( instance = r ) <EOL> self . assertEqual ( <EOL> [ c [ <NUM_LIT:0> ] for c in f . fields [ "<STR_LIT>" ] . choices ] , <EOL> [ '<STR_LIT>' , r . productversion . id ] <EOL> ) <EOL> def test_no_edit_product ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory ( ) <EOL> r = self . F . RunFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> self . assertEqual ( <EOL> f . errors [ "<STR_LIT>" ] , <EOL> [ u"<STR_LIT>" <EOL> "<STR_LIT>" ] <EOL> ) <EOL> def test_active_run_no_product_version_options ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory ( <EOL> status = self . model . Run . STATUS . active , <EOL> productversion__product = pv . product ) <EOL> f = self . form ( instance = r ) <EOL> self . assertEqual ( <EOL> [ c [ <NUM_LIT:0> ] for c in f . fields [ "<STR_LIT>" ] . choices ] , <EOL> [ '<STR_LIT>' , r . productversion . id ] <EOL> ) <EOL> def test_active_run_product_version_readonly ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> r = self . F . RunFactory ( <EOL> status = self . model . Run . STATUS . active , <EOL> productversion__product = pv . product ) <EOL> f = self . form ( instance = r ) <EOL> self . assertTrue ( f . fields [ "<STR_LIT>" ] . readonly ) <EOL> def test_active_run_no_edit_product_version ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory ( ) <EOL> r = self . F . RunFactory ( status = self . model . Run . STATUS . active ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> self . assertEqual ( <EOL> f . errors [ "<STR_LIT>" ] , <EOL> [ u"<STR_LIT>" <EOL> "<STR_LIT>" ] <EOL> ) <EOL> def test_active_run_suites_preserved ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = pv . product ) <EOL> r = self . F . RunFactory . create ( productversion__product = pv . product ) <EOL> self . F . RunSuiteFactory . create ( run = r , suite = s ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : r . name , <EOL> "<STR_LIT:description>" : r . description , <EOL> "<STR_LIT:start>" : r . start . strftime ( "<STR_LIT>" ) , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( s . name ) ] , <EOL> "<STR_LIT>" : str ( r . cc_version ) , <EOL> } , <EOL> instance = r , <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( set ( run . suites . all ( ) ) , set ( [ s ] ) ) <EOL> class AddRunFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . runs . forms import AddRunForm <EOL> return AddRunForm <EOL> def test_add_run ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } , <EOL> user = u <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( run . productversion , pv ) <EOL> self . assertEqual ( run . name , "<STR_LIT>" ) <EOL> self . assertEqual ( run . description , "<STR_LIT>" ) <EOL> self . assertEqual ( run . start , date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( run . end , date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( run . created_by , u ) <EOL> def test_add_run_series_clears_build ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> user = u <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( run . build , None ) <EOL> def test_add_run_withsuites ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = pv . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( pv . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( s . id ) ] , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } , <EOL> ) <EOL> run = f . save ( ) <EOL> self . assertEqual ( set ( run . suites . all ( ) ) , set ( [ s ] ) ) </s>
