def mockCurl(*args, **kwargs): """ mock the curl2Json calls in the gitinterface """ logging.error("\nArgs: %r", args) logging.error("\nArgs: %r", getCommands(args)) logging.error("Kwargs: %r", kwargs ) cmdString = " ".join( getCommands(args) ) cmdString += str(kwargs) logging.error( "ComdString: %s", cmdString ) if "/tags" in cmdString: logging.error("Returning tags structure") return [ { "name": "v01-03-19", "commit": { "sha": "MyTagSha2", "url": "http://localhost/foo/bar" }, "zipball_url": "zipball/v0.1", "tarball_url": "tarball/v0.1" } ] if "/tag" in cmdString: logging.error( "Returning single tag" ) return { "tag": "v1-03-19", "sha": "MyTagSha01", "url": "http://localhost/foo/bar/baz", "message": "initial version", "tagger": { "name": "Foo Bar", "email": "*****@*****.**", "date": "2014-11-07T22:01:45Z" }, "object": { "type": "commit", "sha": "myCommitSha1", "url": "https://foo.org/git/commits/myCommitSha1" } } if "/git/commits/" in cmdString: logging.error( "Returning single commit" ) return { "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "author": { "date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "*****@*****.**" }, "committer": { "date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "*****@*****.**" }, "message": "added readme, because im a good github citizen", "tree": { "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "myCommitSha" }, "parents": [ { "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5" } ] } if "/branches" in cmdString: return { "name": "master", "commit": { "sha": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "commit": { "author": { "name": "The Octocat", "date": "2012-03-06T15:06:50-08:00", "email": "*****@*****.**" }, "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.", "tree": { "sha": "b4eecafa9be2f2006ce1b709d6857b07069b4608", "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608" }, "committer": { "name": "The Octocat", "date": "2012-03-06T15:06:50-08:00", "email": "*****@*****.**" } }, "author": { "gravatar_id": "", "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", "url": "https://api.github.com/users/octocat", "id": 583231, "login": "******" }, "parents": [ { "sha": "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e", "url": "https://api.github.com/repos/octocat/Hello-World/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e" }, { "sha": "762941318ee16e59dabbacb1b4049eec22f0d303", "url": "https://api.github.com/repos/octocat/Hello-World/commits/762941318ee16e59dabbacb1b4049eec22f0d303" } ], "url": "https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "committer": { "gravatar_id": "", "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", "url": "https://api.github.com/users/octocat", "id": 583231, "login": "******" } }, "_links": { "html": "https://github.com/octocat/Hello-World/tree/master", "self": "https://api.github.com/repos/octocat/Hello-World/branches/master" }, "protected": True, "protection_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection" } if "pulls/12/commits" in cmdString: return [ {'commit':{'author': {'name':'User Name2'}}}, {'commit':{'author': {'name':'User Name2'}}} ] if 'rate_limit' in cmdString: return {'rate':{'remaining':444, 'limit':555} } ##default return {}
def test_getCommands_list( self ): t1 = [ [[1, 2], 3], 4, 5, [6, 7] ] self.assertEqual( getCommands(*t1), [1, 2, 3, 4, 5, 6, 7] )
def test_getCommands_tuple( self ): t1 = [(1, 2), 3 ] self.assertEqual( getCommands(*t1), [1, 2, 3] )
def mockCurl(*args, **kwargs): """ mock the curl2Json calls in the gitinterface """ logging.error("\nArgs: %r", args) logging.error("\nArgs: %r", getCommands(args)) logging.error("Kwargs: %r", kwargs) cmdString = " ".join(getCommands(args)) cmdString += str(kwargs) logging.error("ComdString: %s", cmdString) if "/tags" in cmdString: logging.error("Returning tags structure") return [{ "name": "v01-03-19", "commit": { "sha": "MyTagSha2", "url": "http://localhost/foo/bar" }, "zipball_url": "zipball/v0.1", "tarball_url": "tarball/v0.1" }] if "/tag" in cmdString: logging.error("Returning single tag") return { "tag": "v1-03-19", "sha": "MyTagSha01", "url": "http://localhost/foo/bar/baz", "message": "initial version", "tagger": { "name": "Foo Bar", "email": "*****@*****.**", "date": "2014-11-07T22:01:45Z" }, "object": { "type": "commit", "sha": "myCommitSha1", "url": "https://foo.org/git/commits/myCommitSha1" } } if "/git/commits/" in cmdString: logging.error("Returning single commit") return { "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "author": { "date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "*****@*****.**" }, "committer": { "date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "*****@*****.**" }, "message": "added readme, because im a good github citizen", "tree": { "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "myCommitSha" }, "parents": [{ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5" }] } if "/branches" in cmdString: return { "name": "master", "commit": { "sha": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "commit": { "author": { "name": "The Octocat", "date": "2012-03-06T15:06:50-08:00", "email": "*****@*****.**" }, "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.", "tree": { "sha": "b4eecafa9be2f2006ce1b709d6857b07069b4608", "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608" }, "committer": { "name": "The Octocat", "date": "2012-03-06T15:06:50-08:00", "email": "*****@*****.**" } }, "author": { "gravatar_id": "", "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", "url": "https://api.github.com/users/octocat", "id": 583231, "login": "******" }, "parents": [{ "sha": "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e", "url": "https://api.github.com/repos/octocat/Hello-World/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e" }, { "sha": "762941318ee16e59dabbacb1b4049eec22f0d303", "url": "https://api.github.com/repos/octocat/Hello-World/commits/762941318ee16e59dabbacb1b4049eec22f0d303" }], "url": "https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", "committer": { "gravatar_id": "", "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", "url": "https://api.github.com/users/octocat", "id": 583231, "login": "******" } }, "_links": { "html": "https://github.com/octocat/Hello-World/tree/master", "self": "https://api.github.com/repos/octocat/Hello-World/branches/master" }, "protected": True, "protection_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection" } if "pulls/12/commits" in cmdString: return [{ 'commit': { 'author': { 'name': 'User Name2' } } }, { 'commit': { 'author': { 'name': 'User Name2' } } }] if 'rate_limit' in cmdString: return {'rate': {'remaining': 444, 'limit': 555}} ##default return {}
def test_getCommands_list(self): t1 = [[[1, 2], 3], 4, 5, [6, 7]] self.assertEqual(getCommands(*t1), [1, 2, 3, 4, 5, 6, 7])
def test_getCommands_tuple(self): t1 = [(1, 2), 3] self.assertEqual(getCommands(*t1), [1, 2, 3])