Beispiel #1
0
 def test_to_python_invalid(self):
     field = BytesField(name='asdf')
     field.encoding = 'adsf'
     with pytest.raises(TypeError):
         field.to_python(MockConfig(), 'asdf')
Beispiel #2
0
 def test_to_python_hex_valid(self):
     field = BytesField('hex')
     assert field.to_python(MockConfig(), 'deadbeef') == b'\xde\xad\xbe\xef'
Beispiel #3
0
 def test_to_python_hex_invalid(self):
     field = BytesField('hex')
     with pytest.raises(ValueError):
         field.to_python(MockConfig(), 'hello')
Beispiel #4
0
 def test_to_python_base64_valid(self):
     field = BytesField('base64')
     assert field.to_python(MockConfig(), base64.b64encode(b'hello').decode()) == b'hello'
Beispiel #5
0
 def test_to_python_not_str(self):
     field = BytesField(name='asdf')
     with pytest.raises(ValueError):
         field.to_python(MockConfig(), 100)
Beispiel #6
0
 def test_to_python_none(self):
     field = BytesField()
     assert field.to_python(MockConfig(), None) is None
Beispiel #7
0
 def test_to_python_base64_invalid(self):
     field = BytesField('base64')
     with pytest.raises(ValueError):
         field.to_python(None, 'hello')
Beispiel #8
0
 def test_to_python_none(self):
     field = BytesField()
     assert field.to_python(None, None) is None