| |
@@ -1,9 +1,10 @@
|
| |
import json
|
| |
import os
|
| |
- from unittest.mock import patch
|
| |
+ from unittest.mock import patch, MagicMock
|
| |
|
| |
import pagure.lib.model
|
| |
import pagure.lib.query
|
| |
+ import pygit2
|
| |
|
| |
from pagure_distgit import model
|
| |
from pagure_distgit import plugin
|
| |
@@ -274,8 +275,27 @@
|
| |
[],
|
| |
)
|
| |
|
| |
+ # Create a rpms/test4 project
|
| |
+ item = pagure.lib.model.Project(
|
| |
+ user_id=1, # pingou
|
| |
+ name="test4",
|
| |
+ namespace="rpms",
|
| |
+ is_fork=False,
|
| |
+ parent_id=None,
|
| |
+ description="test project #4",
|
| |
+ hook_token="aaabbbcccdd",
|
| |
+ )
|
| |
+ item.close_status = ["Invalid", "Insufficient data", "Fixed", "Duplicate"]
|
| |
+ self.session.add(item)
|
| |
+ self.session.flush()
|
| |
+ tests.create_locks(self.session, item)
|
| |
+ self.session.commit()
|
| |
+ # Create its git repo
|
| |
+ repo_path = os.path.join(self.path, "repos", "rpms", "test4.git")
|
| |
+ pygit2.init_repository(repo_path, bare=True)
|
| |
+
|
| |
repo = pagure.lib.query.get_authorized_project(
|
| |
- self.session, "test3", namespace="somenamespace",
|
| |
+ self.session, "test4", namespace="rpms",
|
| |
)
|
| |
token = pagure.lib.query.get_api_token(self.session, "aaabbbcccddd")
|
| |
token.project = repo
|
| |
@@ -297,7 +317,7 @@
|
| |
"""
|
| |
headers = {"Authorization": "token foo_token"}
|
| |
output = self.app.post(
|
| |
- "/_dg/take_orphan/somenamespace/test3", headers=headers
|
| |
+ "/_dg/take_orphan/rpms/test4", headers=headers
|
| |
)
|
| |
# invalid token
|
| |
assert output.status_code == 401
|
| |
@@ -306,7 +326,7 @@
|
| |
"""Test the take orphan endpoint with an invalid API token. """
|
| |
headers = {"Authorization": "token BBBZZZOOO"}
|
| |
output = self.app.post(
|
| |
- "/_dg/take_orphan/somenamespace/test3", headers=headers,
|
| |
+ "/_dg/take_orphan/rpms/test4", headers=headers,
|
| |
)
|
| |
assert output.status_code == 401
|
| |
|
| |
@@ -318,11 +338,11 @@
|
| |
mock_pdc.return_value = True
|
| |
headers = {"Authorization": "token aaabbbcccddd"}
|
| |
repo = pagure.lib.query.get_authorized_project(
|
| |
- self.session, "test3", namespace="somenamespace",
|
| |
+ self.session, "test4", namespace="rpms",
|
| |
)
|
| |
assert repo.orphan_reason.reason == "reason"
|
| |
output = self.app.post(
|
| |
- "/_dg/take_orphan/somenamespace/test3", headers=headers,
|
| |
+ "/_dg/take_orphan/rpms/test4", headers=headers,
|
| |
)
|
| |
assert output.status_code == 200
|
| |
data = json.loads(output.get_data(as_text=True))
|
| |
@@ -335,23 +355,27 @@
|
| |
|
| |
assert mock_log.call_count == 1
|
| |
|
| |
- @patch("pagure_distgit.plugin._is_active_in_pdc")
|
| |
+ @patch.dict("pagure.config.config", {"PDC_URL": "invalid://"})
|
| |
+ @patch("pagure_distgit.plugin.requests")
|
| |
@patch("pagure_distgit.plugin.pagure.lib.notify.log")
|
| |
- def test_take_orphan_no_reason(self, mock_log, mock_pdc):
|
| |
+ def test_take_orphan_no_reason(self, mock_log, mock_req):
|
| |
"""
|
| |
Assert that package is correctly adopted when reason
|
| |
is not provided.
|
| |
"""
|
| |
- mock_pdc.return_value = True
|
| |
+ resp = MagicMock()
|
| |
+ resp.url = "http://localhost"
|
| |
+ resp.json.return_value = {"results": [{"active": True}]}
|
| |
+ mock_req.get.return_value = resp
|
| |
headers = {"Authorization": "token aaabbbcccddd"}
|
| |
repo = pagure.lib.query.get_authorized_project(
|
| |
- self.session, "test3", namespace="somenamespace",
|
| |
+ self.session, "test4", namespace="rpms",
|
| |
)
|
| |
reason = repo.orphan_reason
|
| |
self.session.delete(reason)
|
| |
self.session.commit()
|
| |
output = self.app.post(
|
| |
- "/_dg/take_orphan/somenamespace/test3", headers=headers,
|
| |
+ "/_dg/take_orphan/rpms/test4", headers=headers,
|
| |
)
|
| |
assert output.status_code == 200
|
| |
data = json.loads(output.get_data(as_text=True))
|
| |
@@ -362,3 +386,10 @@
|
| |
assert repo.user.user == "pingou"
|
| |
|
| |
assert mock_log.call_count == 1
|
| |
+
|
| |
+ assert mock_req.get.call_count == 1
|
| |
+ mock_req.get.assert_called_with(
|
| |
+ "invalid:/component-branches/?"
|
| |
+ "global_component=test4&name=rawhide&type=rpm",
|
| |
+ timeout=(30, 30)
|
| |
+ )
|
| |
Adjust the tests so it uses a project in the rpms namespace and check
how PDC is being called.
Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr