Beispiel #1
0
 def test_to_python_not_str(self):
     field = BytesField(name='asdf')
     with pytest.raises(ValueError):
         field.to_python(MockConfig(), 100)
Beispiel #2
0
 def test_to_basic_hex(self):
     field = BytesField('hex')
     assert field.to_basic(MockConfig(), b'hello') == b'hello'.hex()
Beispiel #3
0
 def test_to_python_none(self):
     field = BytesField()
     assert field.to_python(MockConfig(), None) is None
Beispiel #4
0
 def test_to_basic_none(self):
     field = BytesField(name='asdf')
     field.to_basic(MockConfig(), None) is None
Beispiel #5
0
 def test_to_basic_base64(self):
     field = BytesField('base64')
     assert field.to_basic(MockConfig(), b'hello') == base64.b64encode(b'hello').decode()
Beispiel #6
0
 def test_to_python_hex_invalid(self):
     field = BytesField('hex')
     with pytest.raises(ValueError):
         field.to_python(MockConfig(), 'hello')
Beispiel #7
0
 def test_to_basic_none(self):
     field = BytesField(name='asdf')
     field.to_basic(None, None) is None
Beispiel #8
0
 def test_init_invalid_encoding(self):
     with pytest.raises(TypeError):
         BytesField('asdf')
Beispiel #9
0
 def test_validate_str(self):
     field = BytesField()
     field._validate(MockConfig(), 'hello') == b'hello'
Beispiel #10
0
 def test_to_python_base64_invalid(self):
     field = BytesField('base64')
     with pytest.raises(ValueError):
         field.to_python(None, 'hello')
Beispiel #11
0
 def test_init_valid_encoding(self):
     field = BytesField('hex')
     assert field.encoding == 'hex'
Beispiel #12
0
 def test_to_python_none(self):
     field = BytesField()
     assert field.to_python(None, None) is None
Beispiel #13
0
 def test_to_basic_invalid(self):
     field = BytesField(name='asdf')
     field.encoding = 'adsf'
     with pytest.raises(TypeError):
         field.to_basic(None, 'asdf')
Beispiel #14
0
 def test_to_basic_hex(self):
     field = BytesField('hex')
     assert field.to_basic(None, b'hello') == b'hello'.hex()
Beispiel #15
0
 def test_to_python_base64_valid(self):
     field = BytesField('base64')
     assert field.to_python(MockConfig(), base64.b64encode(b'hello').decode()) == b'hello'
Beispiel #16
0
 def test_validate_bytes(self):
     field = BytesField()
     assert field._validate(None, b'hello') == b'hello'
Beispiel #17
0
 def test_to_python_hex_valid(self):
     field = BytesField('hex')
     assert field.to_python(MockConfig(), 'deadbeef') == b'\xde\xad\xbe\xef'
Beispiel #18
0
 def test_validate_invalid_type(self):
     field = BytesField(name='asdf')
     with pytest.raises(ValueError):
         field._validate(MockConfig(), 100)
Beispiel #19
0
 def test_to_python_invalid(self):
     field = BytesField(name='asdf')
     field.encoding = 'adsf'
     with pytest.raises(TypeError):
         field.to_python(MockConfig(), 'asdf')
Beispiel #20
0
 def test_validate_str(self):
     field = BytesField()
     field._validate(None, 'hello') == b'hello'