-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4324 from nickmango/revert-pr-label
Revert "[#3577] Feature/PR Label"
- Loading branch information
Showing
3 changed files
with
40 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,9 @@ | |
from unittest import TestCase | ||
from unittest.mock import MagicMock, Mock, patch | ||
|
||
from cla.models.github_models import ( | ||
UserCommitSummary, | ||
get_author_summary, | ||
get_co_author_commits, | ||
get_pull_request_commit_authors, | ||
update_pull_request, | ||
) | ||
from cla.models.github_models import (UserCommitSummary, get_author_summary, | ||
get_co_author_commits, | ||
get_pull_request_commit_authors) | ||
|
||
|
||
class TestGetPullRequestCommitAuthors(TestCase): | ||
|
@@ -51,7 +47,7 @@ def test_get_pull_request_commit_with_co_author(self, mock_github_instance): | |
self.assertIn(co_author_email_2, [author.author_email for author in result]) | ||
self.assertIn("fake_login", [author.author_login for author in result]) | ||
self.assertIn("co_author_login", [author.author_login for author in result]) | ||
|
||
@patch("cla.utils.get_repository_service") | ||
def test_get_co_author_commits_invalid_gh_email(self, mock_github_instance): | ||
# Mock data | ||
|
@@ -63,27 +59,29 @@ def test_get_co_author_commits_invalid_gh_email(self, mock_github_instance): | |
installation_id = 123 | ||
|
||
# Call the function | ||
result = get_co_author_commits(co_author, commit, pr, installation_id) | ||
result = get_co_author_commits(co_author,commit, pr, installation_id) | ||
|
||
# Assertions | ||
self.assertEqual(result.commit_sha, "fake_sha") | ||
self.assertEqual(result.author_id, None) | ||
self.assertEqual(result.author_login, None) | ||
self.assertEqual(result.author_email, "co_author_email.gmail.com") | ||
self.assertEqual(result.author_name, "co_author") | ||
|
||
@patch("cla.utils.get_repository_service") | ||
def test_get_co_author_commits_valid_gh_email(self, mock_github_instance): | ||
# Mock data | ||
co_author = ("co_author", "co_author_email.gmail.com") | ||
commit = MagicMock() | ||
commit.sha = "fake_sha" | ||
mock_github_instance.return_value.get_github_user_by_email.return_value = Mock(id=123, login="co_author_login") | ||
mock_github_instance.return_value.get_github_user_by_email.return_value = Mock( | ||
id=123, login="co_author_login" | ||
) | ||
pr = 1 | ||
installation_id = 123 | ||
|
||
# Call the function | ||
result = get_co_author_commits(co_author, commit, pr, installation_id) | ||
result = get_co_author_commits(co_author,commit, pr, installation_id) | ||
|
||
# Assertions | ||
self.assertEqual(result.commit_sha, "fake_sha") | ||
|
@@ -92,57 +90,6 @@ def test_get_co_author_commits_valid_gh_email(self, mock_github_instance): | |
self.assertEqual(result.author_email, "co_author_email.gmail.com") | ||
self.assertEqual(result.author_name, "co_author") | ||
|
||
@patch("cla.models.github_models.cla.utils") | ||
@patch("cla.models.github_models.GitHubInstallation") | ||
def test_update_pull_request_valid_labels(self, mock_github_installation, mock_utils): | ||
# Mock data | ||
installation_id = 123 | ||
github_repository_id = 456 | ||
pull_request = MagicMock() | ||
repository_name = "test_org/test_repo" | ||
signed = [ | ||
UserCommitSummary( | ||
author_id="1", | ||
author_login="fake_login", | ||
author_name="Fake Author", | ||
author_email="[email protected]", | ||
commit_sha="fake_sha", | ||
authorized=True, | ||
affiliated=True, | ||
) | ||
] | ||
missing = [] | ||
project_version = "2" | ||
|
||
last_commit = MagicMock() | ||
last_commit.sha = "fake_sha" | ||
pull_request.get_commits.return_value.reversed.__getitem__.return_value = last_commit | ||
|
||
mock_utils.get_full_sign_url.return_value = "https://example.com/sign" | ||
mock_utils.assemble_cla_comment.return_value = "CLA comment" | ||
mock_utils.assemble_cla_status.return_value = ("context", "CLA status") | ||
|
||
client_mock = MagicMock() | ||
mock_github_installation.return_value = client_mock | ||
|
||
# Call the function | ||
update_pull_request( | ||
installation_id, | ||
github_repository_id, | ||
pull_request, | ||
repository_name, | ||
signed, | ||
missing, | ||
project_version, | ||
) | ||
|
||
# Assertions | ||
client_mock.add_labels_to_pr.assert_called_once_with( | ||
repository_name, | ||
pull_request.number, | ||
["CLA: Valid"], | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |