<s> import random <EOL> import unittest <EOL> from youtrack import YouTrackException , EnumBundle , EnumField , UserBundle <EOL> from youtrack . connection import Connection , youtrack , os , os <EOL> import math <EOL> class ConnectionTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . con = Connection ( "<STR_LIT>" , "<STR_LIT:root>" , "<STR_LIT:root>" ) <EOL> def test_getProject ( self ) : <EOL> p = self . con . getProject ( '<STR_LIT>' ) <EOL> self . assertEqual ( p . id , '<STR_LIT>' ) <EOL> self . assertEqual ( p . name , '<STR_LIT>' ) <EOL> def test_getSubsystems ( self ) : <EOL> subsystems = self . con . getSubsystems ( '<STR_LIT>' ) <EOL> default = [ s for s in subsystems if s . isDefault ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( default is not None ) <EOL> def test_getIssue ( self ) : <EOL> i = self . con . getIssue ( '<STR_LIT>' ) <EOL> self . assertEqual ( i . id , '<STR_LIT>' ) <EOL> self . assertEqual ( i . numberInProject , '<STR_LIT:1>' ) <EOL> self . assertEqual ( i . projectShortName , '<STR_LIT>' ) <EOL> def test_createIssue ( self ) : <EOL> i = self . con . createIssue ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( i . projectShortName , '<STR_LIT>' ) <EOL> self . assertEqual ( i . priority , '<STR_LIT:2>' ) <EOL> self . assertEqual ( i . type , '<STR_LIT>' ) <EOL> self . assertEqual ( i . subsystem , '<STR_LIT>' ) <EOL> def test_createIssueAttachment ( self ) : <EOL> i = self . con . createIssue ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fname = '<STR_LIT>' <EOL> content = open ( fname ) <EOL> self . con . createAttachment ( i . id , fname , content ) <EOL> self . assertEqual ( fname , self . con . getAttachments ( i . id ) [ <NUM_LIT:0> ] . name ) <EOL> def test_createAndDeleteSubsystem ( self ) : <EOL> name = '<STR_LIT>' + str ( random . random ( ) ) + "<STR_LIT:]>" <EOL> self . con . createSubsystemDetailed ( '<STR_LIT>' , name , False , '<STR_LIT>' ) <EOL> s = self . con . getSubsystem ( '<STR_LIT>' , name ) <EOL> self . assertEqual ( s . name , name ) <EOL> self . assertEqual ( s . isDefault , '<STR_LIT:false>' ) <EOL> self . con . deleteSubsystem ( '<STR_LIT>' , name ) <EOL> def test_importIssues ( self ) : <EOL> issues = self . con . getIssues ( "<STR_LIT:A>" , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:10> ) <EOL> for issue in issues : <EOL> if hasattr ( issue , "<STR_LIT>" ) : <EOL> issue [ "<STR_LIT>" ] = issue [ "<STR_LIT>" ] <EOL> del issue . Assignee <EOL> self . con . importIssues ( "<STR_LIT:B>" , "<STR_LIT>" , issues ) <EOL> class EnumBundleTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . con = Connection ( '<STR_LIT>' , '<STR_LIT:root>' , '<STR_LIT:root>' ) <EOL> def test_01_createBundle ( self ) : <EOL> enum_bundle = EnumBundle ( ) <EOL> enum_bundle . name = "<STR_LIT>" <EOL> enum_bundle . values = [ ] <EOL> value_names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> for vn in value_names : <EOL> element = EnumField ( ) <EOL> element . name = vn <EOL> element . description = vn + "<STR_LIT>" <EOL> enum_bundle . values . append ( element ) <EOL> response = self . con . createBundle ( enum_bundle ) <EOL> self . assertTrue ( response . find ( "<STR_LIT>" + enum_bundle . name ) != - <NUM_LIT:1> ) <EOL> def test_02_getBundle ( self ) : <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( enum_bundle . name , "<STR_LIT>" ) <EOL> values = dict ( { } ) <EOL> for elem in enum_bundle . values : <EOL> values [ elem . name ] = elem . description <EOL> self . assertTrue ( len ( values . keys ( ) ) == <NUM_LIT:3> ) <EOL> for name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertEquals ( values [ name ] , name + "<STR_LIT>" ) <EOL> def test_03_getAllBundles ( self ) : <EOL> bundles = self . con . getAllBundles ( "<STR_LIT>" ) <EOL> names = [ bundle . name for bundle in bundles ] <EOL> self . assertTrue ( len ( names ) == <NUM_LIT:4> ) <EOL> for name in names : <EOL> self . assertTrue ( name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_04_renameBundle ( self ) : <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . con . renameBundle ( enum_bundle , "<STR_LIT>" ) <EOL> self . assertRaises ( Exception , self . con . getBundle , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_05_addDeleteValue ( self ) : <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> value = EnumField ( ) <EOL> value . name = "<STR_LIT>" <EOL> value . description = "<STR_LIT:description>" <EOL> self . con . addValueToBundle ( enum_bundle , value ) <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( len ( enum_bundle . values ) , <NUM_LIT:4> ) <EOL> new_value = "<STR_LIT>" <EOL> for v in enum_bundle . values : <EOL> if v . name == "<STR_LIT>" : <EOL> new_value = v <EOL> self . assertEquals ( new_value . description , "<STR_LIT:description>" ) <EOL> self . con . removeValueFromBundle ( enum_bundle , new_value ) <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertFalse ( "<STR_LIT>" in [ elem . name for elem in enum_bundle . values ] ) <EOL> def test_06_deleteBundle ( self ) : <EOL> enum_bundle = self . con . getBundle ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . con . deleteBundle ( enum_bundle ) <EOL> self . assertRaises ( Exception , self . con . getBundle , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class UserBundleTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . con = Connection ( '<STR_LIT>' , '<STR_LIT:root>' , '<STR_LIT:root>' ) <EOL> def test_01_createBundle ( self ) : <EOL> user_bundle = UserBundle ( ) <EOL> user_bundle . name = "<STR_LIT>" <EOL> user_bundle . users = [ self . con . getUser ( "<STR_LIT>" ) ] <EOL> user_bundle . groups = [ self . con . getGroup ( "<STR_LIT>" ) , self . con . getGroup ( "<STR_LIT>" ) ] <EOL> response = self . con . createBundle ( user_bundle ) <EOL> self . assertTrue ( response . find ( <EOL> "<STR_LIT>" + <EOL> user_bundle . name ) != - <NUM_LIT:1> ) <EOL> def test_02_getBundle ( self ) : <EOL> user_bundle = self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> self . assertEquals ( user_bundle . name , "<STR_LIT>" ) <EOL> user_names = [ u . login for u in user_bundle . users ] <EOL> group_names = [ u . name for u in user_bundle . groups ] <EOL> self . assertTrue ( len ( user_names ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( len ( group_names ) == <NUM_LIT:2> ) <EOL> self . assertTrue ( "<STR_LIT>" in user_names ) <EOL> self . assertTrue ( "<STR_LIT>" in group_names ) <EOL> self . assertTrue ( "<STR_LIT>" in group_names ) <EOL> def test_03_getAllBundles ( self ) : <EOL> bundles = self . con . getAllBundles ( "<STR_LIT:user>" ) <EOL> names = [ bundle . name for bundle in bundles ] <EOL> self . assertTrue ( len ( names ) == <NUM_LIT:3> ) <EOL> for name in names : <EOL> self . assertTrue ( name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_04_renameBundle ( self ) : <EOL> user_bundle = self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> self . con . renameBundle ( user_bundle , "<STR_LIT>" ) <EOL> self . assertRaises ( Exception , self . con . getBundle , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> def test_05_addDeleteValue ( self ) : <EOL> user_bundle = self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> new_user = self . con . getUser ( "<STR_LIT>" ) <EOL> self . con . addValueToBundle ( user_bundle , new_user ) <EOL> user_bundle = self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> self . assertEquals ( len ( user_bundle . users ) , <NUM_LIT:2> ) <EOL> user_names = [ u . login for u in user_bundle . users ] <EOL> self . assertTrue ( "<STR_LIT>" in user_names ) <EOL> self . assertTrue ( "<STR_LIT>" in user_names ) <EOL> self . con . removeValueFromBundle ( user_bundle , new_user ) <EOL> user_names = [ u . login for u in self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) . users ] <EOL> self . assertFalse ( "<STR_LIT>" in user_names ) <EOL> def test_06_deleteBundle ( self ) : <EOL> user_bundle = self . con . getBundle ( "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> self . con . deleteBundle ( user_bundle ) <EOL> self . assertRaises ( Exception , self . con . getBundle , "<STR_LIT:user>" , "<STR_LIT>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
