#NEWLINE# @ mock . patch ( 'changes.models.Repository.get_vcs' ) #NEWLINE# def test_with_vcs( self , get_vcs ) : #NEWLINE# #INDENT# def log_results( parent = None , branch = None , offset = 0 , limit = 100 , paths = None ) : #NEWLINE# #INDENT# assert ( not branch ) #NEWLINE# results = [ RevisionResult ( id = ( 'a' * 40 ) , message = 'hello world' , author = 'Foo <foo@example.com>' , author_date = datetime ( 2013 , 9 , 19 , 22 , 15 , 22 ) ) , RevisionResult ( id = ( 'b' * 40 ) , message = 'biz' , author = 'Bar <bar@example.com>' , author_date = datetime ( 2013 , 9 , 19 , 22 , 15 , 21 ) ) ] #NEWLINE# return iter ( results [ offset : ( offset + limit ) ] ) #NEWLINE# #UNINDENT# fake_vcs = mock . Mock ( spec = Vcs ) #NEWLINE# fake_vcs . log . side_effect = log_results #NEWLINE# get_vcs . return_value = fake_vcs #NEWLINE# project = self . create_project ( ) #NEWLINE# source = self . create_source ( project , revision_sha = ( 'b' * 40 ) ) #NEWLINE# build = self . create_build ( project , source = source , status = Status . finished ) #NEWLINE# path = '/api/0/projects/{0}/commits/' . format ( project . id . hex ) #NEWLINE# resp = self . client . get ( path ) #NEWLINE# assert ( resp . status_code == 200 ) #NEWLINE# data = self . unserialize ( resp ) #NEWLINE# assert ( len ( data ) == 2 ) #NEWLINE# assert ( data [ 0 ] [ 'id' ] == ( 'a' * 40 ) ) #NEWLINE# assert ( data [ 0 ] [ 'build' ] is None ) #NEWLINE# assert ( data [ 1 ] [ 'id' ] == ( 'b' * 40 ) ) #NEWLINE# assert ( data [ 1 ] [ 'build' ] [ 'id' ] == build . id . hex ) #NEWLINE# resp = self . client . get ( ( path + '?per_page=1&page=1' ) ) #NEWLINE# assert ( resp . status_code == 200 ) #NEWLINE# data = self . unserialize ( resp ) #NEWLINE# assert ( len ( data ) == 1 ) #NEWLINE# assert ( data [ 0 ] [ 'id' ] == ( 'a' * 40 ) ) #NEWLINE# resp = self . client . get ( ( path + '?per_page=1&page=2' ) ) #NEWLINE# assert ( resp . status_code == 200 ) #NEWLINE# data = self . unserialize ( resp ) #NEWLINE# assert ( len ( data ) == 1 ) #NEWLINE# assert ( data [ 0 ] [ 'id' ] == ( 'b' * 40 ) )