8000 Added read_only parameter in create_key API · runt18/github3.py@79fbcf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79fbcf1

Browse files
Akasurdeitsmemattchung
authored andcommitted
Added read_only parameter in create_key API
Fixes Github issue 501 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
1 parent a9a20c
8000
1 commit 79fbcf1

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,5 @@ Contributors
118118
- Derek Gustafson (@degustaf)
119119

120120
- Christophe Lecointe (@christophelec)
121+
122+
- Abhijeet Kasurde (@akasurde)

github3/github.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
298298
return self._instance_or_null(Issue, None)
299299

300300
@requires_auth
301-
def create_key(self, title, key):
301+
def create_key(self, title, key, read_only=False):
302302
"""Create a new key for the authenticated user.
303303
304304
:param str title: (required), key title
@@ -309,8 +309,9 @@ def create_key(self, title, key):
309309
json = None
310310

311311
if title and key:
312+
data = {'title': title, 'key': key, 'read_only': read_only}
312313
url = self._build_url('user', 'keys')
313-
req = self._post(url, data={'title': title, 'key': key})
314+
req = self._post(url, data=data)
314315
json = self._json(req, 201)
315316
return self._instance_or_null(users.Key, json)
316317

github3/repos/repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def create_issue(self,
820820
return self._instance_or_null(Issue, json)
821821

822822
@requires_auth
823-
def create_key(self, title, key):
823+
def create_key(self, title, key, read_only=False):
824824
"""Create a deploy key.
825825
826826
:param str title: (required), title of key
@@ -829,7 +829,7 @@ def create_key(self, title, key):
829829
"""
830830
json = None
831831
if title and key:
832-
data = {'title': title, 'key': key}
832+
data = {'title': title, 'key': key, 'read_only': read_only}
833833
url = self._build_url('keys', base_url=self._api)
834834
json = self._json(self._post(url, data=data), 201)
835835
return self._instance_or_null(Key, json)

tests/unit/test_github.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,27 @@ def test_create_gist(self):
9696

9797
def test_create_key(self):
9898
"""Test the request to create a key."""
99-
self.instance.create_key('key_name', 'key text')
99+
self.instance.create_key('key_name', 'key text', read_only=False)
100100

101101
self.post_called_with(
102102
url_for('user/keys'),
103103
data={
104104
'title': 'key_name',
105-
'key': 'key text'
105+
'key': 'key text',
106+
'read_only': False
107+
}
108+
)
109+
110+
def test_create_key_with_readonly(self):
111+
""" Test the request to create a key with read only"""
112+
self.instance.create_key('key_name', 'key text', read_only=True)
113+
114+
self.post_called_with(
115+
url_for('user/keys'),
116+
data={
117+
'title': 'key_name',
118+
'key': 'key text',
119+
'read_only': True
106120
}
107121
)
108122

tests/unit/test_repos_repo.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,21 @@ def test_create_key(self):
144144
"""Verify the request to create a key."""
145145
data = {
146146
'title': 'octocat@octomac',
147-
'key': 'ssh-rsa AAA'
147+
'key': 'ssh-rsa AAA',
148+
'read_only': False
149+
}
150+
self.instance.create_key(**data)
151+
self.post_called_with(
152+
url_for('keys'),
153+
data=data
154+
)
155+
156+
def test_create_key_readonly(self):
157+
"""Verify the request to create a key with readonly true"""
158+
data = {
159+
'title': 'octocat@octomac',
160+
'key': 'ssh-rsa AAA',
161+
'read_only': True
148162
}
149163
self.instance.create_key(**data)
150164
self.post_called_with(

0 commit comments

Comments
 (0)
0