Browse Source

hotfix: tests for python 3.8

pull/13760/head
WrldEngine 4 weeks ago
parent
commit
cdc85ba280
  1. 35
      tests/test_bsonjs_response_class.py

35
tests/test_bsonjs_response_class.py

@ -1,33 +1,28 @@
import json
import pytest
import sys
# Because of python 3.8 doesn't support this library
try:
import bsonjs # type: ignore
except ImportError: # pragma: nocover
bsonjs = None
from fastapi import FastAPI
from fastapi.responses import BSONJSResponse
from fastapi.testclient import TestClient
app = FastAPI(default_response_class=BSONJSResponse)
@app.get("/bsonjs_keys")
def get_bsonjs_serialized_data():
return {"key": "Hello World", 1: 1}
@pytest.mark.skipif(
sys.version_info < (3, 9), reason="requires minimum python3.9 or higher"
)
def test_bsonjs_serialized_data():
import bsonjs
from fastapi import FastAPI
from fastapi.responses import BSONJSResponse
from fastapi.testclient import TestClient
client = TestClient(app)
app = FastAPI(default_response_class=BSONJSResponse)
@app.get("/bsonjs_keys")
def get_bsonjs_serialized_data():
return {"key": "Hello World"}
def test_bsonjs_serialized_data():
client = TestClient(app)
with client:
response = client.get("/bsonjs_keys")
if bsonjs is not None:
assert response.content == bsonjs.loads(
json.dumps({"key": "Hello World", 1: 1})
)
assert True

Loading…
Cancel
Save