/ tests / PullRequestReview.py
PullRequestReview.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2017 Aaron Levine <allevin@sandia.gov>                             #
 4  # Copyright 2017 Mike Miller <github@mikeage.net>                              #
 5  # Copyright 2017 Simon <spam@esemi.ru>                                         #
 6  # Copyright 2018 Gilad Shefer <gshefer@redhat.com>                             #
 7  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 8  #                                                                              #
 9  # This file is part of PyGithub.                                               #
10  # http://pygithub.readthedocs.io/                                              #
11  #                                                                              #
12  # PyGithub is free software: you can redistribute it and/or modify it under    #
13  # the terms of the GNU Lesser General Public License as published by the Free  #
14  # Software Foundation, either version 3 of the License, or (at your option)    #
15  # any later version.                                                           #
16  #                                                                              #
17  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
18  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
19  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
20  # details.                                                                     #
21  #                                                                              #
22  # You should have received a copy of the GNU Lesser General Public License     #
23  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
24  #                                                                              #
25  ################################################################################
26  
27  from datetime import datetime, timezone
28  
29  from . import Framework
30  
31  
32  class PullRequestReview(Framework.TestCase):
33      def setUp(self):
34          super().setUp()
35  
36          self.repo = self.g.get_repo("PyGithub/PyGithub", lazy=True)
37          self.pull = self.repo.get_pull(538)
38  
39          # Test ability to create a review
40          self.created_pullreview = self.pull.create_review(
41              self.repo.get_commit("2f0e4e55fe87e38d26efc9aa1346f56abfbd6c52"),
42              "Some review created by PyGithub",
43          )
44  
45          # Test ability to get all reviews
46          self.pullreviews = self.pull.get_reviews()
47  
48          # Test ability to get a single review
49          self.pullreview = self.pull.get_review(28482091)
50  
51      def testDoesNotModifyPullRequest(self):
52          self.assertEqual(self.pull.id, 111649703)
53  
54      def testDismiss(self):
55          self.pullreview.dismiss("with prejudice")
56          pr = self.pull.get_review(28482091)
57          self.assertEqual(pr.state, "DISMISSED")
58  
59      def testAttributes(self):
60          self.assertEqual(self.pullreview.id, 28482091)
61          self.assertEqual(self.pullreview.user.login, "jzelinskie")
62          self.assertEqual(self.pullreview.body, "")
63          self.assertEqual(self.pullreview.commit_id, "7a0fcb27b7cd6c346fc3f76216ccb6e0f4ca3bcc")
64          self.assertEqual(self.pullreview.state, "APPROVED")
65          self.assertEqual(
66              self.pullreview.html_url,
67              "https://github.com/PyGithub/PyGithub/pull/538#pullrequestreview-28482091",
68          )
69          self.assertEqual(
70              self.pullreview.pull_request_url,
71              "https://api.github.com/repos/PyGithub/PyGithub/pulls/538",
72          )
73          self.assertEqual(
74              self.pullreview.submitted_at,
75              datetime(2017, 3, 22, 19, 6, 59, tzinfo=timezone.utc),
76          )
77          self.assertIn(self.created_pullreview.id, [r.id for r in self.pullreviews])
78          self.assertEqual(
79              repr(self.pullreview),
80              'PullRequestReview(user=NamedUser(login="jzelinskie"), id=28482091)',
81          )