fix anitya tests
This commit is contained in:
parent
0a2f768848
commit
9dbd571a01
3 changed files with 68 additions and 196 deletions
|
@ -19,7 +19,7 @@ class TestAnityaSetAnitya:
|
|||
Test initialization of anitya module.
|
||||
"""
|
||||
config = {
|
||||
"anitya_endpoint": "https://release-monitoring.org/",
|
||||
"anitya_endpoint": "https://release-monitoring.org",
|
||||
"anitya_access_token": "TOKEN",
|
||||
}
|
||||
anitya_obj = anitya.set_anitya(config)
|
||||
|
@ -59,7 +59,7 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
Setup method for test class.
|
||||
"""
|
||||
config = {
|
||||
"anitya_endpoint": "https://release-monitoring.org/",
|
||||
"anitya_endpoint": "https://release-monitoring.org",
|
||||
"anitya_access_token": "TOKEN",
|
||||
}
|
||||
self.anitya_obj = anitya.set_anitya(config)
|
||||
|
@ -69,7 +69,7 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
"""
|
||||
Assert that method will return correct response about project exists in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "amedvede_project"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
|
@ -87,7 +87,7 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
|
||||
result = self.anitya_obj.does_project_exists_in_anitya(project_name)
|
||||
|
||||
assert result == "https://release-monitoring.org/project//123"
|
||||
assert result == "https://release-monitoring.org/project/123"
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
@ -96,7 +96,7 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
"""
|
||||
Assert that method will return correct response about project does not exist in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "amedvede_project"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 404
|
||||
|
@ -112,7 +112,7 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
|
||||
def test_does_project_exists_in_anitya_empty_items(self):
|
||||
"""Assert that method will return correct response about project not found in anitya."""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "amedvede_project"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
|
@ -127,11 +127,11 @@ class TestAnityaDoesProjectExistInAnitya:
|
|||
endpoint, params=params
|
||||
)
|
||||
|
||||
def test_does_project_exists_in_anitya_wronge_strcture(self):
|
||||
def test_does_project_exists_in_anitya_wrong_structure(self):
|
||||
"""
|
||||
Assert that method will return correct response about project has wrong structure in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "amedvede_project"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
|
@ -164,56 +164,26 @@ class TestAnityaDoesPackageExistInAnitya:
|
|||
Setup method for test class.
|
||||
"""
|
||||
config = {
|
||||
"anitya_endpoint": "https://release-monitoring.org/",
|
||||
"anitya_endpoint": "https://release-monitoring.org",
|
||||
"anitya_access_token": "TOKEN",
|
||||
}
|
||||
self.anitya_obj = anitya.set_anitya(config)
|
||||
self.anitya_obj._requests_session = Mock()
|
||||
|
||||
def test_does_package_exists_in_anitya_project_names_are_same(self):
|
||||
@pytest.mark.parametrize(
|
||||
"project_name, expected_project_name, expected_result",
|
||||
[
|
||||
("nice_project", "nice_project", True),
|
||||
("nice_project", "bad_project", False),
|
||||
],
|
||||
)
|
||||
def test_does_package_exists_in_anitya(self, project_name, expected_project_name, expected_result):
|
||||
"""
|
||||
Assert that method will return correct response about package exists in anitya
|
||||
and his project name is same with expected.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/packages/"
|
||||
package_name = "amedvede_package"
|
||||
project_name = "amedvede_package"
|
||||
distribution = "Fedora"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"items": [
|
||||
{
|
||||
"name": package_name,
|
||||
"project": project_name,
|
||||
}
|
||||
],
|
||||
"total_items": 1,
|
||||
}
|
||||
params = {
|
||||
"name": package_name,
|
||||
"distribution": distribution,
|
||||
}
|
||||
self.anitya_obj._requests_session.get.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.does_package_exists_in_anitya(
|
||||
package_name, distribution, project_name
|
||||
)
|
||||
|
||||
assert result == 2 # package and project name the same
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
||||
def test_does_package_exists_in_anitya_project_names_are_different(self):
|
||||
"""
|
||||
Assert that method will return correct response about package exists in anitya
|
||||
and his project name is different from expected.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
package_name = "amedvede_package"
|
||||
project_name = "different name"
|
||||
expected_project_name = "amedvede_package"
|
||||
distribution = "Fedora"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
|
@ -236,16 +206,41 @@ class TestAnityaDoesPackageExistInAnitya:
|
|||
package_name, distribution, expected_project_name
|
||||
)
|
||||
|
||||
assert result == 1 # package and project name are different
|
||||
assert result is expected_result # package and project name the same
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
||||
def test_does_package_exists_in_anitya_not_found_status_code(self):
|
||||
def test_does_package_exists_in_anitya_not_found(self):
|
||||
"""
|
||||
Assert that method will return correct response when package does not exist in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org/api/v2/packages/"
|
||||
package_name = "amedvede_package"
|
||||
project_name = "different name"
|
||||
distribution = "Fedora"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 202
|
||||
params = {
|
||||
"name": package_name,
|
||||
"distribution": distribution,
|
||||
}
|
||||
self.anitya_obj._requests_session.get.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.does_package_exists_in_anitya(
|
||||
package_name, distribution, project_name
|
||||
)
|
||||
|
||||
assert result == False # package and project name are different
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
||||
def test_does_package_exists_in_anitya_found_zero_items(self):
|
||||
"""
|
||||
Assert that method will return correct response about package does not exist in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/packages/"
|
||||
package_name = "amedvede_package"
|
||||
project_name = "different name"
|
||||
distribution = "Fedora"
|
||||
|
@ -262,32 +257,7 @@ class TestAnityaDoesPackageExistInAnitya:
|
|||
package_name, distribution, project_name
|
||||
)
|
||||
|
||||
assert result == 0 # package and project name are different
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
||||
def test_does_package_exists_in_anitya_not_found_items_count(self):
|
||||
"""
|
||||
Assert that method will return correct response about package does not exist in anitya.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
package_name = "amedvede_package"
|
||||
project_name = "different name"
|
||||
distribution = "Fedora"
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 400
|
||||
params = {
|
||||
"name": package_name,
|
||||
"distribution": distribution,
|
||||
}
|
||||
self.anitya_obj._requests_session.get.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.does_package_exists_in_anitya(
|
||||
package_name, distribution, project_name
|
||||
)
|
||||
|
||||
assert result == 0 # package and project name are different
|
||||
assert result is False # package and project name are different
|
||||
self.anitya_obj._requests_session.get.assert_called_once_with(
|
||||
endpoint, params=params
|
||||
)
|
||||
|
@ -303,7 +273,7 @@ class TestAnityaCreateProjectInAnitya:
|
|||
Setup method for test class.
|
||||
"""
|
||||
config = {
|
||||
"anitya_endpoint": "https://release-monitoring.org/",
|
||||
"anitya_endpoint": "https://release-monitoring.org",
|
||||
"anitya_access_token": "TOKEN",
|
||||
}
|
||||
self.anitya_obj = anitya.set_anitya(config)
|
||||
|
@ -313,7 +283,7 @@ class TestAnityaCreateProjectInAnitya:
|
|||
"""
|
||||
Assert that method will return correct response when project is created.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "project"
|
||||
homepage = "https://project.com"
|
||||
backend = "GitHub"
|
||||
|
@ -332,7 +302,7 @@ class TestAnityaCreateProjectInAnitya:
|
|||
project_name, homepage, backend
|
||||
)
|
||||
|
||||
assert result == "https://release-monitoring.org/project//123"
|
||||
assert result == "https://release-monitoring.org/project/123"
|
||||
self.anitya_obj._requests_session.post.assert_called_once_with(
|
||||
url=endpoint,
|
||||
data=test_data,
|
||||
|
@ -343,7 +313,7 @@ class TestAnityaCreateProjectInAnitya:
|
|||
"""
|
||||
Assert that method will return correct response when project is not created.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/projects/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/projects/"
|
||||
project_name = "project"
|
||||
homepage = "https://project.com"
|
||||
backend = "GitHub"
|
||||
|
@ -378,17 +348,27 @@ class TestAnityaCreatePackageInAnitya:
|
|||
Setup method for test class.
|
||||
"""
|
||||
config = {
|
||||
"anitya_endpoint": "https://release-monitoring.org/",
|
||||
"anitya_endpoint": "https://release-monitoring.org",
|
||||
"anitya_access_token": "TOKEN",
|
||||
}
|
||||
self.anitya_obj = anitya.set_anitya(config)
|
||||
self.anitya_obj._requests_session = Mock()
|
||||
|
||||
def test_create_package_in_anitya_successful_creation(self):
|
||||
@pytest.mark.parametrize(
|
||||
"response_code, expected_result",
|
||||
[
|
||||
(201, "Success"),
|
||||
(400, "Bad Request, some necessary arguments were not provided."),
|
||||
(401, "Unauthorized, access token is incorrect."),
|
||||
(409, "Conflict, package already exists."),
|
||||
(404, None),
|
||||
],
|
||||
)
|
||||
def test_create_package_in_anitya(self, response_code, expected_result):
|
||||
"""
|
||||
Assert that method will return correct response when package is created.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
endpoint = "https://release-monitoring.org/api/v2/packages/"
|
||||
package_name = "test_package"
|
||||
project_name = "test_project"
|
||||
distribution = "Fedora"
|
||||
|
@ -400,122 +380,14 @@ class TestAnityaCreatePackageInAnitya:
|
|||
"project_ecosystem": project_ecosystem,
|
||||
}
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 201
|
||||
mock_response.status_code = response_code
|
||||
self.anitya_obj._requests_session.post.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.create_package_in_anitya(
|
||||
package_name, project_name, distribution, project_ecosystem
|
||||
)
|
||||
|
||||
assert result == "Success"
|
||||
self.anitya_obj._requests_session.post.assert_called_once_with(
|
||||
url=endpoint,
|
||||
data=test_data,
|
||||
headers={"Authorization": "token TOKEN"},
|
||||
)
|
||||
|
||||
def test_create_package_in_anitya_bad_request(self):
|
||||
"""
|
||||
Assert that method will return correct response when some arguments are missing.
|
||||
"""
|
||||
package_name = "test_package"
|
||||
distribution = "Fedora"
|
||||
project_ecosystem = "https://project.com"
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 400
|
||||
self.anitya_obj._requests_session.post.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.create_package_in_anitya(
|
||||
package_name, "", distribution, project_ecosystem
|
||||
)
|
||||
|
||||
assert result == "Bad Request, some necessary arguments were not provided."
|
||||
|
||||
def test_create_package_in_anitya_unauthorized(self):
|
||||
"""
|
||||
Assert that method will return correct response when token is incorrect.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
package_name = "test_package"
|
||||
project_name = "test_project"
|
||||
distribution = "Fedora"
|
||||
project_ecosystem = "https://project.com"
|
||||
test_data = {
|
||||
"package_name": package_name,
|
||||
"project_name": project_name,
|
||||
"distribution": distribution,
|
||||
"project_ecosystem": project_ecosystem,
|
||||
}
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 401
|
||||
self.anitya_obj._requests_session.post.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.create_package_in_anitya(
|
||||
package_name, project_name, distribution, project_ecosystem
|
||||
)
|
||||
|
||||
assert result == "Unauthorized, access token is incorrect."
|
||||
self.anitya_obj._requests_session.post.assert_called_once_with(
|
||||
url=endpoint,
|
||||
data=test_data,
|
||||
headers={"Authorization": "token TOKEN"},
|
||||
)
|
||||
|
||||
def test_create_package_in_anitya_conflict(self):
|
||||
"""
|
||||
Assert that method will return correct response when some other issues will happen.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
package_name = "test_package"
|
||||
project_name = "test_project"
|
||||
distribution = "Fedora"
|
||||
project_ecosystem = "https://project.com"
|
||||
test_data = {
|
||||
"package_name": package_name,
|
||||
"project_name": project_name,
|
||||
"distribution": distribution,
|
||||
"project_ecosystem": project_ecosystem,
|
||||
}
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 409
|
||||
self.anitya_obj._requests_session.post.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.create_package_in_anitya(
|
||||
package_name, project_name, distribution, project_ecosystem
|
||||
)
|
||||
|
||||
assert result == "Conflict, package already exists."
|
||||
self.anitya_obj._requests_session.post.assert_called_once_with(
|
||||
url=endpoint,
|
||||
data=test_data,
|
||||
headers={"Authorization": "token TOKEN"},
|
||||
)
|
||||
|
||||
def test_create_package_in_anitya_other_issues(self):
|
||||
"""
|
||||
Assert that method will return correct response when some other issues will happen.
|
||||
"""
|
||||
endpoint = "https://release-monitoring.org//api/v2/packages/"
|
||||
package_name = "test_package"
|
||||
project_name = "test_project"
|
||||
distribution = "Fedora"
|
||||
project_ecosystem = "https://project.com"
|
||||
test_data = {
|
||||
"package_name": package_name,
|
||||
"project_name": project_name,
|
||||
"distribution": distribution,
|
||||
"project_ecosystem": project_ecosystem,
|
||||
}
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 505
|
||||
self.anitya_obj._requests_session.post.return_value = mock_response
|
||||
|
||||
result = self.anitya_obj.create_package_in_anitya(
|
||||
package_name, project_name, distribution, project_ecosystem
|
||||
)
|
||||
|
||||
assert result is None
|
||||
assert result == expected_result
|
||||
self.anitya_obj._requests_session.post.assert_called_once_with(
|
||||
url=endpoint,
|
||||
data=test_data,
|
||||
|
|
|
@ -480,7 +480,7 @@ class SCMRequestProcessor(ToddlerBase):
|
|||
)
|
||||
return
|
||||
|
||||
monitor = issue_body_json["monitor"]
|
||||
monitor = issue_body_json.get("monitor", "").strip()
|
||||
if monitor != "no-monitoring":
|
||||
for key in required_keys_for_monitor:
|
||||
if key not in issue_body_json.keys():
|
||||
|
|
|
@ -111,7 +111,7 @@ class Anitya(object):
|
|||
project_name (str): The name of the project.
|
||||
|
||||
Returns:
|
||||
False if package dont exist
|
||||
False if package don't exist
|
||||
False if package exist but his project is different from provided project name
|
||||
True if package exist and his project is correct
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue