<s> """<STR_LIT>""" <EOL> from tests import case <EOL> class EditSuiteFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . suites . forms import EditSuiteForm <EOL> return EditSuiteForm <EOL> def test_edit_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> s = self . F . SuiteFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( p . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> user = u ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( suite . product , p ) <EOL> self . assertEqual ( suite . name , "<STR_LIT>" ) <EOL> self . assertEqual ( suite . description , "<STR_LIT>" ) <EOL> self . assertEqual ( suite . modified_by , u ) <EOL> def test_no_change_product_option ( self ) : <EOL> """<STR_LIT>""" <EOL> self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory ( ) <EOL> self . F . SuiteCaseFactory ( suite = s ) <EOL> f = self . form ( instance = s ) <EOL> self . assertEqual ( <EOL> [ c [ <NUM_LIT:0> ] for c in f . fields [ "<STR_LIT>" ] . choices ] , <EOL> [ '<STR_LIT>' , s . product . id ] <EOL> ) <EOL> self . assertTrue ( f . fields [ "<STR_LIT>" ] . readonly ) <EOL> def test_no_edit_product ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> s = self . F . SuiteFactory ( ) <EOL> self . F . SuiteCaseFactory ( suite = s ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( p . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <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_add_cases ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . F . SuiteFactory ( ) <EOL> c = self . F . CaseFactory ( product = s . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( s . product . id ) , <EOL> "<STR_LIT:name>" : s . name , <EOL> "<STR_LIT:description>" : s . description , <EOL> "<STR_LIT:status>" : s . status , <EOL> "<STR_LIT>" : [ str ( c . id ) ] , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( set ( suite . cases . all ( ) ) , set ( [ c ] ) ) <EOL> def test_add_bad_case ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . F . SuiteFactory ( ) <EOL> c = self . F . CaseFactory ( product = s . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( s . product . id ) , <EOL> "<STR_LIT:name>" : s . name , <EOL> "<STR_LIT:description>" : s . description , <EOL> "<STR_LIT:status>" : s . status , <EOL> "<STR_LIT>" : [ str ( c . id + <NUM_LIT:1> ) ] , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> self . assertEqual ( <EOL> f . errors [ "<STR_LIT>" ] , <EOL> [ u"<STR_LIT>" ] <EOL> ) <EOL> def test_edit_cases ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . F . SuiteFactory . create ( ) <EOL> self . F . SuiteCaseFactory . create ( suite = s ) <EOL> c = self . F . CaseFactory . create ( product = s . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( s . product . id ) , <EOL> "<STR_LIT:name>" : s . name , <EOL> "<STR_LIT:description>" : s . description , <EOL> "<STR_LIT:status>" : s . status , <EOL> "<STR_LIT>" : [ str ( c . id ) ] , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( set ( suite . cases . all ( ) ) , set ( [ c ] ) ) <EOL> def test_edit_cases_order_only ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . F . SuiteFactory . create ( ) <EOL> c1 = self . F . CaseFactory . create ( product = s . product ) <EOL> c2 = self . F . CaseFactory . create ( product = s . product ) <EOL> self . F . SuiteCaseFactory . create ( suite = s , case = c1 , order = <NUM_LIT:0> ) <EOL> self . F . SuiteCaseFactory . create ( suite = s , case = c2 , order = <NUM_LIT:1> ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( s . product . id ) , <EOL> "<STR_LIT:name>" : s . name , <EOL> "<STR_LIT:description>" : s . description , <EOL> "<STR_LIT:status>" : s . status , <EOL> "<STR_LIT>" : [ str ( c2 . id ) , str ( c1 . id ) ] , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( <EOL> list ( suite . cases . all ( ) . order_by ( "<STR_LIT>" ) ) , <EOL> [ c2 , c1 ] , <EOL> ) <EOL> def test_remove_dup_cases ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . F . SuiteFactory . create ( ) <EOL> c = self . F . CaseFactory . create ( product = s . product ) <EOL> self . F . SuiteCaseFactory . create ( suite = s , case = c ) <EOL> self . F . SuiteCaseFactory . create ( suite = s , case = c ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( s . product . id ) , <EOL> "<STR_LIT:name>" : s . name , <EOL> "<STR_LIT:description>" : s . description , <EOL> "<STR_LIT:status>" : s . status , <EOL> "<STR_LIT>" : [ str ( c . id ) , str ( c . id ) ] , <EOL> "<STR_LIT>" : str ( s . cc_version ) , <EOL> } , <EOL> instance = s , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( set ( suite . cases . all ( ) ) , set ( [ c ] ) ) <EOL> class AddSuiteFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . suites . forms import AddSuiteForm <EOL> return AddSuiteForm <EOL> def test_add_suite ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( p . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } , <EOL> user = u <EOL> ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( suite . product , p ) <EOL> self . assertEqual ( suite . name , "<STR_LIT>" ) <EOL> self . assertEqual ( suite . description , "<STR_LIT>" ) <EOL> self . assertEqual ( suite . created_by , u ) <EOL> def test_initial_state ( self ) : <EOL> """<STR_LIT>""" <EOL> form = self . form ( ) <EOL> self . assertEqual ( form [ "<STR_LIT:status>" ] . value ( ) , "<STR_LIT>" ) <EOL> def test_add_with_cases ( self ) : <EOL> """<STR_LIT>""" <EOL> c = self . F . CaseFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( c . product . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( c . id ) ] , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> suite = f . save ( ) <EOL> self . assertEqual ( set ( suite . cases . all ( ) ) , set ( [ c ] ) ) <EOL> def test_product_id_attrs ( self ) : <EOL> """<STR_LIT>""" <EOL> case = self . F . CaseFactory . create ( ) <EOL> f = self . form ( ) <EOL> self . assertEqual ( <EOL> [ <EOL> c [ <NUM_LIT:1> ] . attrs [ "<STR_LIT>" ] <EOL> for c in f . fields [ "<STR_LIT>" ] . choices <EOL> if c [ <NUM_LIT:0> ] <EOL> ] , <EOL> [ case . product . id ] <EOL> ) </s>
