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

Commit

Permalink
#13 Fix unit 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 20, 2019
1 parent 8ba2c24 commit 94ff2cf
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 141 deletions.
25 changes: 8 additions & 17 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
def create_attributes():
bintray = Bintray()
attributes = [{"name": "att1", "values": ["val1"], "type": "string"}]
try:
return bintray.set_attributes("uilianries", "generic", "statistics", "test", attributes)
except:
pass
return None
return bintray.set_attributes("uilianries", "generic", "statistics", "test", attributes)


@pytest.fixture()
Expand Down Expand Up @@ -54,7 +50,7 @@ def test_delete_attributes(create_attributes):

def test_search_attributes(create_attributes):
bintray = Bintray()
attributes = [{"att1": ["val1", "val2"]}]
attributes = [{'att1': ["val1", "val2"]}]
response = bintray.search_attributes("uilianries", "generic", "statistics", attributes)
assert {'error': False, 'statusCode': 200} in response

Expand All @@ -66,7 +62,7 @@ def test_get_files_attributes(create_file_attributes):

def test_set_files_attributes():
bintray = Bintray()
attributes = [{"name": "att1", "values": ["val2"], "type": "string"}]
attributes = [{'name': 'att1', 'values': ['val2'], 'type': "string"}]
response = bintray.set_file_attributes("uilianries", "generic", "packages.json", attributes)
assert [{'name': 'att1', 'type': 'STRING', 'values': ['val2']},
{'error': False, 'statusCode': 200}] == response
Expand All @@ -90,14 +86,9 @@ def test_delete_file_attributes(create_file_attributes):
'statusCode': 200} == response


def test_search_file_attributes():
def test_search_file_attributes(create_file_attributes):
bintray = Bintray()
attributes = [{"name": "att1"}]
error_message = ""
try:
bintray.search_file_attributes("uilianries", "generic", attributes)
except Exception as error:
error_message = str(error)

assert "Could not POST (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/files/uilianries/generic/search/attributes" == error_message
attributes = [{'att1': ["val1"]}]
response = bintray.search_file_attributes("uilianries", "generic", attributes)
assert "packages.json" == response[0]["name"]

4 changes: 1 addition & 3 deletions tests/test_content_downloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ def test_url_signing():
bintray.url_signing("uilianries", "generic", json_file, {})
except Exception as error:
error_message = str(error)
assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/signed_url/uilianries/generic/packages.json" \
"?encrypt=false" == error_message
assert "Could not POST (403): Repository '/uilianries/generic' must be premium" == error_message
5 changes: 2 additions & 3 deletions tests/test_content_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ def test_sync_version_artifacts_to_maven_central():
except Exception as error:
error_message = str(error)

assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/maven_central_sync/uilianries/generic/statistics/versions/test"\
== error_message
assert "Could not POST (403): In order to sync to Maven Central your package must be included" \
" in the JCenter repository" == error_message
23 changes: 7 additions & 16 deletions tests/test_eula.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@

def test_get_eulas():
bintray = Bintray()
error_message = ""
try:
bintray.get_eulas("jfrog", "bintray")
except Exception as error:
error_message = str(error)
assert "Could not GET (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/jfrog/bintray/eulas" == error_message
response = bintray.get_eulas("jfrog", "xray")
assert response[0]["name"] == "XRAY_License_Agreement"


def test_get_eula():
bintray = Bintray()
error_message = ""
try:
bintray.get_eula("jfrog", "bintray", "eula")
bintray.get_eula("jfrog", "xray", "eula")
except Exception as error:
error_message = str(error)
assert "Could not GET (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/jfrog/bintray/eulas/eula" == error_message
assert "Could not GET (403): forbidden" == error_message


def test_create_eula():
Expand All @@ -31,8 +25,7 @@ def test_create_eula():
["1.0"])
except Exception as error:
error_message = str(error)
assert "Could not POST (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/uilianries/generic/eulas" == error_message
assert "Could not POST (404): Product 'generic' was not found" == error_message


def test_update_eula():
Expand All @@ -43,8 +36,7 @@ def test_update_eula():
["1.0"])
except Exception as error:
error_message = str(error)
assert "Could not PATCH (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/uilianries/generic/eulas/eula" == error_message
assert "Could not PATCH (404): Product 'generic' was not found" == error_message


def test_delete_eula():
Expand All @@ -54,5 +46,4 @@ def test_delete_eula():
bintray.delete_eula("uilianries", "generic", "eula")
except Exception as error:
error_message = str(error)
assert "Could not DELETE (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/uilianries/generic/eulas/eula" == error_message
assert "Could not DELETE (404): Product 'generic' was not found" == error_message
8 changes: 3 additions & 5 deletions tests/test_eula_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ def test_get_product_signed_eulas():
bintray = Bintray()
error_message = ""
try:
bintray.get_product_signed_eulas("jfrog", "bintray")
bintray.get_product_signed_eulas("jfrog", "xray")
except Exception as error:
error_message = str(error)
assert "Could not GET (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/jfrog/bintray/signed_eulas" == error_message
assert "Could not GET (403): forbidden" == error_message


def test_get_all_products_signed_eulas():
Expand All @@ -19,5 +18,4 @@ def test_get_all_products_signed_eulas():
bintray.get_all_products_signed_eulas("jfrog")
except Exception as error:
error_message = str(error)
assert "Could not GET (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/products/jfrog/_all/signed_eulas" == error_message
assert "Could not GET (403): forbidden" == error_message
19 changes: 6 additions & 13 deletions tests/test_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from bintray.bintray import Bintray


