@mock.patch('localshop.apps.packages.tasks.download_file')
@pytest.mark.django_db
def test_release_with_a_missing_file(download_file_mock, repository, rf):
    release_file = ReleaseFileFactory(
        release__package__repository=repository)
    os.remove(release_file.distribution.path)

    url_kwargs = {
        'repo': repository.slug,
        'name': release_file.release.package.name,
        'pk': release_file.pk,
        'filename': release_file.filename
    }

    request = rf.get(reverse('packages:download', kwargs=url_kwargs))
    response = views.DownloadReleaseFile.as_view()(request, **url_kwargs)

    # The request is redirected to PyPI
    assert response.status_code == 302
    assert response.url == release_file.url

    # The download file task must the queued
    assert download_file_mock.delay.call_count == 1
    assert download_file_mock.delay.call_args[1] == {'pk': release_file.pk}
If a local ReleaseFile had a missing file we must set local as False,
dataset/ETHPy150Open mvantellingen/localshop/tests/apps/packages/views/test_download_file.py/test_release_with_a_missing_file