fix headers for fastapi 0.65.2+
This commit is contained in:
@ -24,7 +24,7 @@ pytest
|
||||
pytest-cov
|
||||
codecov
|
||||
pytest-asyncio
|
||||
fastapi<=0.65.1
|
||||
fastapi
|
||||
flake8
|
||||
flake8-black
|
||||
flake8-bugbear
|
||||
|
||||
@ -20,6 +20,8 @@ database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||
metadata = sqlalchemy.MetaData()
|
||||
app.state.database = database
|
||||
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup() -> None:
|
||||
@ -82,7 +84,9 @@ def test_read_main():
|
||||
client = TestClient(app)
|
||||
with client as client:
|
||||
response = client.post(
|
||||
"/things", data=json.dumps({"bt": base64.b64encode(blob3).decode()})
|
||||
"/things",
|
||||
data=json.dumps({"bt": base64.b64encode(blob3).decode()}),
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
response = client.get("/things")
|
||||
|
||||
@ -16,6 +16,8 @@ metadata = sqlalchemy.MetaData()
|
||||
database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||
app.state.database = database
|
||||
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup() -> None:
|
||||
@ -151,7 +153,9 @@ def test_saving_related_in_fastapi():
|
||||
},
|
||||
],
|
||||
}
|
||||
response = client.post("/departments/", data=json.dumps(payload))
|
||||
response = client.post(
|
||||
"/departments/", data=json.dumps(payload), headers=headers
|
||||
)
|
||||
department = Department(**response.json())
|
||||
|
||||
assert department.id is not None
|
||||
|
||||
@ -15,6 +15,8 @@ metadata = sqlalchemy.MetaData()
|
||||
database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||
app.state.database = database
|
||||
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup() -> None:
|
||||
@ -106,7 +108,9 @@ def test_queries():
|
||||
wrong_category = {"name": "Test category2", "posts": [{"title": "Test Post"}]}
|
||||
|
||||
# cannot add posts if skipped, will be ignored (with extra=ignore by default)
|
||||
response = client.post("/categories/", data=json.dumps(wrong_category))
|
||||
response = client.post(
|
||||
"/categories/", data=json.dumps(wrong_category), headers=headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
response = client.get("/categories/")
|
||||
assert response.status_code == 200
|
||||
@ -115,7 +119,9 @@ def test_queries():
|
||||
assert categories[0] is not None
|
||||
assert categories[0].name == "Test category2"
|
||||
|
||||
response = client.post("/categories/", data=json.dumps(right_category))
|
||||
response = client.post(
|
||||
"/categories/", data=json.dumps(right_category), headers=headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = client.get("/categories/")
|
||||
@ -129,7 +135,7 @@ def test_queries():
|
||||
"author": {"first_name": "John", "last_name": "Smith"},
|
||||
"categories": [{"name": "New cat"}],
|
||||
}
|
||||
response = client.post("/posts/", data=json.dumps(right_post))
|
||||
response = client.post("/posts/", data=json.dumps(right_post), headers=headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
Category.__config__.extra = "allow"
|
||||
|
||||
Reference in New Issue
Block a user