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

Commit

Permalink
#11 Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries committed Jul 10, 2019
1 parent a8044be commit 4c90f3f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bintray/bintray.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def delete_user_proprietary_license(self, user, custom_license_name):
:return: request answer
"""
url = "{}/users/{}/licenses/{}".format(Bintray.BINTRAY_URL, user, custom_license_name)
return self._requester.patch(url)
return self._requester.delete(url)

def get_oss_licenses(self):
""" Returns a list of all the OSS licenses.
Expand Down
35 changes: 14 additions & 21 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_bad_credentials_for_get_package_files():
error_message = str(error)
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
"https://api.bintray.com/packages/uilianries/generic/statistics/files?" \
"include_unpublished=False&include_unpublished=0" == error_message
"include_unpublished=0" == error_message


def test_get_version_files():
Expand All @@ -46,6 +46,7 @@ def test_get_version_files():
'size': 1967,
'version': '20190701'} in response


def test_bad_credentials_for_get_version_files():
bintray = Bintray("foobar", "85abc6aece02515e8bd87b9754a18af697527d88")
error_message = ""
Expand All @@ -55,12 +56,12 @@ def test_bad_credentials_for_get_version_files():
error_message = str(error)
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
"https://api.bintray.com/packages/uilianries/generic/statistics/versions" \
"/20190701/files?include_unpublished=False&include_unpublished=0" == error_message
"/20190701/files?include_unpublished=0" == error_message


def test_file_search_by_name():
bintray = Bintray()
response = bintray.file_search_by_name("statistics", subject="uilianries", repo="generic")
response = bintray.file_search_by_name("packages.json", subject="uilianries", repo="generic")
assert {'error': False, 'statusCode': 200} in response
assert {'created': '2019-07-01T20:51:42.879Z',
'name': 'packages.json',
Expand All @@ -78,47 +79,39 @@ def test_bad_credentials_file_search_by_name():
bintray = Bintray("foobar", "85abc6aece02515e8bd87b9754a18af697527d88")
error_message = ""
try:
bintray.file_search_by_name("statistics", subject="uilianries", repo="generic")
bintray.file_search_by_name("packages.json", subject="uilianries", repo="generic")
except Exception as error:
error_message = str(error)
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
"https://api.bintray.com/packages/uilianries/generic/statistics/versions" \
"/20190701/files?include_unpublished=False&include_unpublished=0" == error_message
"https://api.bintray.com/search/file" \
"?name=packages.json&subject=uilianries&repo=generic" == error_message


def test_file_search_by_checksum():
bintray = Bintray()
response = bintray.file_search_by_checksum("85abc6aece02515e8bd87b9754a18af697527d88",
subject="uilianries", repo="generic")
subject="uilianries", repo="generic",
created_after="2019-07-01")
assert {'error': False, 'statusCode': 200} in response
assert {'created': '2019-07-01T20:51:42.879Z',
'name': 'packages.json',
'owner': 'uilianries',
'package': 'statistics',
'path': 'packages.json',
'repo': 'generic',
'sha1': '85abc6aece02515e8bd87b9754a18af697527d88',
'sha256': '9537027db06c520b6eeb3b8317cef5c994ab93e5ad4b17fac3567fba7089b165',
'size': 1967,
'version': '20190701'} in response


def test_bad_credentials_file_search_by_checksum():
bintray = Bintray("foobar", "85abc6aece02515e8bd87b9754a18af697527d88")
error_message = ""
try:
response = bintray.file_search_by_checksum(
bintray.file_search_by_checksum(
"85abc6aece02515e8bd87b9754a18af697527d88",
subject="uilianries", repo="generic")
except Exception as error:
error_message = str(error)
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
"https://api.bintray.com/packages/uilianries/generic/statistics/versions" \
"/20190701/files?include_unpublished=False&include_unpublished=0" == error_message
"https://api.bintray.com/search/file" \
"?sha1=85abc6aece02515e8bd87b9754a18af697527d88" \
"&subject=uilianries&repo=generic" == error_message


def test_file_in_download_list():
bintray = Bintray()
response = bintray.file_in_download_list("uilianries", "generic", "packages.json", True)
assert {'error': False, 'statusCode': 200} in response
assert {'error': False, 'message': 'success', 'statusCode': 200} == response

11 changes: 6 additions & 5 deletions tests/test_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_update_org_proprietary_licenses():
error_message = str(error)

assert "Could not PATCH (405): 405 Client Error: Method Not Allowed for url: " \
"https://api.bintray.com/orgs/jfrog/licenses/foobar"
"https://api.bintray.com/orgs/jfrog/licenses/foobar" == error_message


def test_update_user_proprietary_licenses():
Expand All @@ -88,7 +88,7 @@ def test_update_user_proprietary_licenses():
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"
"https://api.bintray.com/users/uilianries/licenses/foobar" == error_message


def test_delete_org_proprietary_licenses():
Expand All @@ -99,7 +99,8 @@ def test_delete_org_proprietary_licenses():
except Exception as error:
error_message = str(error)
assert "Could not DELETE (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/orgs/jfrog/licenses/foobar"
"https://api.bintray.com/orgs/jfrog/licenses/foobar" == error_message


def test_delete_user_proprietary_licenses():
bintray = Bintray()
Expand All @@ -108,5 +109,5 @@ def test_delete_user_proprietary_licenses():
bintray.delete_user_proprietary_license(user="uilianries", custom_license_name="foobar")
except Exception as error:
error_message = str(error)
assert "Could not DELETE (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/users/uilianries/licenses/foobar"
assert "Could not DELETE (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses/foobar" == error_message

0 comments on commit 4c90f3f

Please sign in to comment.