Skip to content

Commit 6b29de8

Browse files
committed
Test b64 decoding
1 parent db1e6bf commit 6b29de8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/test_server_fields.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from labthings.server import fields
33

44
from marshmallow import ValidationError
5+
from base64 import b64encode
56
import pickle
67

78
import pytest
89

910

10-
def test_bytes_in_schema():
11+
def test_bytes_encode():
1112
test_schema = schema.Schema.from_dict({"b": fields.Bytes()})()
1213

1314
obj = type("obj", (object,), {"b": pickle.dumps(object())})
@@ -17,6 +18,23 @@ def test_bytes_in_schema():
1718
}
1819

1920

21+
def test_bytes_decode():
22+
test_schema = schema.Schema.from_dict({"b": fields.Bytes()})()
23+
24+
data = {"b": pickle.dumps(object())}
25+
26+
assert test_schema.load(data) == data
27+
28+
29+
def test_bytes_decode_string():
30+
test_schema = schema.Schema.from_dict({"b": fields.Bytes()})()
31+
32+
data = {"b": pickle.dumps(object())}
33+
encoded_data = {"b": b64encode(data["b"]).decode()}
34+
35+
assert test_schema.load(encoded_data) == data
36+
37+
2038
def test_bytes_validate():
2139
assert fields.Bytes()._validate(pickle.dumps(object())) is None
2240

0 commit comments

Comments
 (0)