|
| 1 | +import copy |
1 | 2 | import subprocess |
2 | 3 | from unittest.mock import ( |
3 | 4 | MagicMock, |
@@ -51,30 +52,51 @@ def test_iterate_repos_matching_authed_username(mock_archive_repo, mock_github_i |
51 | 52 | @patch('github_archive.repos._archive_repo') |
52 | 53 | def test_iterate_repos_include_list(mock_archive_repo, mock_github_instance, mock_git_asset): |
53 | 54 | """Tests that we iterate repos that are on the include list.""" |
54 | | - repos = [mock_git_asset] |
| 55 | + mock_non_include_asset = copy.deepcopy(mock_git_asset) |
| 56 | + mock_non_include_asset.name = 'not-the-name' |
| 57 | + repos = [mock_git_asset, mock_non_include_asset] |
55 | 58 | github_archive = GithubArchive( |
56 | 59 | users='mock_username', |
57 | 60 | include='mock-asset-name', |
58 | 61 | ) |
59 | 62 |
|
60 | 63 | iterate_repos_to_archive(github_archive, repos, CLONE_OPERATION) |
61 | 64 |
|
62 | | - mock_archive_repo.assert_called_once() |
| 65 | + mock_archive_repo.assert_called_once() # Called once even though there are two, ensure we filtered |
63 | 66 |
|
64 | 67 |
|
65 | 68 | @patch('github_archive.archive.Github') |
66 | 69 | @patch('github_archive.repos._archive_repo') |
67 | 70 | def test_iterate_repos_exclude_list(mock_archive_repo, mock_github_instance, mock_git_asset): |
68 | 71 | """Tests that we do not iterate repos that are on the exclude list.""" |
69 | | - repos = [mock_git_asset] |
| 72 | + mock_non_exclude_asset = copy.deepcopy(mock_git_asset) |
| 73 | + mock_non_exclude_asset.name = 'not-the-name' |
| 74 | + repos = [mock_git_asset, mock_non_exclude_asset] |
70 | 75 | github_archive = GithubArchive( |
71 | 76 | users='mock_username', |
72 | 77 | exclude='mock-asset-name', |
73 | 78 | ) |
74 | 79 |
|
75 | 80 | iterate_repos_to_archive(github_archive, repos, CLONE_OPERATION) |
76 | 81 |
|
77 | | - mock_archive_repo.assert_not_called() |
| 82 | + mock_archive_repo.assert_called_once() # Called once even though there are two, ensure we filtered |
| 83 | + |
| 84 | + |
| 85 | +@patch('github_archive.archive.Github') |
| 86 | +@patch('github_archive.repos._archive_repo') |
| 87 | +def test_iterate_repos_languages_list(mock_archive_repo, mock_github_instance, mock_git_asset): |
| 88 | + """Tests that we iterate repos that are one of the languages in the list.""" |
| 89 | + mock_non_language_asset = copy.deepcopy(mock_git_asset) |
| 90 | + mock_non_language_asset.language = 'Go' |
| 91 | + repos = [mock_git_asset, mock_non_language_asset] |
| 92 | + github_archive = GithubArchive( |
| 93 | + users='mock_username', |
| 94 | + languages='python', |
| 95 | + ) |
| 96 | + |
| 97 | + iterate_repos_to_archive(github_archive, repos, CLONE_OPERATION) |
| 98 | + |
| 99 | + mock_archive_repo.assert_called_once() # Called once even though there are two, ensure we filtered |
78 | 100 |
|
79 | 101 |
|
80 | 102 | @patch('logging.Logger.info') |
@@ -157,10 +179,14 @@ def test_archive_repo_called_process_error(mock_logger, mock_subprocess, mock_gi |
157 | 179 | mock_logger.assert_called_once() |
158 | 180 |
|
159 | 181 |
|
| 182 | +@patch('github_archive.archive.Github') |
160 | 183 | @patch('github_archive.repos._fork_repo') |
161 | | -def test_iterate_repos_to_fork(mock_fork_repo): |
| 184 | +def test_iterate_repos_to_fork(mock_fork_repo, mock_github_instance): |
162 | 185 | repo = MagicMock(spec=Repository.Repository) |
163 | | - iterate_repos_to_fork([repo]) |
| 186 | + github_archive = GithubArchive( |
| 187 | + gists='mock_username', |
| 188 | + ) |
| 189 | + iterate_repos_to_fork(github_archive, [repo]) |
164 | 190 |
|
165 | 191 | mock_fork_repo.assert_called_once() |
166 | 192 |
|
|
0 commit comments