def test_valid_form(self):
"""
Checks whether the form validates correct data
"""
# open the image file
with open(self.image_path, 'rb') as upload_file:
# dict with valid values
post_dict = {
'position': 0,
'content_type': self.ctype.pk,
'object_id': 1
}
# dict with valid uploaded file
file_dict = {
# create an uploaded file object
# using opened image file
'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())
评论列表
文章目录