/ tests / DeploymentStatus.py
DeploymentStatus.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2020 Colby Gallup <colbygallup@gmail.com>                          #
 4  # Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de>                        #
 5  #                                                                              #
 6  # This file is part of PyGithub.                                               #
 7  # http://pygithub.readthedocs.io/                                              #
 8  #                                                                              #
 9  # PyGithub is free software: you can redistribute it and/or modify it under    #
10  # the terms of the GNU Lesser General Public License as published by the Free  #
11  # Software Foundation, either version 3 of the License, or (at your option)    #
12  # any later version.                                                           #
13  #                                                                              #
14  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
15  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
16  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
17  # details.                                                                     #
18  #                                                                              #
19  # You should have received a copy of the GNU Lesser General Public License     #
20  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
21  #                                                                              #
22  ################################################################################
23  
24  from datetime import datetime, timezone
25  
26  from . import Framework
27  
28  
29  class DeploymentStatus(Framework.TestCase):
30      def setUp(self):
31          super().setUp()
32          self.deployment = self.g.get_user().get_repo("PyGithub").get_deployment(263877258)
33          self.status = self.deployment.get_status(388454671)
34  
35      def testAttributes(self):
36          self.assertEqual(self.status.id, 388454671)
37          created_at = datetime(2020, 8, 26, 14, 32, 51, tzinfo=timezone.utc)
38          self.assertEqual(self.status.created_at, created_at)
39          self.assertEqual(self.status.creator.login, "jacquev6")
40          self.assertEqual(
41              self.status.deployment_url,
42              "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258",
43          )
44          self.assertEqual(self.status.description, "Deployment queued")
45          self.assertEqual(self.status.environment, "test")
46          self.assertEqual(self.status.environment_url, "https://example.com/environment")
47          self.assertEqual(
48              self.status.repository_url,
49              "https://api.github.com/repos/jacquev6/PyGithub",
50          )
51          self.assertEqual(self.status.state, "queued")
52          self.assertEqual(self.status.target_url, "https://example.com/deployment.log")
53          self.assertEqual(self.status.updated_at, created_at)
54          self.assertEqual(
55              self.status.url,
56              "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses/388454671",
57          )
58          self.assertEqual(
59              self.status.node_id,
60              "MDE2OkRlcGxveW1lbnRTdGF0dXMzODg0NTQ2NzE=",
61          )
62          self.assertEqual(
63              repr(self.status),
64              'DeploymentStatus(url="https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses/388454671", id=388454671)',
65          )
66  
67      def testCreate(self):
68          newStatus = self.deployment.create_status(
69              "queued",
70              target_url="https://example.com/deployment.log",
71              description="Deployment queued",
72              environment="test",
73              environment_url="https://example.com/environment",
74              auto_inactive=True,
75          )
76          self.assertEqual(newStatus.id, 388454671)
77          self.assertEqual(newStatus.state, "queued")
78          self.assertEqual(
79              newStatus.repository_url,
80              "https://api.github.com/repos/jacquev6/PyGithub",
81          )
82  
83      def testGetStatuses(self):
84          statuses = self.deployment.get_statuses()
85          self.assertListKeyEqual(
86              statuses,
87              lambda s: s.id,
88              [388454671, 388433743, 388432880],
89          )