This file contains hidden or 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
| from fastapi.testclient import TestClient | |
| from app.main import app | |
| client = TestClient(app) | |
| def test_root(): | |
| response = client.get('/') | |
| data = response.json() | |
| assert response.status_code == 200 |
This file contains hidden or 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
| from fastapi import FastAPI | |
| app = FastAPI(title='Hello') | |
| @app.get('/') | |
| def root(): | |
| return {'service': 'Hello World', 'docs_url': '/docs'} |
This file contains hidden or 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
| ARG PORT=5000 | |
| FROM python:3.8-slim-buster AS base | |
| # Builder stage | |
| FROM base AS builder | |
| WORKDIR /wheels |
This file contains hidden or 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
| ARG PORT=5000 | |
| FROM python:3.8-slim-buster | |
| LABEL maintainer="Mohammed Mwijaa<mm.mwijaa@gmail.com>" | |
| ENV PYTHONUNBUFFERED 1 | |
| ENV PYTHONDONTWRITEBYTECODE 1 | |
| RUN apt-get update && \ |
This file contains hidden or 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
| from fastapi import FastAPI | |
| from .api.endpoints import router as todo_router | |
| from .database.utils import connect_mongo, disconnect_mongo | |
| app = FastAPI(title='Todos API') | |
| app.add_event_handler('startup', connect_mongo) | |
| app.add_event_handler('shutdown', disconnect_mongo) |
This file contains hidden or 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
| from fastapi import APIRouter, Depends, HTTPException, status | |
| from slugify import slugify | |
| from .crud import ( | |
| create_todo_by_slug, | |
| delete_todo_by_slug, | |
| get_all_todos, | |
| get_todo_by_slug, | |
| get_todo_or_404, | |
| update_todo_by_slug |
This file contains hidden or 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
| from datetime import datetime | |
| from fastapi import HTTPException, status | |
| from slugify import slugify | |
| from ..database.models import BaseTodo, TodoDoc | |
| from ..database.utils import AIOMC, todos_db, todos_coll | |
| async def get_all_todos(db: AIOMC): |
This file contains hidden or 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
| from datetime import datetime | |
| from enum import Enum | |
| from bson import ObjectId | |
| from pydantic import BaseConfig, BaseModel, Field | |
| from typing import List, Optional | |
| class Status(str, Enum): | |
| pending = 'pending' |
This file contains hidden or 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
| from fastapi import FastAPI | |
| from .database.utils import connect_mongo, disconnect_mongo | |
| app = FastAPI() | |
| app.add_event_handler('startup', connect_mongo) | |
| app.add_event_handler('shutdown', disconnect_mongo) | |
| @app.get('/') |
This file contains hidden or 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
| from motor.motor_asyncio import AsyncIOMotorClient as AIOMC | |
| DB_NAME = 'fastapi' | |
| MONGO_URI = f"mongodb://<user>:<password>@localhost:27017/{DB_NAME}?authSource=admin" | |
| todos_db = DB_NAME | |
| todos_coll = 'todos' | |
| class DB: |
NewerOlder