Skip to content

Commit

Permalink
chore: update package; add example
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Nov 10, 2023
1 parent 0a4e19a commit 8f498a1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
74 changes: 72 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
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"
Expand All @@ -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"
19 changes: 19 additions & 0 deletions tests/basic.py
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)

0 comments on commit 8f498a1

Please sign in to comment.