<s> """<STR_LIT>""" <EOL> from tests import case <EOL> class EditTagFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . tags . forms import EditTagForm <EOL> return EditTagForm <EOL> def test_edit_tag ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p2 = self . F . ProductFactory . create ( ) <EOL> t = self . F . TagFactory . create ( name = "<STR_LIT>" , product = p ) <EOL> u = self . F . UserFactory . create ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( p2 . id ) , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( t . cc_version ) , <EOL> } , <EOL> instance = t , <EOL> user = u , <EOL> ) <EOL> tag = f . save ( ) <EOL> self . assertEqual ( tag . name , "<STR_LIT>" ) <EOL> self . assertEqual ( tag . product , p2 ) <EOL> self . assertEqual ( tag . description , "<STR_LIT>" ) <EOL> self . assertEqual ( tag . modified_by , u ) <EOL> def test_no_edit_product_if_tagged ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p2 = self . F . ProductFactory . create ( ) <EOL> cv = self . F . CaseVersionFactory . create ( case__product = p , productversion__product = p ) <EOL> t = self . F . TagFactory . create ( name = "<STR_LIT>" , product = p ) <EOL> cv . tags . add ( t ) <EOL> f = self . form ( <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : str ( p2 . id ) } , instance = t ) <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_no_set_product_if_multiple_products_tagged ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p2 = self . F . ProductFactory . create ( ) <EOL> cv = self . F . CaseVersionFactory . create ( <EOL> case__product = p , productversion__product = p ) <EOL> cv2 = self . F . CaseVersionFactory . create ( <EOL> case__product = p2 , productversion__product = p2 ) <EOL> t = self . F . TagFactory . create ( name = "<STR_LIT>" ) <EOL> cv . tags . add ( t ) <EOL> cv2 . tags . add ( t ) <EOL> f = self . form ( <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : str ( p . id ) } , instance = t ) <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> cv = self . F . CaseVersionFactory ( ) <EOL> t = self . F . TagFactory ( product = cv . productversion . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( t . product . id ) , <EOL> "<STR_LIT:name>" : t . name , <EOL> "<STR_LIT:description>" : t . description , <EOL> "<STR_LIT>" : [ str ( cv . id ) ] , <EOL> "<STR_LIT>" : str ( t . cc_version ) , <EOL> } , <EOL> instance = t , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> tag = f . save ( ) <EOL> self . assertEqual ( set ( tag . caseversions . all ( ) ) , set ( [ cv ] ) ) <EOL> def test_add_bad_case ( self ) : <EOL> """<STR_LIT>""" <EOL> cv = self . F . CaseVersionFactory ( ) <EOL> t = self . F . TagFactory ( product = cv . productversion . product ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( t . product . id ) , <EOL> "<STR_LIT:name>" : t . name , <EOL> "<STR_LIT:description>" : t . description , <EOL> "<STR_LIT>" : [ str ( cv . id + <NUM_LIT:1> ) ] , <EOL> "<STR_LIT>" : str ( t . cc_version ) , <EOL> } , <EOL> instance = t , <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> pv = self . F . ProductVersionFactory ( ) <EOL> t = self . F . TagFactory ( product = pv . product ) <EOL> t . caseversions . add ( self . F . CaseVersionFactory ( productversion = pv ) ) <EOL> cv_new = self . F . CaseVersionFactory ( productversion = pv ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( t . product . id ) , <EOL> "<STR_LIT:name>" : t . name , <EOL> "<STR_LIT:description>" : t . description , <EOL> "<STR_LIT>" : [ str ( cv_new . id ) ] , <EOL> "<STR_LIT>" : str ( t . cc_version ) , <EOL> } , <EOL> instance = t , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> tag = f . save ( ) <EOL> self . assertEqual ( set ( tag . caseversions . all ( ) ) , set ( [ cv_new ] ) ) <EOL> class AddTagFormTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def form ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . view . manage . tags . forms import AddTagForm <EOL> return AddTagForm <EOL> def test_add_tag ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> u = self . F . UserFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( p . id ) , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } , <EOL> user = u ) <EOL> tag = f . save ( ) <EOL> self . assertEqual ( tag . name , "<STR_LIT>" ) <EOL> self . assertEqual ( tag . product , p ) <EOL> self . assertEqual ( tag . description , "<STR_LIT>" ) <EOL> self . assertEqual ( tag . created_by , u ) <EOL> def test_add_with_cases ( self ) : <EOL> """<STR_LIT>""" <EOL> cv = self . F . CaseVersionFactory ( ) <EOL> f = self . form ( <EOL> { <EOL> "<STR_LIT>" : str ( cv . productversion . product . id ) , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ str ( cv . id ) ] , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> } , <EOL> ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> tag = f . save ( ) <EOL> self . assertEqual ( set ( tag . caseversions . all ( ) ) , set ( [ cv ] ) ) <EOL> def test_product_id_attrs ( self ) : <EOL> """<STR_LIT>""" <EOL> cv = self . F . CaseVersionFactory . 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> [ cv . productversion . product . id ] <EOL> ) </s>
