def test_max_size(self): validator = MaxSizeValidator(5) for char in 'hello': validator(char) self.assertRaises(ValidationError, validator, 'x')
def test_max_size_validator_normal(): validator = MaxSizeValidator(5) for char in 'hello': validator(char) with pytest.raises(ValidationError): validator('x')
def test_total_size_validator(self): target = ValueTarget(validator=MaxSizeValidator(10)) self.assertEqual(target.value, b'') target.start() target.data_received(b'hello') target.data_received(b' ') self.assertRaises(ValidationError, target.data_received, b'world')
def test_value_target_total_size_validator(): target = ValueTarget(validator=MaxSizeValidator(10)) assert target.value == b'' target.start() target.data_received(b'hello') target.data_received(b' ') with pytest.raises(ValidationError): target.data_received(b'world')
def test_file_target_exceeds_max_size(self): data = b'''\ --1234 Content-Disposition: form-data; name="files"; filename="ab.txt" Foo --1234--'''.replace(b'\n', b'\r\n') target = FileTarget('/tmp/file.txt', validator=MaxSizeValidator(1)) parser = StreamingFormDataParser( headers={'Content-Type': 'multipart/form-data; boundary=1234'}) parser.register('files', target) self.assertRaises(ValidationError, parser.data_received, data) self.assertTrue(target._started) self.assertTrue(target._finished)
def test_target_exceeds_max_size(): data = b'''\ --1234 Content-Disposition: form-data; name="files"; filename="ab.txt" Foo --1234--'''.replace(b'\n', b'\r\n') target = ValueTarget(validator=MaxSizeValidator(1)) parser = StreamingFormDataParser( headers={'Content-Type': 'multipart/form-data; boundary=1234'}) parser.register('files', target) with pytest.raises(ValidationError): parser.data_received(data) assert target._started assert target._finished
def test_max_size_validator_empty_input(): validator = MaxSizeValidator(0) with pytest.raises(ValidationError): validator('x')