Skip to content

Commit 26cb16a

Browse files
committed
Temporarily removed CBOR encoding support
1 parent 334539b commit 26cb16a

File tree

6 files changed

+1
-89
lines changed

6 files changed

+1
-89
lines changed

poetry.lock

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ flask-cors = "^3.0.8"
2121
gevent = ">=1.4,<21.0"
2222
gevent-websocket = "^0.10.1"
2323
zeroconf = ">=0.24.5,<0.28.0"
24-
cbor2 = "^5.1.0"
2524

2625
[tool.poetry.dev-dependencies]
2726
pytest = "^5.4"

src/labthings/representations.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from flask.json import JSONEncoder
55
from base64 import b64encode
66
import json
7-
import cbor2
87

98

109
from .utilities import PY3
@@ -51,24 +50,6 @@ def output_json(data, code, headers=None):
5150
return resp
5251

5352

54-
def encode_cbor(data, **settings):
55-
"""Makes CBOR encoded data using the default CBOR encoder"""
56-
return cbor2.dumps(data, **settings)
57-
58-
59-
def output_cbor(data, code, headers=None):
60-
"""Makes a Flask response with a CBOR encoded body, using app CBOR settings"""
61-
62-
settings = current_app.config.get("LABTHINGS_CBOR", {})
63-
dumped = encode_cbor(data, **settings)
64-
65-
resp = make_response(dumped, code)
66-
resp.headers.extend(headers or {})
67-
resp.mimetype = "application/cbor"
68-
return resp
69-
70-
7153
DEFAULT_REPRESENTATIONS = [
7254
("application/json", output_json),
73-
("application/cbor", output_cbor),
7455
]

tests/conftest.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ def open(self, *args, **kwargs):
7777
return super().open(*args, **kwargs)
7878

7979

80-
class CborClient(FlaskClient):
81-
def open(self, *args, **kwargs):
82-
kwargs.setdefault(
83-
"headers",
84-
{"Content-Type": "application/json", "Accept": "application/cbor"},
85-
)
86-
kwargs.setdefault("content_type", "application/json")
87-
return super().open(*args, **kwargs)
88-
89-
9080
class SocketClient(FlaskClient):
9181
def __init__(self, app, response_wrapper, *args, **kwargs):
9282
super().__init__(app, response_wrapper, *args, **kwargs)
@@ -276,12 +266,6 @@ def debug_client(debug_app):
276266
return debug_app.test_client()
277267

278268

279-
@pytest.fixture
280-
def cbor_client(app):
281-
app.test_client_class = CborClient
282-
return app.test_client()
283-
284-
285269
@pytest.fixture
286270
def text_client(app):
287271
return app.test_client()

tests/test_server_representations.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from labthings.server import representations
22
from flask import Response
3-
import cbor2
43
import pytest
54
import pickle
65
import json
@@ -49,25 +48,3 @@ def test_pretty_output_json(app_ctx_debug):
4948
with app_ctx_debug.test_request_context():
5049
response = representations.output_json(data, 200)
5150
assert response.data == b'{\n "key": "value"\n}\n'
52-
53-
54-
def test_encode_cbor():
55-
data = {
56-
"key": "value",
57-
"blob": pickle.dumps(object()),
58-
}
59-
assert cbor2.loads(representations.encode_cbor(data)) == data
60-
61-
62-
def test_output_cbor(app_ctx):
63-
data = {
64-
"key": "value",
65-
"blob": pickle.dumps(object()),
66-
}
67-
68-
with app_ctx.test_request_context():
69-
response = representations.output_cbor(data, 200)
70-
assert isinstance(response, Response)
71-
assert response.status_code == 200
72-
assert response.headers.get("Content-Type") == "application/cbor"
73-
assert cbor2.loads(response.data) == data

tests/test_server_view.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from flask import make_response
55

66
import json
7-
import cbor2
87

98
import pytest
109

@@ -67,20 +66,6 @@ def get(self):
6766
assert json.loads(res.data) == {"key": "value"}
6867

6968

70-
def test_accept_default_application_cbor(app, cbor_client):
71-
class Index(view.View):
72-
def get(self):
73-
return {"key": "value"}
74-
75-
app.add_url_rule("/", view_func=Index.as_view("index"))
76-
77-
with cbor_client:
78-
res = cbor_client.get("/")
79-
assert res.status_code == 200
80-
assert res.content_type == "application/cbor"
81-
assert cbor2.loads(res.data) == {"key": "value"}
82-
83-
8469
def test_return_response(app, client):
8570
class Index(view.View):
8671
def get(self):

0 commit comments

Comments
 (0)