66from pathlib import Path
77from types import SimpleNamespace
88from typing import Any , Dict , Iterable , Iterator , Tuple
9- from unittest .mock import patch
9+ from unittest .mock import MagicMock , patch
1010
11+ import github
1112import pytest
1213
1314from cookie_python .manage .main import main as manage_cookie_main
@@ -27,6 +28,7 @@ def environ() -> Iterator[None]:
2728 GIT_AUTHOR_EMAIL = AUTHOR_EMAIL ,
2829 GIT_COMMITTER_NAME = AUTHOR_NAME ,
2930 GIT_COMMITTER_EMAIL = AUTHOR_EMAIL ,
31+ GITHUB_API_TOKEN = "unittest_token" ,
3032 )
3133 )
3234 with patch .dict (os .environ , env ):
@@ -62,6 +64,25 @@ def new_cookie(
6264 yield Path (temp_dir ) / PROJECT_NAME
6365
6466
67+ @pytest .fixture (autouse = True )
68+ def mock_pygithub (new_cookie : Path ) -> Iterator [MagicMock ]:
69+ with patch .object (github , "Github" ) as obj :
70+ gh = obj .return_value
71+ gh .get_repo .return_value = SimpleNamespace (
72+ name = PROJECT_NAME ,
73+ full_name = f"{ AUTHOR_NAME } /{ PROJECT_NAME } " ,
74+ ssh_url = str (new_cookie ),
75+ get_pulls = MagicMock (
76+ return_value = [
77+ SimpleNamespace (
78+ url = "https://unittest.example.com/repo/pulls/1138"
79+ )
80+ ],
81+ ),
82+ )
83+ yield obj
84+
85+
6586@pytest .fixture
6687def new_cookie_with_lock (new_cookie : Path , temp_dir : str ) -> Iterator [Path ]:
6788 for cmd in (
0 commit comments