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

Commit

Permalink
#5 Fix license tests
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Jul 13, 2019
1 parent 5b81a26 commit 2566deb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
67 changes: 50 additions & 17 deletions bintray/bintray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
https://bintray.com/docs/api
"""
import json
import os

from bintray.requester import Requester
Expand Down Expand Up @@ -442,49 +443,81 @@ def get_user_proprietary_licenses(self, user):
url = "{}/users/{}/licenses".format(Bintray.BINTRAY_URL, user)
return self._requester.get(url)

def create_org_proprietary_license(self, org, license):
def create_org_proprietary_license(self, org, name, description, url):
""" Create a license associated with an organization.
Caller must be an admin of the organization.
:param org: Organization name
:param license: JSON data with license information
:param name: license name
:param description: license description
:param url: license url
:return: request answer
"""
url = "{}/orgs/{}/licenses".format(Bintray.BINTRAY_URL, org)
return self._requester.post(url, json=license)
url_request = "{}/orgs/{}/licenses".format(Bintray.BINTRAY_URL, org)
json_data = {
'name': name,
'description': description,
'url': url
}
return self._requester.post(url_request, json=json_data)

def create_user_proprietary_license(self, user, license):
def create_user_proprietary_license(self, user, name, description, url):
""" Create a license associated with an user.
:param user: User name
:param license: JSON data with license information
:return: request answer
:param name: license name
:param description: license description
:param url: license url
:return: request response
"""
url = "{}/users/{}/licenses".format(Bintray.BINTRAY_URL, user)
return self._requester.post(url, json=license)
url_request = "{}/users/{}/licenses".format(Bintray.BINTRAY_URL, user)
json_data = {
'name': name,
'description': description,
'url': url
}
return self._requester.post(url_request, json=json_data)

def update_org_proprietary_license(self, org, custom_license_name, license):
def update_org_proprietary_license(self, org, custom_license_name, description=None, url=None):
""" Update a license associated with an organization.
Caller must be an admin of the organization.
:param org: Organization name
:param custom_license_name: License to be updated
:param license: JSON data with license information
:param description: license description
:param url: license url
:return: request answer
"""
url = "{}/orgs/{}/licenses/{}".format(Bintray.BINTRAY_URL, org, custom_license_name)
return self._requester.patch(url, json=license)
request_url = "{}/orgs/{}/licenses/{}".format(Bintray.BINTRAY_URL, org, custom_license_name)
json_data = {}
if isinstance(description, str):
json_data["description"] = description
if isinstance(url, str):
json_data["url"] = url
return self._requester.patch(request_url, json=json_data)

def update_user_proprietary_license(self, user, custom_license_name, license):
def update_user_proprietary_license(self, user, custom_license_name, description=None,
url=None):
""" Update a license associated with an user.
:param user: User name
:param custom_license_name: License to be updated
:param license: JSON data with license information
:param description: license description
:param url: license url
:return: request answer
"""
url = "{}/users/{}/licenses/{}".format(Bintray.BINTRAY_URL, user, custom_license_name)
return self._requester.patch(url, json=license)
request_url = "{}/users/{}/licenses/{}".format(Bintray.BINTRAY_URL, user,
custom_license_name)
json_data = {}
if isinstance(description, str):
json_data["description"] = description
if isinstance(url, str):
json_data["url"] = url

if not json_data:
raise ValueError("At lease one parameter must be filled.")

return self._requester.patch(request_url, json=json_data)

def delete_org_proprietary_license(self, org, custom_license_name):
""" Delete a license associated with an organization.
Expand Down
23 changes: 14 additions & 9 deletions tests/test_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def test_create_org_proprietary_licenses():
bintray = Bintray()
error_message = ""
try:
bintray.create_org_proprietary_license(org="jfrog", license=[{}])
bintray.create_org_proprietary_license(org="jfrog", name='foobar', description='foo',
url='https://opensource.org/licenses/MIT')
except Exception as error:
error_message = str(error)
assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
Expand All @@ -58,19 +59,21 @@ def test_create_user_proprietary_licenses():
bintray = Bintray()
error_message = ""
try:
bintray.create_user_proprietary_license(user="uilianries", license=[{}])
bintray.create_user_proprietary_license(user="uilianries", name='foobar', description='foo',
url='https://opensource.org/licenses/MIT')
except Exception as error:
error_message = str(error)
assert "Could not PATCH (405): 405 Client Error: Method Not Allowed for url: " \
"https://api.bintray.com/users/uilianries/licenses/foobar" == error_message
assert "Could not POST (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses" == error_message


def test_update_org_proprietary_licenses():
bintray = Bintray()
error_message = ""
try:
bintray.update_org_proprietary_license(org="jfrog", custom_license_name="foobar",
license=[{}])
description="MIT license",
url="https://opensource.org/licenses/MIT")
except Exception as error:
error_message = str(error)

Expand All @@ -82,13 +85,15 @@ def test_update_user_proprietary_licenses():
bintray = Bintray()
error_message = ""
try:
bintray.update_user_proprietary_license(user="uilianries", custom_license_name="foobar",
license=[{}])
bintray.update_user_proprietary_license(user="uilianries",
custom_license_name="foo",
description="MIT license",
url="https://opensource.org/licenses/MIT")
except Exception as error:
error_message = str(error)

assert "Could not PATCH (405): 405 Client Error: Method Not Allowed for url: " \
"https://api.bintray.com/users/uilianries/licenses/foobar" == error_message
assert "Could not PATCH (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses/foo" == error_message


def test_delete_org_proprietary_licenses():
Expand Down

0 comments on commit 2566deb

Please sign in to comment.