Example #1
0
class Attending(gateaux.Structure):
    '''Stores which student is attending which class'''
    key = (gateaux.StringField(name='student',
                               help_text='Name of the student'),
           gateaux.StringField(name='class',
                               help_text='Class the student is attending'))
    value = ()
Example #2
0
 def test_validation(self) -> None:
     field = gateaux.StringField()
     self.assertEqual(field.pack('test'), 'test')
     field = gateaux.StringField(max_length=3)
     self.assertEqual(field.max_length, 3)
     with self.assertRaises(gateaux.errors.ValidationError):
         field.pack('test')
Example #3
0
class ClassAvailability(gateaux.Structure):
    '''Stores the number of available seats for a class'''
    key = (gateaux.StringField(name='name', help_text='Name of the class'), )
    value = (gateaux.IntegerField(name='seats',
                                  help_text='Number of available seats'), )
Example #4
0
 def test_constructor(self) -> None:
     field = gateaux.StringField()
     self.assertEqual(field.max_length, None)
     field = gateaux.StringField(max_length=12345)
     self.assertEqual(field.max_length, 12345)
Example #5
0
 def test_unpack(self) -> None:
     field = gateaux.StringField()
     with self.assertRaises(gateaux.errors.ValidationError):
         field.unpack(b'not str') # type: ignore
     self.assertEqual(field.unpack('test'), 'test')