Commit.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # 4 # Copyright 2012 Zearin <zearin@gonk.net> # 5 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # 6 # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # 7 # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # 8 # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # 9 # Copyright 2017 Wan Liuyang <tsfdye@gmail.com> # 10 # Copyright 2018 sfdye <tsfdye@gmail.com> # 11 # # 12 # This file is part of PyGithub. # 13 # http://pygithub.readthedocs.io/ # 14 # # 15 # PyGithub is free software: you can redistribute it and/or modify it under # 16 # the terms of the GNU Lesser General Public License as published by the Free # 17 # Software Foundation, either version 3 of the License, or (at your option) # 18 # any later version. # 19 # # 20 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 22 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 23 # details. # 24 # # 25 # You should have received a copy of the GNU Lesser General Public License # 26 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 27 # # 28 ################################################################################ 29 30 from . import Framework 31 32 33 class Commit(Framework.TestCase): 34 def setUp(self): 35 super().setUp() 36 self.commit = self.g.get_user().get_repo("PyGithub").get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") 37 self.commit.author.login # to force lazy completion 38 39 def testAttributes(self): 40 self.assertEqual(self.commit.author.login, "jacquev6") 41 self.assertEqual( 42 self.commit.commit.url, 43 "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", 44 ) 45 self.assertEqual(self.commit.committer.login, "jacquev6") 46 self.assertEqual(len(self.commit.files), 1) 47 self.assertEqual(self.commit.files[0].additions, 0) 48 self.assertEqual( 49 self.commit.files[0].blob_url, 50 "https://github.com/jacquev6/PyGithub/blob/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", 51 ) 52 self.assertEqual(self.commit.files[0].changes, 20) 53 self.assertEqual(self.commit.files[0].deletions, 20) 54 self.assertEqual(self.commit.files[0].filename, "github/GithubObjects/GitAuthor.py") 55 self.assertTrue(isinstance(self.commit.files[0].patch, str)) 56 self.assertEqual( 57 self.commit.files[0].raw_url, 58 "https://github.com/jacquev6/PyGithub/raw/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", 59 ) 60 self.assertEqual(self.commit.files[0].sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") 61 self.assertEqual(self.commit.files[0].status, "modified") 62 self.assertEqual(len(self.commit.parents), 1) 63 self.assertEqual(self.commit.parents[0].sha, "b46ed0dfde5ad02d3b91eb54a41c5ed960710eae") 64 self.assertEqual(self.commit.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") 65 self.assertEqual(self.commit.stats.deletions, 20) 66 self.assertEqual(self.commit.stats.additions, 0) 67 self.assertEqual(self.commit.stats.total, 20) 68 self.assertEqual( 69 self.commit.url, 70 "https://api.github.com/repos/jacquev6/PyGithub/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", 71 ) 72 self.assertEqual(self.commit.commit.tree.sha, "4c6bd50994f0f9823f898b1c6c964ad7d4fa11ab") 73 self.assertEqual( 74 repr(self.commit), 75 'Commit(sha="1292bf0e22c796e91cc3d6e24b544aece8c21f2a")', 76 ) 77 78 def testGetComments(self): 79 self.assertListKeyEqual( 80 self.commit.get_comments(), 81 lambda c: c.id, 82 [1347033, 1347083, 1347397, 1349654], 83 ) 84 85 def testCreateComment(self): 86 comment = self.commit.create_comment("Comment created by PyGithub") 87 self.assertEqual(comment.id, 1361949) 88 self.assertEqual(comment.line, None) 89 self.assertEqual(comment.path, None) 90 self.assertEqual(comment.position, None) 91 92 def testCreateCommentOnFileLine(self): 93 comment = self.commit.create_comment( 94 "Comment created by PyGithub", 95 path="codegen/templates/GithubObject.MethodBody.UseResult.py", 96 line=26, 97 ) 98 self.assertEqual(comment.id, 1362000) 99 self.assertEqual(comment.line, 26) 100 self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") 101 self.assertEqual(comment.position, None) 102 103 def testCreateCommentOnFilePosition(self): 104 comment = self.commit.create_comment( 105 "Comment also created by PyGithub", 106 path="codegen/templates/GithubObject.MethodBody.UseResult.py", 107 position=3, 108 ) 109 self.assertEqual(comment.id, 1362001) 110 self.assertEqual(comment.line, None) 111 self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") 112 self.assertEqual(comment.position, 3) 113 114 def testCreateStatusWithoutOptionalParameters(self): 115 status = self.commit.create_status("pending") 116 self.assertEqual(status.id, 277031) 117 self.assertEqual(status.state, "pending") 118 self.assertEqual(status.target_url, None) 119 self.assertEqual(status.description, None) 120 121 def testCreateStatusWithAllParameters(self): 122 status = self.commit.create_status( 123 "success", 124 "https://github.com/jacquev6/PyGithub/issues/67", 125 "Status successfuly created by PyGithub", 126 ) 127 self.assertEqual(status.id, 277040) 128 self.assertEqual(status.state, "success") 129 self.assertEqual(status.target_url, "https://github.com/jacquev6/PyGithub/issues/67") 130 self.assertEqual(status.description, "Status successfuly created by PyGithub") 131 132 def testGetPulls(self): 133 commit = self.g.get_user().get_repo("PyGithub").get_commit("e44d11d565c022496544dd6ed1f19a8d718c2b0c") 134 self.assertListKeyEqual(commit.get_pulls(), lambda c: c.number, [1431])