test_forms.py 文件源码

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

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
def test_valid_form_without_position(self):
        """
        Checks whether the form without specified position
        is valid since the 'posion' field is optional
        """
        # open the image file
        with open(self.image_path, 'rb') as upload_file:
            # dict without position
            post_dict = {
                'content_type': self.ctype.pk,
                'object_id': 1
            }
            # dict with valid uploaded file
            file_dict = {
                'image': SimpleUploadedFile(
                    upload_file.name,
                    upload_file.read()
                )
            }
            # create a form with both dicts
            form = forms.ImageAdminForm(post_dict, file_dict)
            # check whether the form is valid
            self.assertTrue(form.is_valid())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号