<s> import unittest <EOL> import webbrowser <EOL> from bitbucket . bitbucket import Bitbucket <EOL> TEST_REPO_SLUG = '<STR_LIT>' <EOL> OAUTH_ACCESS_TOKEN = '<STR_LIT>' <EOL> OAUTH_ACCESS_TOKEN_SECRET = '<STR_LIT>' <EOL> class AuthenticatedBitbucketTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from settings import USERNAME , CONSUMER_KEY , CONSUMER_SECRET <EOL> PASSWORD = None <EOL> except ImportError : <EOL> try : <EOL> from settings import USERNAME , PASSWORD <EOL> CONSUMER_KEY = None <EOL> CONSUMER_SECRET = None <EOL> except ImportError : <EOL> raise ImportError ( '<STR_LIT>' ) <EOL> if USERNAME and PASSWORD : <EOL> self . bb = Bitbucket ( USERNAME , PASSWORD ) <EOL> elif USERNAME and CONSUMER_KEY and CONSUMER_SECRET : <EOL> global OAUTH_ACCESS_TOKEN , OAUTH_ACCESS_TOKEN_SECRET <EOL> self . bb = Bitbucket ( USERNAME ) <EOL> if not OAUTH_ACCESS_TOKEN and not OAUTH_ACCESS_TOKEN_SECRET : <EOL> self . bb . authorize ( CONSUMER_KEY , CONSUMER_SECRET , '<STR_LIT>' ) <EOL> webbrowser . open ( self . bb . url ( '<STR_LIT>' , token = self . bb . access_token ) ) <EOL> token_is_valid = False <EOL> while not token_is_valid : <EOL> oauth_verifier = raw_input ( '<STR_LIT>' ) <EOL> token_is_valid = bool ( oauth_verifier and self . bb . verify ( oauth_verifier ) [ <NUM_LIT:0> ] ) <EOL> if not token_is_valid : <EOL> print ( '<STR_LIT>' ) <EOL> OAUTH_ACCESS_TOKEN = self . bb . access_token <EOL> OAUTH_ACCESS_TOKEN_SECRET = self . bb . access_token_secret <EOL> else : <EOL> self . bb . authorize ( CONSUMER_KEY , CONSUMER_SECRET , '<STR_LIT>' , OAUTH_ACCESS_TOKEN , OAUTH_ACCESS_TOKEN_SECRET ) <EOL> success , result = self . bb . repository . create ( TEST_REPO_SLUG , has_issues = True ) <EOL> assert success <EOL> self . bb . repo_slug = result [ u'<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . bb . repository . delete ( ) <EOL> self . bb = None <EOL> class BitbucketAuthenticatedMethodsTest ( AuthenticatedBitbucketTest ) : <EOL> """<STR_LIT>""" <EOL> def test_get_tags ( self ) : <EOL> """<STR_LIT>""" <EOL> success , result = self . bb . get_tags ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertIsInstance ( result , dict ) <EOL> success , result = self . bb . get_tags ( repo_slug = '<STR_LIT>' ) <EOL> self . assertFalse ( success ) <EOL> def test_get_branches ( self ) : <EOL> """<STR_LIT>""" <EOL> success , result = self . bb . get_branches ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertIsInstance ( result , dict ) <EOL> success , result = self . bb . get_branches ( repo_slug = '<STR_LIT>' ) <EOL> self . assertFalse ( success ) </s>
