Exemple #1
0
    def test_fields_notrequired_empty(self):
        """Not required fields should accept empty values"""

        testfield = CharField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), '')

        testfield = TextField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), '')

        testfield = DateTimeField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), None)

        testfield = IntegerField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), None)
Exemple #2
0
    def test_fields_required(self):
        """Test fields with the required prop and ensure they validate"""

        testfield = CharField('Test', required=True)
        testfield.validate('test')
        self.assertEqual(testfield.prepare_data('test'), 'test')

        testfield = TextField('Test', required=True)
        testfield.validate('test')
        self.assertEqual(testfield.prepare_data('test'), 'test')

        testfield = DateTimeField('Test', required=True)
        date = datetime.today()
        date_sz = date.isoformat()
        testfield.validate(date_sz)
        self.assertEqual(testfield.prepare_data(date_sz), date)

        testfield = IntegerField('Test', required=True)
        testfield.validate('5')
        self.assertEqual(testfield.prepare_data('5'), 5)
Exemple #3
0
    def test_char_field(self):
        """Should be able to initialize charfield and set data"""

        testfield = CharField('Title')

        data = 'This is a sentence'

        try:
            testfield.validate(data)
        except InvalidField:
            self.fail('Field data is valid, exception should not have been thrown')

        self.assertEqual(testfield.to_json(data), 'This is a sentence')
        self.assertEqual(testfield.prepare_data(data), 'This is a sentence')