Labels API: support description (#738)

The description attribute handling requirement is
  a custom media type in the Accept header:
    application/vnd.github.symmetra-preview+json

Limitation: Repository.get_labels does not report description,
possibly something has changed in the preview API.
This commit is contained in:
Mateusz Loskot
2018-03-29 18:16:20 +08:00
committed by Wan Liuyang
parent 6bf2acc74d
commit 42e7593871
7 changed files with 37 additions and 13 deletions
+3 -1
View File
@@ -39,14 +39,16 @@ class Label(Framework.TestCase):
def testAttributes(self):
self.assertEqual(self.label.color, "e10c02")
self.assertEqual(self.label.name, "Bug")
self.assertIsNone(self.label.description)
self.assertEqual(self.label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Bug")
# test __repr__() based on this attributes
self.assertEqual(self.label.__repr__(), 'Label(name="Bug")')
def testEdit(self):
self.label.edit("LabelEditedByPyGithub", "0000ff")
self.label.edit("LabelEditedByPyGithub", "0000ff", "Description of LabelEditedByPyGithub")
self.assertEqual(self.label.color, "0000ff")
self.assertEqual(self.label.description, "Description of LabelEditedByPyGithub")
self.assertEqual(self.label.name, "LabelEditedByPyGithub")
self.assertEqual(self.label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub")
@@ -3,7 +3,7 @@ POST
api.github.com
None
/repos/jacquev6/PyGithub/labels
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.symmetra-preview+json'}
{"color": "ffff00", "name": "Label with spaces and strange characters (&*#$)"}
201
[('status', '201 Created'), ('content-length', '197'), ('etag', '"99cbb3bf0f7ee7d6278c2ddd3ef42577"'), ('x-ratelimit-remaining', '4968'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+spaces+and+strange+characters+%28%26%2A%23%24%29'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Thu, 28 Jun 2012 19:29:52 GMT'), ('content-type', 'application/json; charset=utf-8')]
+3 -3
View File
@@ -3,9 +3,9 @@ PATCH
api.github.com
None
/repos/jacquev6/PyGithub/labels/Bug
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"color": "0000ff", "name": "LabelEditedByPyGithub"}
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.symmetra-preview+json'}
{"color": "0000ff", "name": "LabelEditedByPyGithub", "description": "Description of LabelEditedByPyGithub"}
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4965'), ('content-length', '133'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"57435796bd4f14b84ad92105669cfab1"'), ('date', 'Sat, 19 May 2012 10:17:44 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub","name":"LabelEditedByPyGithub","color":"0000ff"}
{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub","name":"LabelEditedByPyGithub","color":"0000ff","description":"Description of LabelEditedByPyGithub"}
@@ -3,9 +3,9 @@ POST
api.github.com
None
/repos/jacquev6/PyGithub/labels
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"color": "00ff00", "name": "Label with silly name % * + created by PyGithub"}
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.symmetra-preview+json'}
{"color": "00ff00", "name": "Label with silly name % * + created by PyGithub", "description": "Description of label with silly name"}
201
[('status', '201 Created'), ('x-ratelimit-remaining', '4969'), ('content-length', '191'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"92b623552b1bac3f019d03c920305acd"'), ('date', 'Sat, 19 May 2012 10:17:36 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub')]
{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub","name":"Label with silly name % * + created by PyGithub","color":"00ff00"}
{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub","name":"Label with silly name % * + created by PyGithub","color":"00ff00","description":"Description of label with silly name"}
+2 -1
View File
@@ -226,8 +226,9 @@ class Repository(Framework.TestCase):
self.assertEqual(issue.number, 30)
def testCreateLabel(self):
label = self.repo.create_label("Label with silly name % * + created by PyGithub", "00ff00")
label = self.repo.create_label("Label with silly name % * + created by PyGithub", "00ff00", "Description of label with silly name")
self.assertEqual(label.color, "00ff00")
self.assertEqual(label.description, "Description of label with silly name")
self.assertEqual(label.name, "Label with silly name % * + created by PyGithub")
self.assertEqual(label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub")