from typing import Annotated, Union
import pytest
-from dirty_equals import IsDict, IsOneOf, IsPartialDict
+from dirty_equals import IsOneOf, IsPartialDict
from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
client = TestClient(app)
response = client.post(path, json=json)
assert response.status_code == 422
- assert response.json() == IsDict(
- {
- "detail": [
- {
- "type": "missing",
- "loc": IsOneOf(["body", "p"], ["body"]),
- "msg": "Field required",
- "input": IsOneOf(None, {}),
- }
- ]
- }
- ) | IsDict(
- {
- "detail": [
- {
- "loc": IsOneOf(["body", "p"], ["body"]),
- "msg": "field required",
- "type": "value_error.missing",
- }
- ]
- }
- )
+ assert response.json() == {
+ "detail": [
+ {
+ "type": "missing",
+ "loc": IsOneOf(["body", "p"], ["body"]),
+ "msg": "Field required",
+ "input": IsOneOf(None, {}),
+ }
+ ]
+ }
@pytest.mark.parametrize(
from typing import Annotated
import pytest
-from dirty_equals import IsDict
from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
- "p": (
- IsDict(
- {
- "anyOf": [
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- },
- {"type": "null"},
- ],
- "title": "P",
- },
- )
- | IsDict(
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- "title": "P",
- },
- )
- )
+ "p": {
+ "type": "array",
+ "items": {"type": "string", "format": "binary"},
+ "title": "P",
+ },
},
"required": ["p"],
"title": body_model_name,
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
- "p_alias": (
- IsDict(
- {
- "anyOf": [
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- },
- {"type": "null"},
- ],
- "title": "P Alias",
- },
- )
- | IsDict(
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- "title": "P Alias",
- },
- )
- )
+ "p_alias": {
+ "type": "array",
+ "items": {"type": "string", "format": "binary"},
+ "title": "P Alias",
+ },
},
"required": ["p_alias"],
"title": body_model_name,
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
- "p_val_alias": (
- IsDict(
- {
- "anyOf": [
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- },
- {"type": "null"},
- ],
- "title": "P Val Alias",
- },
- )
- | IsDict(
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- "title": "P Val Alias",
- },
- )
- )
+ "p_val_alias": {
+ "type": "array",
+ "items": {"type": "string", "format": "binary"},
+ "title": "P Val Alias",
+ },
},
"required": ["p_val_alias"],
"title": body_model_name,
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
- "p_val_alias": (
- IsDict(
- {
- "anyOf": [
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- },
- {"type": "null"},
- ],
- "title": "P Val Alias",
- },
- )
- | IsDict(
- {
- "type": "array",
- "items": {"type": "string", "format": "binary"},
- "title": "P Val Alias",
- },
- )
- )
+ "p_val_alias": {
+ "type": "array",
+ "items": {"type": "string", "format": "binary"},
+ "title": "P Val Alias",
+ },
},
"required": ["p_val_alias"],
"title": body_model_name,
from typing import Annotated
import pytest
-from dirty_equals import IsDict, IsOneOf, IsPartialDict
+from dirty_equals import IsOneOf, IsPartialDict
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
- assert response.json() == IsDict(
- {
- "detail": [
- {
- "type": "missing",
- "loc": ["body", "p"],
- "msg": "Field required",
- "input": IsOneOf(None, {}),
- }
- ]
- }
- ) | IsDict(
- {
- "detail": [
- {
- "loc": ["body", "p"],
- "msg": "field required",
- "type": "value_error.missing",
- }
- ]
- }
- )
+ assert response.json() == {
+ "detail": [
+ {
+ "type": "missing",
+ "loc": ["body", "p"],
+ "msg": "Field required",
+ "input": IsOneOf(None, {}),
+ }
+ ]
+ }
@pytest.mark.parametrize(
from typing import Annotated
import pytest
-from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
+from dirty_equals import AnyThing, IsOneOf, IsPartialDict
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
- assert response.json() == IsDict(
- {
- "detail": [
- {
- "type": "missing",
- "loc": ["header", "p"],
- "msg": "Field required",
- "input": AnyThing,
- }
- ]
- }
- ) | IsDict(
- {
- "detail": [
- {
- "loc": ["header", "p"],
- "msg": "field required",
- "type": "value_error.missing",
- }
- ]
- }
- )
+ assert response.json() == {
+ "detail": [
+ {
+ "type": "missing",
+ "loc": ["header", "p"],
+ "msg": "Field required",
+ "input": AnyThing,
+ }
+ ]
+ }
@pytest.mark.parametrize(
from typing import Annotated
import pytest
-from dirty_equals import IsDict, IsOneOf
+from dirty_equals import IsOneOf
from fastapi import FastAPI, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
- assert response.json() == IsDict(
- {
- "detail": [
- {
- "type": "missing",
- "loc": ["query", "p"],
- "msg": "Field required",
- "input": IsOneOf(None, {}),
- }
- ]
- }
- ) | IsDict(
- {
- "detail": [
- {
- "loc": ["query", "p"],
- "msg": "field required",
- "type": "value_error.missing",
- }
- ]
- }
- )
+ assert response.json() == {
+ "detail": [
+ {
+ "type": "missing",
+ "loc": ["query", "p"],
+ "msg": "Field required",
+ "input": IsOneOf(None, {}),
+ }
+ ]
+ }
@pytest.mark.parametrize(