test_form.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:django-hierarkey 作者: raphaelm 项目源码 文件源码
def test_form_delete_file(organization):
    val = SimpleUploadedFile("sample_invalid_image.jpg", b"file_content", content_type="image/jpeg")
    form = SampleForm(obj=organization, attribute_name='settings', data={}, files={
        'test_file': val
    })
    assert form.is_valid()
    form.save()

    organization.settings.flush()
    oldname = organization.settings.get('test_file', as_type=File, binary_file=True).name

    form = SampleForm(obj=organization, attribute_name='settings', data={
        'test_file-clear': 'on'
    })
    assert form.is_valid()
    form.save()

    organization.settings.flush()
    assert not organization.settings.test_file
    assert not os.path.exists(oldname)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号