nixprstatus/tests/test_pr.py

70 lines
2.8 KiB
Python
Raw Permalink Normal View History

2024-10-05 23:53:34 +00:00
import unittest
import unittest.mock
2024-10-06 17:31:14 +00:00
from nixprstatus.pr import commit_in_branch, pr_merge_status, commits_since
2024-10-09 20:21:28 +00:00
from tests.helpers.mocks import mocked_requests_get
2024-10-05 23:53:34 +00:00
class TestPRMergeStatus(unittest.TestCase):
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_merge_status_345583(self, mock_get):
pr = 345583
branches = ["master", "nixos-unstable", "nixos-24.05"]
2024-10-06 23:50:22 +00:00
res = pr_merge_status(pr, branches, check_backport=False)
2024-10-05 23:53:34 +00:00
self.assertTrue(res.merged)
self.assertTrue(res.branches["master"])
self.assertTrue(res.branches["nixos-unstable"])
self.assertFalse(res.branches["nixos-24.05"])
2024-10-06 23:50:22 +00:00
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_merge_status_backport_345769(self, mock_get):
pr = 345769
branches = ["nixos-24.05"]
res = pr_merge_status(pr, branches, check_backport=True)
self.assertTrue(res.merged)
self.assertTrue(res.branches["nixos-24.05 (#346022)"])
2024-10-07 14:02:45 +00:00
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_merge_status_title_345769(self, mock_get):
pr = 345769
branches = ["nixos-24.05"]
expected_title = "Firefox: 130.0.1 -> 131.0; 128.2.0esr -> 128.3.0esr; 115.15.0esr -> 115.16.0esr"
res = pr_merge_status(pr, branches, check_backport=True)
self.assertEqual(res.title, expected_title)
2024-10-07 14:32:49 +00:00
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_merge_status_no_check_master_345583(self, mock_get):
pr = 345583
branches = ["master", "nixos-unstable", "nixos-24.05"]
master_compare_url = "https://api.github.com/repos/NixOS/nixpkgs/compare/master...2c5fac3edf2d00d948253e392ec1604b29b38f14"
res = pr_merge_status(pr, branches, check_backport=False)
self.assertTrue(res.merged)
self.assertTrue(res.branches["master"])
urls_called = [call[0][0] for call in mock_get.call_args_list]
self.assertFalse(master_compare_url in urls_called)
2024-10-05 23:53:34 +00:00
class TestCommitInBranch(unittest.TestCase):
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_commit_in_branch_2c5fac3e(self, mock_get):
commit_sha = "2c5fac3edf2d00d948253e392ec1604b29b38f14"
res = commit_in_branch(commit_sha, "master")
self.assertTrue(res)
res = commit_in_branch(commit_sha, "nixos-24.05")
self.assertFalse(res)
2024-10-06 17:31:14 +00:00
class TestCommitsSince(unittest.TestCase):
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_commits_since_27e30d17(self, mock_get):
commit_sha = "27e30d177e57d912d614c88c622dcfdb2e6e6515"
res = commits_since("nixos-unstable", commit_sha)
self.assertEqual(res, 795)