From c2166c052e9064b508e734503c42e827aca3e6a2 Mon Sep 17 00:00:00 2001 From: armantovmasyan Date: Sun, 10 Mar 2024 17:47:18 +0300 Subject: [PATCH] feat: app main skeleton done --- .github/workflows/linters.yml | 2 + alembic.ini | 110 ++++++++++++++++++ alembic/README | 1 + alembic/env.py | 93 +++++++++++++++ alembic/script.py.mako | 24 ++++ .../2024-03-10_d061ba67a828_gooder.py | 77 ++++++++++++ alembic/versions/b76de57d07d3_good_one.py | 74 ++++++++++++ requirements/prod.txt | 0 src/auth/base_config.py | 27 +++++ src/auth/manager.py | 51 ++++++++ src/auth/models.py | 16 +++ src/auth/schemas.py | 24 ++++ src/auth/utils.py | 10 ++ src/config.py | 12 ++ src/database.py | 22 ++++ src/main.py | 25 ++-- src/models.py | 0 src/polls/models.py | 40 +++++++ src/polls/router.py | 4 + src/polls/schemas.py | 20 ++++ .../base.txt => tests/auth/__init__.py | 0 .../dev.txt => tests/auth/test_routes.py | 0 tests/{ => test_http}/test_main.http | 0 23 files changed, 624 insertions(+), 8 deletions(-) create mode 100644 alembic.ini create mode 100644 alembic/README create mode 100644 alembic/env.py create mode 100644 alembic/script.py.mako create mode 100644 alembic/versions/2024-03-10_d061ba67a828_gooder.py create mode 100644 alembic/versions/b76de57d07d3_good_one.py delete mode 100644 requirements/prod.txt create mode 100644 src/auth/base_config.py create mode 100644 src/auth/manager.py create mode 100644 src/auth/models.py create mode 100644 src/auth/schemas.py create mode 100644 src/auth/utils.py delete mode 100644 src/models.py create mode 100644 src/polls/models.py create mode 100644 src/polls/router.py create mode 100644 src/polls/schemas.py rename requirements/base.txt => tests/auth/__init__.py (100%) rename requirements/dev.txt => tests/auth/test_routes.py (100%) rename tests/{ => test_http}/test_main.http (100%) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index e69de29..69e30c9 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -0,0 +1,2 @@ + on: + jobs: \ No newline at end of file diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 0000000..f8e1444 --- /dev/null +++ b/alembic.ini @@ -0,0 +1,110 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = alembic + +# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s +# Uncomment the line below if you want the files to be prepended with date and time +# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file +# for all available tokens +# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s + +# sys.path path, will be prepended to sys.path if present. +# defaults to the current working directory. +prepend_sys_path = . + +# timezone to use when rendering the date within the migration file +# as well as the filename. +# If specified, requires the python-dateutil library that can be +# installed by adding `alembic[tz]` to the pip requirements +# string value is passed to dateutil.tz.gettz() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; This defaults +# to alembic/versions. When using multiple version +# directories, initial revisions must be specified with --version-path. +# The path separator used here should be the separator specified by "version_path_separator" below. +# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions + +# version path separator; As mentioned above, this is the character used to split +# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. +# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. +# Valid values for version_path_separator are: +# +# version_path_separator = : +# version_path_separator = ; +# version_path_separator = space +version_path_separator = os # Use os.pathsep. Default configuration used for new projects. + +# set to 'true' to search source files recursively +# in each "version_locations" directory +# new in Alembic version 1.10 +# recursive_version_locations = false + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = postgresql+asyncpg://%(DB_USER)s:%(DB_PASS)s@%(DB_HOST)s:%(DB_PORT)s/%(DB_NAME)s?async_fallback=True + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks = black +# black.type = console_scripts +# black.entrypoint = black +# black.options = -l 79 REVISION_SCRIPT_FILENAME + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/alembic/README b/alembic/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/alembic/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 0000000..be4b139 --- /dev/null +++ b/alembic/env.py @@ -0,0 +1,93 @@ +from sqlalchemy import engine_from_config +from sqlalchemy import pool + +from alembic import context + +from src.config import DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER +from src.database import metadata, Base +from src.auth.models import * +from src.polls.models import * + +import sys +import os + +sys.path.append(os.path.join(sys.path[0], 'src')) + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +section = config.config_ini_section +config.set_section_option(section, "DB_HOST", DB_HOST) +config.set_section_option(section, "DB_NAME", DB_NAME) +config.set_section_option(section, "DB_PASS", DB_PASS) +config.set_section_option(section, "DB_PORT", DB_PORT) +config.set_section_option(section, "DB_USER", DB_USER) + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +# if config.config_file_name is not None: +# fileConfig(config.config_file_name) + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +target_metadata = [Base.metadata] + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def run_migrations_offline() -> None: + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online() -> None: + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + connectable = engine_from_config( + config.get_section(config.config_ini_section, {}), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, target_metadata=target_metadata + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/alembic/script.py.mako b/alembic/script.py.mako new file mode 100644 index 0000000..55df286 --- /dev/null +++ b/alembic/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} diff --git a/alembic/versions/2024-03-10_d061ba67a828_gooder.py b/alembic/versions/2024-03-10_d061ba67a828_gooder.py new file mode 100644 index 0000000..e1263f2 --- /dev/null +++ b/alembic/versions/2024-03-10_d061ba67a828_gooder.py @@ -0,0 +1,77 @@ +"""gooder + +Revision ID: d061ba67a828 +Revises: b76de57d07d3 +Create Date: 2024-03-10 14:55:51.897161 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd061ba67a828' +down_revision = 'b76de57d07d3' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(), nullable=False), + sa.Column('email', sa.String(), nullable=False), + sa.Column('hashed_password', sa.String(length=1024), nullable=False), + sa.Column('is_active', sa.Boolean(), nullable=False), + sa.Column('is_superuser', sa.Boolean(), nullable=False), + sa.Column('is_verified', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email'), + sa.UniqueConstraint('username') + ) + op.create_table('poll', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('title', sa.String(), nullable=False), + sa.Column('description', sa.String(), nullable=True), + sa.Column('created_by', sa.String(), nullable=False), + sa.Column('start_date', sa.TIMESTAMP(), nullable=True), + sa.Column('end_date', sa.TIMESTAMP(), nullable=False), + sa.ForeignKeyConstraint(['created_by'], ['user.username'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('title') + ) + op.create_table('question', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('poll_id', sa.Integer(), nullable=True), + sa.Column('question_text', sa.String(), nullable=False), + sa.ForeignKeyConstraint(['poll_id'], ['poll.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('choice', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('question_id', sa.Integer(), nullable=True), + sa.Column('choice_text', sa.String(), nullable=False), + sa.ForeignKeyConstraint(['question_id'], ['question.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('vote', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('choice_id', sa.Integer(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('vote_timestamp', sa.TIMESTAMP(), nullable=True), + sa.ForeignKeyConstraint(['choice_id'], ['choice.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('vote') + op.drop_table('choice') + op.drop_table('question') + op.drop_table('poll') + op.drop_table('user') + # ### end Alembic commands ### diff --git a/alembic/versions/b76de57d07d3_good_one.py b/alembic/versions/b76de57d07d3_good_one.py new file mode 100644 index 0000000..ae13205 --- /dev/null +++ b/alembic/versions/b76de57d07d3_good_one.py @@ -0,0 +1,74 @@ +"""good one + +Revision ID: b76de57d07d3 +Revises: f38e8c167b22 +Create Date: 2024-03-09 19:48:59.958385 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'b76de57d07d3' +down_revision = 'f38e8c167b22' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(), nullable=False), + sa.Column('email', sa.String(), nullable=False), + sa.Column('hashed_password', sa.String(length=1024), nullable=False), + sa.Column('is_active', sa.Boolean(), nullable=False), + sa.Column('is_superuser', sa.Boolean(), nullable=False), + sa.Column('is_verified', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('poll', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('title', sa.String(), nullable=False), + sa.Column('description', sa.String(), nullable=True), + sa.Column('created_by', sa.String(), nullable=False), + sa.Column('start_date', sa.TIMESTAMP(), nullable=True), + sa.Column('end_date', sa.TIMESTAMP(), nullable=False), + sa.ForeignKeyConstraint(['created_by'], ['user.username'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('title') + ) + op.create_table('question', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('poll_id', sa.Integer(), nullable=True), + sa.Column('question_text', sa.String(), nullable=False), + sa.ForeignKeyConstraint(['poll_id'], ['poll.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('choice', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('question_id', sa.Integer(), nullable=True), + sa.Column('choice_text', sa.String(), nullable=False), + sa.ForeignKeyConstraint(['question_id'], ['question.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('vote', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('choice_id', sa.Integer(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('vote_timestamp', sa.TIMESTAMP(), nullable=True), + sa.ForeignKeyConstraint(['choice_id'], ['choice.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('user') + op.drop_table('vote') + op.drop_table('choice') + op.drop_table('question') + op.drop_table('poll') + # ### end Alembic commands ### diff --git a/requirements/prod.txt b/requirements/prod.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/auth/base_config.py b/src/auth/base_config.py new file mode 100644 index 0000000..efef7f9 --- /dev/null +++ b/src/auth/base_config.py @@ -0,0 +1,27 @@ +from fastapi_users import FastAPIUsers +from fastapi_users.authentication import (AuthenticationBackend, + CookieTransport, JWTStrategy) + +from src.auth.manager import get_user_manager +from src.auth.models import User +from src.config import SECRET_AUTH + +cookie_transport = CookieTransport(cookie_name="bonds", cookie_max_age=3600) + + +def get_jwt_strategy() -> JWTStrategy: + return JWTStrategy(secret=SECRET_AUTH, lifetime_seconds=3600) + + +auth_backend = AuthenticationBackend( + name="jwt", + transport=cookie_transport, + get_strategy=get_jwt_strategy, +) + +fastapi_users = FastAPIUsers[User, int]( + get_user_manager, + [auth_backend], +) + +current_user = fastapi_users.current_user() diff --git a/src/auth/manager.py b/src/auth/manager.py new file mode 100644 index 0000000..12f67ed --- /dev/null +++ b/src/auth/manager.py @@ -0,0 +1,51 @@ +from typing import Optional + +from fastapi import Depends, Request +from fastapi_users import (BaseUserManager, IntegerIDMixin, exceptions, models, + schemas) + +from src.auth.models import User +from src.auth.utils import get_user_db +from src.config import SECRET_AUTH + + +class UserManager(IntegerIDMixin, BaseUserManager[User, int]): + reset_password_token_secret = SECRET_AUTH + verification_token_secret = SECRET_AUTH + + async def on_after_register(self, user: User, request: Optional[Request] = None): + # TODO: add email verification + print(f"User {user.id} has registered.") + + async def get_by_email(self, email: str) -> Optional[User]: + user = await super() + + async def create( + self, + user_create: schemas.UC, + safe: bool = False, + request: Optional[Request] = None, + ) -> models.UP: + await self.validate_password(user_create.password, user_create) + + existing_user = await self.user_db.get_by_email(user_create.email) + if existing_user is not None: + raise exceptions.UserAlreadyExists() + + user_dict = ( + user_create.create_update_dict() + if safe + else user_create.create_update_dict_superuser() + ) + password = user_dict.pop("password") + user_dict["hashed_password"] = self.password_helper.hash(password) + + created_user = await self.user_db.create(user_dict) + + await self.on_after_register(created_user, request) + + return created_user + + +async def get_user_manager(user_db=Depends(get_user_db)): + yield UserManager(user_db) diff --git a/src/auth/models.py b/src/auth/models.py new file mode 100644 index 0000000..cc003fb --- /dev/null +++ b/src/auth/models.py @@ -0,0 +1,16 @@ +from fastapi_users_db_sqlalchemy import SQLAlchemyBaseUserTable +from sqlalchemy import (Boolean, Column, Integer, + String) +from src.database import Base + + +class User(SQLAlchemyBaseUserTable[int], Base): + __tablename__ = "user" + + id = Column(Integer, primary_key=True) + username = Column(String, nullable=False, unique=True) + email = Column(String, nullable=False, unique=True) + hashed_password: str = Column(String(length=1024), nullable=False) + is_active: bool = Column(Boolean, default=True, nullable=False) + is_superuser: bool = Column(Boolean, default=False, nullable=False) + is_verified: bool = Column(Boolean, default=False, nullable=False) diff --git a/src/auth/schemas.py b/src/auth/schemas.py new file mode 100644 index 0000000..5b40ac7 --- /dev/null +++ b/src/auth/schemas.py @@ -0,0 +1,24 @@ +from typing import Optional + +from fastapi_users import schemas + + +class UserRead(schemas.BaseUser[int]): + id: int + username: str + email: str + is_active: bool = True + is_superuser: bool = False + is_verified: bool = False + + class Config: + orm_mode = True + + +class UserCreate(schemas.BaseUserCreate): + username: str + email: str + password: str + is_active: Optional[bool] = True + is_superuser: Optional[bool] = False + is_verified: Optional[bool] = False diff --git a/src/auth/utils.py b/src/auth/utils.py new file mode 100644 index 0000000..35ba6ea --- /dev/null +++ b/src/auth/utils.py @@ -0,0 +1,10 @@ +from fastapi import Depends +from fastapi_users_db_sqlalchemy import SQLAlchemyUserDatabase +from sqlalchemy.ext.asyncio import AsyncSession + +from src.auth.models import User +from src.database import get_async_session + + +async def get_user_db(session: AsyncSession = Depends(get_async_session)): + yield SQLAlchemyUserDatabase(session, User) diff --git a/src/config.py b/src/config.py index e69de29..ecd0684 100644 --- a/src/config.py +++ b/src/config.py @@ -0,0 +1,12 @@ +from dotenv import load_dotenv +import os + +load_dotenv() + +DB_HOST = os.environ.get("DB_HOST") +DB_PORT = os.environ.get("DB_PORT") +DB_NAME = os.environ.get("DB_NAME") +DB_USER = os.environ.get("DB_USER") +DB_PASS = os.environ.get("DB_PASS") + +SECRET_AUTH = os.environ.get("SECRET_AUTH") \ No newline at end of file diff --git a/src/database.py b/src/database.py index e69de29..1e1f8e9 100644 --- a/src/database.py +++ b/src/database.py @@ -0,0 +1,22 @@ +from typing import AsyncGenerator + +from sqlalchemy import MetaData +from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +from sqlalchemy.pool import NullPool + +from src.config import DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER + +DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}" +Base = declarative_base() + +metadata = MetaData() + +engine = create_async_engine(DATABASE_URL, poolclass=NullPool) +async_session_maker = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) + + +async def get_async_session() -> AsyncGenerator[AsyncSession, None]: + async with async_session_maker() as session: + yield session diff --git a/src/main.py b/src/main.py index 6d7c6d9..9a15690 100644 --- a/src/main.py +++ b/src/main.py @@ -1,13 +1,22 @@ from fastapi import FastAPI +from src.polls.router import router as router_polls +from src.auth.base_config import fastapi_users, auth_backend +from src.auth.schemas import UserCreate, UserRead -app = FastAPI() +app = FastAPI( + title="Voting System" +) +app.include_router( + fastapi_users.get_auth_router(auth_backend), + prefix="/auth", + tags=["Auth"] +) -@app.get("/") -async def root(): - return {"message": "Hello World"} +app.include_router( + fastapi_users.get_register_router(UserRead, UserCreate), + prefix="/auth", + tags=["Auth"] +) - -@app.get("/hello/{name}") -async def say_hello(name: str): - return {"message": f"Hello {name}"} +app.include_router(router_polls) diff --git a/src/models.py b/src/models.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/polls/models.py b/src/polls/models.py new file mode 100644 index 0000000..ed323c8 --- /dev/null +++ b/src/polls/models.py @@ -0,0 +1,40 @@ +from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey +from src.database import Base + +import datetime + + +class Poll(Base): + __tablename__ = "poll" + + id = Column("id", Integer, primary_key=True) + title = Column("title", String, nullable=False, unique=True) + description = Column("description", String) + created_by = Column("created_by", String, ForeignKey("user.username"), nullable=False) + start_date = Column("start_date", TIMESTAMP, default=datetime.datetime.now()) + end_date = Column("end_date", TIMESTAMP, nullable=False) + + +class Question(Base): + __tablename__ = "question" + + id = Column("id", Integer, primary_key=True) + poll_id = Column("poll_id", Integer, ForeignKey("poll.id")) + question_text = Column("question_text", String, nullable=False) + + +class Choice(Base): + __tablename__ = "choice" + + id = Column("id", Integer, primary_key=True) + question_id = Column("question_id", Integer, ForeignKey("question.id")) + choice_text = Column("choice_text", String, nullable=False) + + +class Vote(Base): + __tablename__ = "vote" + + id = Column("id", Integer, primary_key=True) + choice_id = Column("choice_id", Integer, ForeignKey("choice.id")) + user_id = Column("user_id", Integer, ForeignKey("user.id")) + vote_timestamp = Column("vote_timestamp", TIMESTAMP) diff --git a/src/polls/router.py b/src/polls/router.py new file mode 100644 index 0000000..c05a0f0 --- /dev/null +++ b/src/polls/router.py @@ -0,0 +1,4 @@ +from fastapi import APIRouter + +router = APIRouter() + diff --git a/src/polls/schemas.py b/src/polls/schemas.py new file mode 100644 index 0000000..a69b5d0 --- /dev/null +++ b/src/polls/schemas.py @@ -0,0 +1,20 @@ +from pydantic import BaseModel, constr, FutureDatetime + + +class CreatePoll(BaseModel): + id: int + title: constr(min_length=5, max_length=60) + description: str + end_date: FutureDatetime # 2024-03-09 18:56:03.085849 + + +class CreateQuestion(BaseModel): + id: int + question_text: constr(min_length=1, max_length=40) + + +class CreateChoice(BaseModel): + id: int + choice_text: constr(min_length=1, max_length=20) + + diff --git a/requirements/base.txt b/tests/auth/__init__.py similarity index 100% rename from requirements/base.txt rename to tests/auth/__init__.py diff --git a/requirements/dev.txt b/tests/auth/test_routes.py similarity index 100% rename from requirements/dev.txt rename to tests/auth/test_routes.py diff --git a/tests/test_main.http b/tests/test_http/test_main.http similarity index 100% rename from tests/test_main.http rename to tests/test_http/test_main.http