Skip to content

Commit 6926cdb

Browse files
committed
Fixed bytes encoding tests
1 parent aaf25c9 commit 6926cdb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tests/test_server_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_bytes_encode():
1414
obj = type("obj", (object,), {"b": pickle.dumps(object())})
1515

1616
assert test_schema.dump(obj) == {
17-
"b": b"\x80\x04\x95\x1a\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x06object\x94\x93\x94)\x81\x94.",
17+
"b": obj.b,
1818
}
1919

2020

tests/test_server_representations.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import cbor2
44
import pytest
55
import pickle
6+
import json
7+
from base64 import b64encode
68

79

810
@pytest.fixture
@@ -20,10 +22,11 @@ def test_encode_json(labthings_json_encoder):
2022
"key": "value",
2123
"blob": pickle.dumps(object()),
2224
}
23-
assert (
24-
representations.encode_json(data, encoder=labthings_json_encoder)
25-
== '{"key": "value", "blob": "gASVGgAAAAAAAACMCGJ1aWx0aW5zlIwGb2JqZWN0lJOUKYGULg=="}\n'
26-
)
25+
26+
out = representations.encode_json(data, encoder=labthings_json_encoder)
27+
out_dict = json.loads(out)
28+
assert "blob" in out_dict
29+
assert isinstance(out_dict.get("blob"), str)
2730

2831

2932
def test_output_json(app_ctx):

0 commit comments

Comments
 (0)