-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a4e19a
commit 8f498a1
Showing
3 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "fastapi-mock" | ||
version = "0.2.2" | ||
version = "0.2.3" | ||
authors = ["Ruslan Belckov <[email protected]>"] | ||
description = "A middleware for FastAPI that allows you to create mock endpoints quickly and easily." | ||
readme = "README.md" | ||
|
@@ -19,6 +19,9 @@ python = "^3.10" | |
fastapi = "^0.104.1" | ||
pydantic = "^2" | ||
|
||
[tool.poetry.group.test.dependencies] | ||
uvicorn = "^0.24.0.post1" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import datetime | ||
|
||
from fastapi import FastAPI | ||
from fastapi_mock import MockMiddleware, MockException | ||
from pydantic import BaseModel, Field | ||
|
||
app = FastAPI() | ||
|
||
app.add_middleware(MockMiddleware) # add middleware as class, not instance | ||
|
||
|
||
class ResponseModel(BaseModel): | ||
message: str = Field(..., example="Hello World!") | ||
|
||
|
||
@app.get("/mock-endpoint") | ||
def mock() -> ResponseModel: | ||
# instead of ResponseModel, you can use any type annotation that is supported by FastAPI Mock. | ||
raise MockException(ResponseModel, status_code=200) |