Files
PyGithub/github/tests/GitRelease.py
T
Ggicci aca50a7581 Change type of GitRelease.author to NamedUser (#969)
Github's release object in the API response contains an `author` field having a value much more like a `NamedUser` but not `GitAuthor`.

e.g. https://api.github.com/repos/edhollandAL/PyGithub/releases/1210902

```
{
  "id": 1210902,
  "author": {
    "login": "edhollandAL",
    "id": 11922660,
    "node_id": "MDQ6VXNlcjExOTIyNjYw",
    "avatar_url": "https://avatars1.githubusercontent.com/u/11922660?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/edhollandAL",
    "html_url": "https://github.com/edhollandAL",
    "followers_url": "https://api.github.com/users/edhollandAL/followers",
    "following_url": "https://api.github.com/users/edhollandAL/following{/other_user}",
    "gists_url": "https://api.github.com/users/edhollandAL/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/edhollandAL/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/edhollandAL/subscriptions",
    "organizations_url": "https://api.github.com/users/edhollandAL/orgs",
    "repos_url": "https://api.github.com/users/edhollandAL/repos",
    "events_url": "https://api.github.com/users/edhollandAL/events{/privacy}",
    "received_events_url": "https://api.github.com/users/edhollandAL/received_events",
    "type": "User",
    "site_admin": false
  },
  // (ignored)
}
```
2018-11-25 09:56:38 +08:00

153 lines
7.8 KiB
Python

# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2015 Ed Holland <eholland@alertlogic.com> #
# Copyright 2016 Benjamin Whitney <benjamin.whitney@ironnetcybersecurity.com> #
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
# Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> #
# Copyright 2017 Simon <spam@esemi.ru> #
# Copyright 2018 Andrew Smith <espadav8@gmail.com> #
# Copyright 2018 Daniel Kesler <kesler.daniel@gmail.com> #
# Copyright 2018 Kuba <jakub.glapa@adspired.com> #
# Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com> #
# Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> #
# Copyright 2018 edquist <edquist@users.noreply.github.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
import os
import zipfile
import datetime
import Framework
from pprint import pprint
class Release(Framework.TestCase):
def setUp(self):
Framework.TestCase.setUp(self)
# Do not get self.release here as it casues bad data to be saved in --record mode
self.content_path = "content.txt"
self.artifact_path = "archive.zip"
with open(self.content_path, "w") as zip_content:
zip_content.write("Pedro for president.")
artifact = zipfile.ZipFile(self.artifact_path, "w")
artifact.write(self.content_path)
artifact.close()
def tearDown(self):
if os.path.exists(self.content_path):
os.remove(self.content_path)
if os.path.exists(self.artifact_path):
os.remove(self.artifact_path)
def testAttributes(self):
self.release = self.g.get_user().get_repo("PyGithub").get_releases()[0]
self.assertEqual(self.release.id, 1210814)
self.assertEqual(self.release.tag_name, "v1.25.2")
self.assertEqual(self.release.target_commitish, "master")
self.assertEqual(self.release.upload_url, "https://uploads.github.com/repos/edhollandAL/PyGithub/releases/1210814/assets{?name}")
self.assertEqual(self.release.body, "Body")
self.assertEqual(self.release.title, "Test")
self.assertEqual(self.release.draft, False)
self.assertEqual(self.release.prerelease, False)
self.assertEqual(self.release.url, "https://api.github.com/repos/edhollandAL/PyGithub/releases/1210814")
self.assertEqual(self.release.author._rawData['login'], "edhollandAL")
self.assertEqual(self.release.author.login, "edhollandAL")
self.assertEqual(self.release.author.id, 11922660)
self.assertEqual(self.release.author.type, "User")
self.assertEqual(self.release.html_url, "https://github.com/edhollandAL/PyGithub/releases/tag/v1.25.2")
self.assertEqual(self.release.created_at, datetime.datetime(2014, 10, 8, 1, 54))
self.assertEqual(self.release.published_at, datetime.datetime(2015, 4, 24, 8, 36, 51))
self.assertEqual(self.release.tarball_url, "https://api.github.com/repos/edhollandAL/PyGithub/tarball/v1.25.2")
self.assertEqual(self.release.zipball_url, "https://api.github.com/repos/edhollandAL/PyGithub/zipball/v1.25.2")
# test __repr__() based on this attributes
self.assertEqual(self.release.__repr__(), 'GitRelease(title="Test")')
def testDelete(self):
self.release = self.g.get_user().get_repo("PyGithub").get_releases()[0]
self.release.delete_release()
def testUpdate(self):
self.release = self.g.get_user().get_repo("PyGithub").get_releases()[0]
new_release = self.release.update_release("Updated Test", "Updated Body")
self.assertEqual(new_release.body, "Updated Body")
self.assertEqual(new_release.title, "Updated Test")
def testGetRelease(self):
release_by_id = self.g.get_user().get_repo("PyGithub").get_release('v1.25.2')
release_by_tag = self.g.get_user().get_repo("PyGithub").get_release(1210837)
self.assertEqual(release_by_id, release_by_tag)
def testCreateGitTagAndRelease(self):
self.repo = self.g.get_user().get_repo("PyGithub")
self.release = self.repo.create_git_tag_and_release('v3.0.0', 'tag message', 'release title', 'release message', '5a05a5e58f682d315acd2447c87ac5b4d4fc55e8', 'commit')
self.assertEqual(self.release.tag_name, "v3.0.0")
self.assertEqual(self.release.body, "release message")
self.assertEqual(self.release.title, "release title")
self.assertEqual(self.release.author._rawData['login'], "edhollandAL")
self.assertEqual(self.release.html_url, "https://github.com/edhollandAL/PyGithub/releases/tag/v3.0.0")
def testGetLatestRelease(self):
self.repo = self.g.get_user().get_repo('PyGithub')
latest_release = self.repo.get_latest_release()
self.assertEqual(latest_release.tag_name, "v1.25.2")
def testGetAsset(self):
"""
Test retrieving a release asset directly by its ID.
"""
the_repo = self.g.get_user().get_repo("PyGithub")
asset_id = 16
the_asset = the_repo.get_release_asset(asset_id)
self.assertTrue(the_asset is not None)
self.assertEqual(the_asset.id, asset_id)
def testGetAssets(self):
"""
Test retrieving the set of assets for the current release.
"""
release_id = 1210837
the_repo = self.g.get_user().get_repo("PyGithub")
the_release = the_repo.get_release(release_id)
self.assertEqual(the_release.id, release_id)
asset_list = [x for x in the_release.get_assets()]
self.assertTrue(asset_list is not None)
self.assertEqual(len(asset_list), 1)
def testUploadAsset(self):
"""
Test uploading a new asset to the release.
"""
release_id = 1210837
the_repo = self.g.get_user().get_repo("PyGithub")
the_release = the_repo.get_release(release_id)
self.assertEqual(the_release.id, release_id)
the_release.upload_asset(self.artifact_path,
"unit test artifact",
"application/zip")