Expand All @@ -24,9 +25,7 @@ def test_bad_credentials_for_get_package_files():
bintray.get_package_files("uilianries", "generic", "statistics")
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/files?" \
"include_unpublished=0" == error_message
assert "Could not GET (401): This resource requires authentication" == error_message


def test_get_version_files():
Expand All @@ -52,9 +51,7 @@ def test_bad_credentials_for_get_version_files():
bintray.get_version_files("uilianries", "generic", "statistics", "20190701")
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=0" == error_message
assert "Could not GET (401): This resource requires authentication" == error_message


def test_file_search_by_name():
Expand All @@ -80,11 +77,10 @@ def test_bad_credentials_file_search_by_name():
bintray.search_file_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/search/file" \
"?name=packages.json&subject=uilianries&repo=generic" == error_message
assert "Could not GET (401): This resource requires authentication" == error_message


@pytest.mark.skip(reason="it takes ~2 minutes")
def test_file_search_by_checksum():
bintray = Bintray()
response = bintray.search_file_by_checksum("85abc6aece02515e8bd87b9754a18af697527d88",
Expand All @@ -102,10 +98,7 @@ def test_bad_credentials_file_search_by_checksum():
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/search/file" \
"?sha1=85abc6aece02515e8bd87b9754a18af697527d88" \
"&subject=uilianries&repo=generic" == error_message
assert "Could not GET (401): This resource requires authentication" == error_message


def test_file_in_download_list():
Expand Down
31 changes: 13 additions & 18 deletions tests/test_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def test_get_org_proprietary_licenses():
bintray.get_org_proprietary_licenses(org="jfrog")
except Exception as error:
error_message = str(error)
assert "Could not GET (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/orgs/jfrog/licenses" == error_message
assert "Could not GET (403): forbidden" == error_message


def test_get_user_proprietary_licenses():
Expand All @@ -26,8 +25,8 @@ def test_get_user_proprietary_licenses():
bintray.get_user_proprietary_licenses(user="uilianries")
except Exception as error:
error_message = str(error)
assert "Could not GET (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses" == error_message
assert "Could not GET (400): This action is not allowed for none-premium subject uilianries" \
== error_message


def test_bad_credentials_for_get_oss_licenses():
Expand All @@ -37,8 +36,7 @@ def test_bad_credentials_for_get_oss_licenses():
bintray.get_oss_licenses()
except Exception as error:
error_message = str(error)
assert "Could not GET (401): 401 Client Error: Unauthorized for url: " \
"https://api.bintray.com/licenses/oss_licenses" == error_message
assert "Could not GET (401): This resource requires authentication" == error_message


def test_create_org_proprietary_licenses():
Expand All @@ -49,8 +47,7 @@ def test_create_org_proprietary_licenses():
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: " \
"https://api.bintray.com/orgs/jfrog/licenses" == error_message
assert "Could not POST (403): forbidden" == error_message


def test_create_user_proprietary_licenses():
Expand All @@ -61,8 +58,8 @@ def test_create_user_proprietary_licenses():
url='https://opensource.org/licenses/MIT')
except Exception as error:
error_message = str(error)
assert "Could not POST (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses" == error_message
assert "Could not POST (400): This action is not allowed for none-premium subject uilianries" \
== error_message


def test_update_org_proprietary_licenses():
Expand All @@ -75,8 +72,7 @@ def test_update_org_proprietary_licenses():
except Exception as error:
error_message = str(error)

assert "Could not PATCH (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/orgs/jfrog/licenses/foobar" == error_message
assert "Could not PATCH (403): forbidden" == error_message


def test_update_user_proprietary_licenses():
Expand All @@ -90,8 +86,8 @@ def test_update_user_proprietary_licenses():
except Exception as error:
error_message = str(error)

assert "Could not PATCH (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses/foo" == error_message
assert "Could not PATCH (400): This action is not allowed for none-premium subject uilianries" \
== error_message


def test_delete_org_proprietary_licenses():
Expand All @@ -101,8 +97,7 @@ def test_delete_org_proprietary_licenses():
bintray.delete_org_proprietary_license(org="jfrog", 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/orgs/jfrog/licenses/foobar" == error_message
assert "Could not DELETE (403): forbidden" == error_message


def test_delete_user_proprietary_licenses():
Expand All @@ -112,5 +107,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 (400): 400 Client Error: Bad Request for url: " \
"https://api.bintray.com/users/uilianries/licenses/foobar" == error_message
assert "Could not DELETE (400): This action is not allowed for none-premium subject uilianries"\
== error_message
10 changes: 4 additions & 6 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ def test_create_product_readme():
bintray = Bintray()
error_message = ""
try:
bintray.create_product_readme("uilianries", "generic",
bintray.create_product_readme("jfrog", "xray",
github="uilianries/bintray-python")
except Exception as error:
error_message = str(error)

assert "Could not POST (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/uilianries/generic/readme" == error_message
assert "Could not POST (403): forbidden" == error_message


def test_delete_product_readme():
bintray = Bintray()
error_message = ""
try:
bintray.delete_product_readme("uilianries", "generic")
bintray.delete_product_readme("jfrog", "xray")
except Exception as error:
error_message = str(error)

assert "Could not DELETE (404): 404 Client Error: Not Found for url: " \
"https://api.bintray.com/products/uilianries/generic/readme" == error_message
assert "Could not DELETE (403): forbidden" == error_message
2 changes: 1 addition & 1 deletion tests/test_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def test_get_package_release_notes():
error_message = str(error)
assert "Could not GET (400): No release notes found for subject 'uilianries' repo 'generic' " \
"and pkg 'statistics' in the package level. Please check the version level release " \
"notes" == error_message
"notes" == error_message

Loading

0 comments on commit 94ff2cf

Please sign in to comment.