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

Commit 9045593

Browse files
committed
#21 Get OSS licenses
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 1b695ab commit 9045593

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

bintray/bintray.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def _add_status_code(self, response):
6363
json_data.update({"statusCode": response.status_code, "error": not response.ok})
6464
return json_data
6565

66-
6766
def _bool_to_number(self, value):
6867
""" Convert boolean result into numeric string
6968
@@ -153,3 +152,17 @@ def download_content(self, subject, repo, remote_file_path, local_file_path):
153152
local_fd.write(response.content)
154153
self._logger.info("Download successfully: {}".format(url))
155154
return self._add_status_code(response)
155+
156+
# Licenses
157+
158+
def get_oss_licenses(self):
159+
""" Returns a list of all the OSS licenses.
160+
161+
:return: List with OSS licenses
162+
"""
163+
url = "{}/licenses/oss_licenses".format(Bintray.BINTRAY_URL)
164+
response = requests.get(url, auth=self._get_authentication())
165+
if not response.ok:
166+
self._raise_error("Could not get OSS licenses", response)
167+
return self._add_status_code(response)
168+

tests/test_licenses.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from bintray.bintray import Bintray
5+
6+
7+
def test_get_oss_licenses():
8+
bintray = Bintray()
9+
licenses = bintray.get_oss_licenses()
10+
copyfree = {'name': 'Copyfree', 'longname': 'Copyfree', 'url': 'http://copyfree.org/'}
11+
assert copyfree in licenses
12+
13+
14+
def test_bad_credentials_for_get_oss_licenses():
15+
bintray = Bintray("foobar", "85abc6aece02515e8bd87b9754a18af697527d88")
16+
error_message = ""
17+
try:
18+
bintray.get_oss_licenses()
19+
except Exception as error:
20+
error_message = str(error)
21+
assert "Could not get OSS licenses (401): 401 Client Error: Unauthorized for url: " \
22+
"https://api.bintray.com/licenses/oss_licenses" == error_message

0 commit comments

Comments
 (0)