77import warnings
88from collections import ChainMap
99from unittest import mock
10+ from unittest .mock import MagicMock
1011
1112import click
1213import pytest
@@ -495,6 +496,7 @@ def test_load_full_config(tmp_git_repo_dir, git_add, git_commit):
495496 "fix_commit_msg" : True ,
496497 "default_branch" : "devel" ,
497498 "require_version_in_branch_name" : True ,
499+ "draft_pr" : False ,
498500 },
499501 )
500502
@@ -519,6 +521,7 @@ def test_load_partial_config(tmp_git_repo_dir, git_add, git_commit):
519521 "fix_commit_msg" : True ,
520522 "default_branch" : "main" ,
521523 "require_version_in_branch_name" : True ,
524+ "draft_pr" : False ,
522525 },
523526 )
524527
@@ -548,6 +551,7 @@ def test_load_config_no_head_sha(tmp_git_repo_dir, git_add, git_commit):
548551 "fix_commit_msg" : True ,
549552 "default_branch" : "devel" ,
550553 "require_version_in_branch_name" : True ,
554+ "draft_pr" : False ,
551555 },
552556 )
553557
@@ -1336,3 +1340,51 @@ def test_abort_cherry_pick_success(
13361340
13371341def test_cli_invoked ():
13381342 subprocess .check_call ("cherry_picker --help" .split ())
1343+
1344+
1345+ @pytest .mark .parametrize ("draft_pr" , (True , False ))
1346+ @mock .patch ("requests.post" )
1347+ @mock .patch ("gidgethub.sansio.create_headers" )
1348+ @mock .patch .object (CherryPicker , "username" , new_callable = mock .PropertyMock )
1349+ def test_create_gh_pr_draft_states (
1350+ mock_username , mock_create_headers , mock_post , monkeypatch , draft_pr , config
1351+ ):
1352+ config ["draft_pr" ] = draft_pr
1353+ mock_username .return_value = "username"
1354+ monkeypatch .setenv ("GH_AUTH" , "True" )
1355+ with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
1356+ cherry_picker = CherryPicker (
1357+ "origin" , "xxx" , [], prefix_commit = True , config = config
1358+ )
1359+ mock_create_headers .return_value = {"Authorization" : "token gh-token" }
1360+
1361+ mock_response = MagicMock ()
1362+ mock_response .status_code = 201
1363+ mock_response .json .return_value = {
1364+ "html_url" : "https://github.com/octocat/Hello-World/pull/1347" ,
1365+ "number" : 1347 ,
1366+ }
1367+ mock_post .return_value = mock_response
1368+
1369+ base_branch = "main"
1370+ head_branch = "feature-branch"
1371+ commit_message = "Commit message"
1372+ gh_auth = "gh_auth"
1373+
1374+ cherry_picker .create_gh_pr (
1375+ base_branch , head_branch , commit_message = commit_message , gh_auth = gh_auth
1376+ )
1377+
1378+ mock_post .assert_called_once_with (
1379+ "https://api.github.com/repos/python/cpython/pulls" ,
1380+ headers = {"Authorization" : "token gh-token" },
1381+ json = {
1382+ "title" : "Commit message" ,
1383+ "body" : "" ,
1384+ "head" : "username:feature-branch" ,
1385+ "base" : "main" ,
1386+ "maintainer_can_modify" : True ,
1387+ "draft" : draft_pr ,
1388+ },
1389+ timeout = 10 ,
1390+ )
0 commit comments