Skip to content

Commit

Permalink
Add / fix tests, accept list vs dict for replace_topics (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyardley committed Jul 5, 2018
1 parent 6d10f73 commit c5e8d74
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions github/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def teams_url(self):
@property
def topics(self):
"""
:type: list
:type: list
"""
self._completeIfNotSet(self._topics)
return self._topics.value
Expand Down Expand Up @@ -2452,11 +2452,14 @@ def replace_topics(self, topics):
:param topics: list of strings
:rtype: None
"""
post_parameters = {
'names': topics
}
headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/topics",
headers={'Accept': 'application/vnd.github.mercy-preview+json'},
input=topics
input=post_parameters
)

def remove_from_collaborators(self, collaborator):
Expand Down
2 changes: 1 addition & 1 deletion github/tests/ReplayData/Repository.testGetTopics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ https
GET
api.github.com
None
/repos/peterkline/PyGithub/topics
/repos/jacquev6/PyGithub/topics
{'Authorization': 'Basic login_and_password_removed', 'Accept': 'application/vnd.github.mercy-preview+json', 'User-Agent': 'PyGithub/Python'}
None
200
Expand Down
11 changes: 11 additions & 0 deletions github/tests/ReplayData/Repository.testReplaceTopics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
https
PUT
api.github.com
None
/repos/jacquev6/PyGithub/topics
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'Accept': 'application/vnd.github.mercy-preview+json', 'User-Agent': 'PyGithub/Python'}
{"names": ["github", "testing"]}
200
[('content-length', '30'), ('x-runtime-rack', '0.081855'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('etag', '"c34823528b2c41eadf247bcea3b7dabc"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('referrer-policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-github-media-type', 'github.mercy-preview; format=json'), ('access-control-expose-headers', 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', '4C20:5398:FE4A88:26DA323:5AD7F450'), ('date', 'Thu, 19 Apr 2018 01:43:45 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1524105758')]
{"names": ["testing","github"]}

2 changes: 2 additions & 0 deletions github/tests/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ def testGetTopics(self):
topic = u'github'
self.assertEquals(topic in topic_list, True)

def testReplaceTopics(self):
self.repo.replace_topics(['github', 'testing'])

class LazyRepository(Framework.TestCase):

Expand Down

0 comments on commit c5e8d74

Please sign in to comment.