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 = ()
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')
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'), )
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)
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')