Example #1
0
    def test_intAttribute_isAnInt(self):
        data = self.form_data.copy()
        data['pageNumber'] = "1"
        with open('fixtures/image1.jpg', 'rb') as img:
            image = SimpleUploadedFile(img.name, img.read(), content_type='image/jpeg')

        form = BookForm(data, {'image': image})
        self.assertTrue(form.is_valid())
Example #2
0
 def test_correctData(self):
     with open('fixtures/image1.jpg', 'rb') as img:
         image = SimpleUploadedFile(img.name, img.read(), content_type='image/jpeg')
     form = BookForm(self.form_data, {'image': image})
     for error in form.errors:
         print("Errors:")
         print(error)
     self.assertTrue(form.is_valid())
Example #3
0
    def test_missingAttribute(self):
        data = self.form_data.copy()

        for attrib in data.keys():
            if attrib in BookForm.base_fields.keys() and not BookForm.base_fields[attrib].required:
                continue
            # restore state
            data = self.form_data.copy()

            data[attrib] = ''
            form = BookForm(data)
            self.assertFalse(form.is_valid(), msg="Error at attribute: %s, empty string" % attrib)
Example #4
0
    def test_intAttribute_isNotAnInt(self):
        data = self.form_data.copy()
        data['pageNumber'] = "NotAnInt"

        form = BookForm(data=data)
        self.assertFalse(form.is_valid())