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