#NEWLINE# def test_get_change( self ) : #NEWLINE# #INDENT# 'Testing GitHub get_change implementation' #NEWLINE# commit_sha = '1c44b461cebe5874a857c51a4a13a849a4d1e52d' #NEWLINE# parent_sha = '44568f7d33647d286691517e6325fea5c7a21d5e' #NEWLINE# tree_sha = '56e25e58380daf9b4dfe35677ae6043fe1743922' #NEWLINE# commits_api_response = json . dumps ( [ { #NEWLINE# #INDENT# 'commit' : { #NEWLINE# #INDENT# 'author' : { #NEWLINE# #INDENT# 'name' : 'David Trowbridge' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'committer' : { #NEWLINE# #INDENT# 'date' : '2013-06-25T23:31:22Z' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'message' : 'Move .clearfix to defs.less' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'sha' : commit_sha , #NEWLINE# 'parents' : [ { #NEWLINE# #INDENT# 'sha' : parent_sha , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# compare_api_response = json . dumps ( { #NEWLINE# #INDENT# 'base_commit' : { #NEWLINE# #INDENT# 'commit' : { #NEWLINE# #INDENT# 'tree' : { #NEWLINE# #INDENT# 'sha' : tree_sha , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# 'files' : [ { #NEWLINE# #INDENT# 'sha' : '4344b3ad41b171ea606e88e9665c34cca602affb' , #NEWLINE# 'filename' : 'reviewboard/static/rb/css/defs.less' , #NEWLINE# 'status' : 'modified' , #NEWLINE# 'patch' : dedent ( '                        @@ -182,4 +182,23 @@\n                         }\n\n\n                        +/* Add a rule for clearing floats, */\n                        +.clearfix {\n                        +  display: inline-block;\n                        +\n                        +  &:after {\n                        +    clear: both;\n                        +    content: ".";\n                        +    display: block;\n                        +    height: 0;\n                        +    visibility: hidden;\n                        +  }\n                        +}\n                        +\n                        +/* Hides from IE-mac \\*/\n                        +* html .clearfix {height: 1%;}\n                        +.clearfix {display: block;}\n                        +/* End hide from IE-mac */\n                        +\n                        +\n                         // vim: set et ts=2 sw=2:' ) , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'sha' : '8e3129277b018b169cb8d13771433fbcd165a17c' , #NEWLINE# 'filename' : 'reviewboard/static/rb/css/reviews.less' , #NEWLINE# 'status' : 'modified' , #NEWLINE# 'patch' : dedent ( '                        @@ -1311,24 +1311,6 @@\n                           .border-radius(8px);\n                         }\n\n                        -/* Add a rule for clearing floats, */\n                        -.clearfix {\n                        -  display: inline-block;\n                        -\n                        -  &:after {\n                        -    clear: both;\n                        -    content: ".";\n                        -    display: block;\n                        -    height: 0;\n                        -    visibility: hidden;\n                        -  }\n                        -}\n                        -\n                        -/* Hides from IE-mac \\*/\n                        -* html .clearfix {height: 1%;}\n                        -.clearfix {display: block;}\n                        -/* End hide from IE-mac */\n                        -\n\n                         /****************************************************\n                          * Issue Summary' ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# trees_api_response = json . dumps ( { #NEWLINE# #INDENT# 'tree' : [ { #NEWLINE# #INDENT# 'path' : 'reviewboard/static/rb/css/defs.less' , #NEWLINE# 'sha' : '830a40c3197223c6a0abb3355ea48891a1857bfd' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'path' : 'reviewboard/static/rb/css/reviews.less' , #NEWLINE# 'sha' : '535cd2c4211038d1bb8ab6beaed504e0db9d7e62' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# step = [ 1 ] #NEWLINE# def _http_get( service , url , * args , **kwargs ) : #NEWLINE# #INDENT# parsed = urlparse ( url ) #NEWLINE# if ( parsed . path == '/repos/myuser/myrepo/commits' ) : #NEWLINE# #INDENT# self . assertEqual ( step [ 0 ] , 1 ) #NEWLINE# step [ 0 ] += 1 #NEWLINE# query = parsed . query . split ( '&' ) #NEWLINE# self . assertIn ( ( 'sha=%s' % commit_sha ) , query ) #NEWLINE# return ( commits_api_response , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if parsed . path . startswith ( '/repos/myuser/myrepo/compare/' ) : #NEWLINE# #INDENT# self . assertEqual ( step [ 0 ] , 2 ) #NEWLINE# step [ 0 ] += 1 #NEWLINE# revs = parsed . path . split ( '/' ) [ ( - 1 ) ] . split ( '...' ) #NEWLINE# self . assertEqual ( revs [ 0 ] , parent_sha ) #NEWLINE# self . assertEqual ( revs [ 1 ] , commit_sha ) #NEWLINE# return ( compare_api_response , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if parsed . path . startswith ( '/repos/myuser/myrepo/git/trees/' ) : #NEWLINE# #INDENT# self . assertEqual ( step [ 0 ] , 3 ) #NEWLINE# step [ 0 ] += 1 #NEWLINE# self . assertEqual ( parsed . path . split ( '/' ) [ ( - 1 ) ] , tree_sha ) #NEWLINE# return ( trees_api_response , None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( parsed ) #NEWLINE# self . fail ( 'Got an unexpected GET request' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# account = self . _get_hosting_account ( ) #NEWLINE# account . data [ 'authorization' ] = { #NEWLINE# #INDENT# 'token' : 'abc123' , #NEWLINE# #UNINDENT# } #NEWLINE# service = account . service #NEWLINE# self . spy_on ( service . client . http_get , call_fake = _http_get ) #NEWLINE# repository = Repository ( hosting_account = account ) #NEWLINE# repository . extra_data = { #NEWLINE# #INDENT# 'repository_plan' : 'public' , #NEWLINE# 'github_public_repo_name' : 'myrepo' , #NEWLINE# #UNINDENT# } #NEWLINE# change = service . get_change ( repository , commit_sha ) #NEWLINE# self . assertTrue ( service . client . http_get . called ) #NEWLINE# self . assertEqual ( change . message , 'Move .clearfix to defs.less' ) #NEWLINE# self . assertEqual ( md5 ( change . diff . encode ( 'utf-8' ) ) . hexdigest ( ) , '0dd1bde0a60c0a7bb92c27b50f51fcb6' )