|
@@ 236-268 (lines=33) @@
|
| 233 |
|
assert not mock_prompt_and_delete.called |
| 234 |
|
|
| 235 |
|
|
| 236 |
|
def test_unzip_url_existing_cache(mocker, tmpdir): |
| 237 |
|
"""In `unzip()`, a url will be downloaded and unzipped; an existing zip file |
| 238 |
|
will be removed. |
| 239 |
|
""" |
| 240 |
|
mock_prompt_and_delete = mocker.patch( |
| 241 |
|
'cookiecutter.zipfile.prompt_and_delete', |
| 242 |
|
return_value=True, |
| 243 |
|
autospec=True |
| 244 |
|
) |
| 245 |
|
|
| 246 |
|
request = mocker.MagicMock() |
| 247 |
|
request.iter_content.return_value = mock_download() |
| 248 |
|
|
| 249 |
|
mocker.patch( |
| 250 |
|
'cookiecutter.zipfile.requests.get', |
| 251 |
|
return_value=request, |
| 252 |
|
autospec=True, |
| 253 |
|
) |
| 254 |
|
|
| 255 |
|
clone_to_dir = tmpdir.mkdir('clone') |
| 256 |
|
|
| 257 |
|
# Create an existing cache of the zipfile |
| 258 |
|
existing_zip = clone_to_dir.join('fake-repo-tmpl.zip') |
| 259 |
|
existing_zip.write('This is an existing zipfile') |
| 260 |
|
|
| 261 |
|
output_dir = zipfile.unzip( |
| 262 |
|
'https://example.com/path/to/fake-repo-tmpl.zip', |
| 263 |
|
is_url=True, |
| 264 |
|
clone_to_dir=str(clone_to_dir) |
| 265 |
|
) |
| 266 |
|
|
| 267 |
|
assert output_dir.startswith(tempfile.gettempdir()) |
| 268 |
|
assert mock_prompt_and_delete.call_count == 1 |
| 269 |
|
|
| 270 |
|
|
| 271 |
|
def test_unzip_url_existing_cache_no_input(mocker, tmpdir): |
|
@@ 206-233 (lines=28) @@
|
| 203 |
|
) |
| 204 |
|
|
| 205 |
|
|
| 206 |
|
def test_unzip_url(mocker, tmpdir): |
| 207 |
|
"""In `unzip()`, a url will be downloaded and unzipped |
| 208 |
|
""" |
| 209 |
|
mock_prompt_and_delete = mocker.patch( |
| 210 |
|
'cookiecutter.zipfile.prompt_and_delete', |
| 211 |
|
return_value=True, |
| 212 |
|
autospec=True |
| 213 |
|
) |
| 214 |
|
|
| 215 |
|
request = mocker.MagicMock() |
| 216 |
|
request.iter_content.return_value = mock_download() |
| 217 |
|
|
| 218 |
|
mocker.patch( |
| 219 |
|
'cookiecutter.zipfile.requests.get', |
| 220 |
|
return_value=request, |
| 221 |
|
autospec=True, |
| 222 |
|
) |
| 223 |
|
|
| 224 |
|
clone_to_dir = tmpdir.mkdir('clone') |
| 225 |
|
|
| 226 |
|
output_dir = zipfile.unzip( |
| 227 |
|
'https://example.com/path/to/fake-repo-tmpl.zip', |
| 228 |
|
is_url=True, |
| 229 |
|
clone_to_dir=str(clone_to_dir) |
| 230 |
|
) |
| 231 |
|
|
| 232 |
|
assert output_dir.startswith(tempfile.gettempdir()) |
| 233 |
|
assert not mock_prompt_and_delete.called |
| 234 |
|
|
| 235 |
|
|
| 236 |
|
def test_unzip_url_existing_cache(mocker, tmpdir): |