Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 9277b9f

Browse files
committed
#21 Create licenses
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent d84e46d commit 9277b9f

3 files changed

Lines changed: 109 additions & 0 deletions

File tree

bintray/bintray.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,45 @@ def download_content(self, subject, repo, remote_file_path, local_file_path):
107107

108108
# Licenses
109109

110+
def get_org_proprietary_licenses(self, org):
111+
""" Get a list of custom, proprietary licenses associated with an organization
112+
113+
:param org: Organization name
114+
:return: Licenses list
115+
"""
116+
url = "{}/orgs/{}/licenses".format(Bintray.BINTRAY_URL, org)
117+
return self._requester.get(url)
118+
119+
def get_user_proprietary_licenses(self, user):
120+
""" Get a list of custom, proprietary licenses associated with an user
121+
122+
:param user: User name
123+
:return: Licenses list
124+
"""
125+
url = "{}/users/{}/licenses".format(Bintray.BINTRAY_URL, user)
126+
return self._requester.get(url)
127+
128+
def create_org_proprietary_license(self, org, license):
129+
""" Create a license associated with an organization.
130+
Caller must be an admin of the organization.
131+
132+
:param org: Organization name
133+
:param license: JSON data with license information
134+
:return: request answer
135+
"""
136+
url = "{}/orgs/{}/licenses".format(Bintray.BINTRAY_URL, org)
137+
return self._requester.post(url, json=license)
138+
139+
def create_user_proprietary_license(self, user, license):
140+
""" Create a license associated with an user.
141+
142+
:param user: User name
143+
:param license: JSON data with license information
144+
:return: request answer
145+
"""
146+
url = "{}/users/{}/licenses".format(Bintray.BINTRAY_URL, user)
147+
return self._requester.post(url, json=license)
148+
110149
def get_oss_licenses(self):
111150
""" Returns a list of all the OSS licenses.
112151

bintray/requester.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,29 @@ def put(self, url, params=None, data=None):
7878
if not response.ok:
7979
self._raise_error("Could not PUT", response)
8080
return self._add_status_code(response)
81+
82+
def post(self, url, json=None, params=None):
83+
""" Forward POST method
84+
85+
:param url: URL address
86+
:param params: URL parameters
87+
:param json: Data to be posted
88+
:return: Request response
89+
"""
90+
response = requests.post(url, auth=self._get_authentication(), json=json, params=params)
91+
if not response.ok:
92+
self._raise_error("Could not POST", response)
93+
return self._add_status_code(response)
94+
95+
def patch(self, url, json=None, params=None):
96+
""" Forward PATCH method
97+
98+
:param url: URL address
99+
:param params: URL parameters
100+
:param json: Data to be patched
101+
:return: Request response
102+
"""
103+
response = requests.post(url, auth=self._get_authentication(), json=json, params=params)
104+
if not response.ok:
105+
self._raise_error("Could not PATCH", response)
106+
return self._add_status_code(response)

tests/test_licenses.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ def test_get_oss_licenses():
1010
assert copyfree in licenses
1111

1212

13+
def test_get_org_proprietary_licenses():
14+
bintray = Bintray()
15+
error_message = ""
16+
try:
17+
bintray.get_org_proprietary_licenses(org="jfrog")
18+
except Exception as error:
19+
error_message = str(error)
20+
assert "Could not GET (403): 403 Client Error: Forbidden for url: " \
21+
"https://api.bintray.com/orgs/jfrog/licenses" == error_message
22+
23+
24+
def test_get_user_proprietary_licenses():
25+
bintray = Bintray()
26+
error_message = ""
27+
try:
28+
bintray.get_user_proprietary_licenses(user="uilianries")
29+
except Exception as error:
30+
error_message = str(error)
31+
assert "Could not GET (400): 400 Client Error: Bad Request for url: " \
32+
"https://api.bintray.com/users/uilianries/licenses" == error_message
33+
34+
1335
def test_bad_credentials_for_get_oss_licenses():
1436
bintray = Bintray("foobar", "85abc6aece02515e8bd87b9754a18af697527d88")
1537
error_message = ""
@@ -19,3 +41,25 @@ def test_bad_credentials_for_get_oss_licenses():
1941
error_message = str(error)
2042
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
2143
"https://api.bintray.com/licenses/oss_licenses" == error_message
44+
45+
46+
def test_create_org_proprietary_licenses():
47+
bintray = Bintray()
48+
error_message = ""
49+
try:
50+
bintray.create_org_proprietary_license(org="jfrog", license=[{}])
51+
except Exception as error:
52+
error_message = str(error)
53+
assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
54+
"https://api.bintray.com/orgs/jfrog/licenses" == error_message
55+
56+
57+
def test_create_user_proprietary_licenses():
58+
bintray = Bintray()
59+
error_message = ""
60+
try:
61+
bintray.create_user_proprietary_license(user="uilianries", license=[{}])
62+
except Exception as error:
63+
error_message = str(error)
64+
assert "Could not POST (400): 400 Client Error: Bad Request for url: " \
65+
"https://api.bintray.com/users/uilianries/licenses" == error_message

0 commit comments

Comments
 (0)