<s> from __future__ import unicode_literals <EOL> from kgb import SpyAgency <EOL> from reviewboard . hostingsvcs . models import HostingServiceAccount <EOL> from reviewboard . hostingsvcs . service import get_hosting_service <EOL> from reviewboard . testing import TestCase <EOL> class ServiceTests ( SpyAgency , TestCase ) : <EOL> service_name = None <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ServiceTests , self ) . __init__ ( * args , ** kwargs ) <EOL> self . assertNotEqual ( self . service_name , None ) <EOL> self . service_class = get_hosting_service ( self . service_name ) <EOL> def setUp ( self ) : <EOL> super ( ServiceTests , self ) . setUp ( ) <EOL> self . assertNotEqual ( self . service_class , None ) <EOL> def _get_repository_info ( self , field , plan = None ) : <EOL> if plan : <EOL> self . assertNotEqual ( self . service_class . plans , None ) <EOL> result = None <EOL> for plan_type , info in self . service_class . plans : <EOL> if plan_type == plan : <EOL> result = info [ field ] <EOL> break <EOL> self . assertNotEqual ( result , None ) <EOL> return result <EOL> else : <EOL> self . assertEqual ( self . service_class . plans , None ) <EOL> self . assertTrue ( hasattr ( self . service_class , field ) ) <EOL> return getattr ( self . service_class , field ) <EOL> def _get_form ( self , plan = None , fields = { } ) : <EOL> form = self . _get_repository_info ( '<STR_LIT>' , plan ) <EOL> self . assertNotEqual ( form , None ) <EOL> form = form ( fields ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> return form <EOL> def _get_hosting_account ( self , use_url = False , local_site = None ) : <EOL> if use_url : <EOL> hosting_url = '<STR_LIT>' <EOL> else : <EOL> hosting_url = None <EOL> return HostingServiceAccount ( service_name = self . service_name , <EOL> username = '<STR_LIT>' , <EOL> hosting_url = hosting_url , <EOL> local_site = local_site ) <EOL> def _get_service ( self ) : <EOL> return self . _get_hosting_account ( ) . service <EOL> def _get_repository_fields ( self , tool_name , fields , plan = None , <EOL> with_url = False ) : <EOL> form = self . _get_form ( plan , fields ) <EOL> account = self . _get_hosting_account ( with_url ) <EOL> service = account . service <EOL> self . assertNotEqual ( service , None ) <EOL> return service . get_repository_fields ( username = account . username , <EOL> hosting_url = '<STR_LIT>' , <EOL> plan = plan , <EOL> tool_name = tool_name , <EOL> field_vars = form . clean ( ) ) </s>
