/ tests / ReleaseAsset.py
ReleaseAsset.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com>        #
 4  # Copyright 2017 Simon <spam@esemi.ru>                                         #
 5  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 6  #                                                                              #
 7  # This file is part of PyGithub.                                               #
 8  # http://pygithub.readthedocs.io/                                              #
 9  #                                                                              #
10  # PyGithub is free software: you can redistribute it and/or modify it under    #
11  # the terms of the GNU Lesser General Public License as published by the Free  #
12  # Software Foundation, either version 3 of the License, or (at your option)    #
13  # any later version.                                                           #
14  #                                                                              #
15  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
16  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
17  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
18  # details.                                                                     #
19  #                                                                              #
20  # You should have received a copy of the GNU Lesser General Public License     #
21  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
22  #                                                                              #
23  ################################################################################
24  
25  from datetime import datetime, timezone
26  
27  from . import Framework
28  
29  
30  class ReleaseAsset(Framework.TestCase):
31      def setUp(self):
32          super().setUp()
33          self.release = self.g.get_user().get_repo("PyGithub").get_releases()[0]
34          self.asset = self.release.get_assets()[0]
35  
36      def testAttributes(self):
37          self.assertEqual(self.release.id, 1210814)
38          self.assertEqual(self.asset.id, 16)
39          self.assertEqual(
40              self.asset.url,
41              "https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16",
42          )
43          self.assertEqual(self.asset.name, "Archive.zip")
44          self.assertEqual(self.asset.label, "Installation msi & runbook zipped")
45          self.assertEqual(self.asset.content_type, "application/zip")
46          self.assertEqual(self.asset.state, "uploaded")
47          self.assertEqual(self.asset.size, 3783)
48          self.assertEqual(self.asset.download_count, 2)
49          self.assertEqual(
50              self.asset.created_at,
51              datetime(2017, 2, 1, 22, 40, 58, tzinfo=timezone.utc),
52          )
53          self.assertEqual(
54              self.asset.updated_at,
55              datetime(2017, 2, 1, 22, 44, 58, tzinfo=timezone.utc),
56          )
57          self.assertEqual(
58              self.asset.browser_download_url,
59              "https://github.com/edhollandAL/PyGithub/releases/download/v1.25.2/Asset.zip",
60          )
61          self.assertEqual(self.asset.uploader.login, "PyGithub")
62          self.assertEqual(
63              repr(self.asset),
64              'GitReleaseAsset(url="https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16")',
65          )
66  
67      def testDelete(self):
68          self.assertTrue(self.asset.delete_asset())
69  
70      def testUpdate(self):
71          new_name = "updated-name.zip"
72          new_label = "Updated label"
73          updated_asset = self.asset.update_asset(new_name, new_label)
74          self.assertEqual(updated_asset.name, new_name)
75          self.assertNotEqual(self.asset.name, updated_asset.name)
76          self.assertEqual(updated_asset.label, new_label)
77          self.assertNotEqual(self.asset.label, updated_asset.label)