diff --git a/alembic/versions/b508b9e595d0_language_unique_true.py b/alembic/versions/b508b9e595d0_language_unique_true.py new file mode 100644 index 0000000..ab62ca7 --- /dev/null +++ b/alembic/versions/b508b9e595d0_language_unique_true.py @@ -0,0 +1,32 @@ +"""language unique true + +Revision ID: b508b9e595d0 +Revises: c291b9a2fbe5 +Create Date: 2024-06-22 01:32:34.346560 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b508b9e595d0' +down_revision = 'c291b9a2fbe5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('locale', schema=None) as batch_op: + batch_op.create_unique_constraint('language_unique_constraint', ['language']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('locale', schema=None) as batch_op: + batch_op.drop_constraint('language_unique_constraint', type_='unique') + + # ### end Alembic commands ### diff --git a/alembic/versions/c291b9a2fbe5_locale_models.py b/alembic/versions/c291b9a2fbe5_locale_models.py new file mode 100644 index 0000000..16ddf12 --- /dev/null +++ b/alembic/versions/c291b9a2fbe5_locale_models.py @@ -0,0 +1,182 @@ +"""locale models + +Revision ID: c291b9a2fbe5 +Revises: 132f5d88e682 +Create Date: 2024-06-19 22:04:55.856481 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'c291b9a2fbe5' +down_revision = '132f5d88e682' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('locale', + sa.Column('language', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('auth', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('welcome', sa.String(), nullable=False), + sa.Column('auth_title1', sa.String(), nullable=False), + sa.Column('auth_title2', sa.String(), nullable=False), + sa.Column('forgot_password', sa.String(), nullable=False), + sa.Column('enter', sa.String(), nullable=False), + sa.Column('register_', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('common', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('all_notification', sa.String(), nullable=False), + sa.Column('profile', sa.String(), nullable=False), + sa.Column('ok', sa.String(), nullable=False), + sa.Column('exit', sa.String(), nullable=False), + sa.Column('cancel', sa.String(), nullable=False), + sa.Column('main', sa.String(), nullable=False), + sa.Column('tasks', sa.String(), nullable=False), + sa.Column('subscription', sa.String(), nullable=False), + sa.Column('account', sa.String(), nullable=False), + sa.Column('notifications', sa.String(), nullable=False), + sa.Column('help', sa.String(), nullable=False), + sa.Column('contacts', sa.String(), nullable=False), + sa.Column('email', sa.String(), nullable=False), + sa.Column('email_placeholder', sa.String(), nullable=False), + sa.Column('login', sa.String(), nullable=False), + sa.Column('login_placeholder', sa.String(), nullable=False), + sa.Column('password', sa.String(), nullable=False), + sa.Column('password_placeholder', sa.String(), nullable=False), + sa.Column('message', sa.String(), nullable=False), + sa.Column('message_placeholder', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('contacts', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('support', sa.String(), nullable=False), + sa.Column('text', sa.String(), nullable=False), + sa.Column('our_contacts', sa.String(), nullable=False), + sa.Column('phones', sa.String(), nullable=False), + sa.Column('phone1', sa.String(), nullable=False), + sa.Column('phone2', sa.String(), nullable=False), + sa.Column('select_label', sa.String(), nullable=False), + sa.Column('select_placeholder', sa.String(), nullable=False), + sa.Column('select_option1', sa.String(), nullable=False), + sa.Column('select_option2', sa.String(), nullable=False), + sa.Column('select_option3', sa.String(), nullable=False), + sa.Column('email_placeholder', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('errors', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('incorect_email', sa.String(), nullable=False), + sa.Column('required_email', sa.String(), nullable=False), + sa.Column('required_login', sa.String(), nullable=False), + sa.Column('required_password', sa.String(), nullable=False), + sa.Column('requirement_password', sa.String(), nullable=False), + sa.Column('error400', sa.String(), nullable=False), + sa.Column('error409', sa.String(), nullable=False), + sa.Column('error500', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('header', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('modal_title', sa.String(), nullable=False), + sa.Column('modal_question', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('help', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('title', sa.String(), nullable=False), + sa.Column('questions', sa.String(), nullable=False), + sa.Column('write_us', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('main', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('title1', sa.String(), nullable=False), + sa.Column('text1', sa.String(), nullable=False), + sa.Column('text2', sa.String(), nullable=False), + sa.Column('text3', sa.String(), nullable=False), + sa.Column('title2', sa.String(), nullable=False), + sa.Column('text4', sa.String(), nullable=False), + sa.Column('button_text', sa.String(), nullable=False), + sa.Column('title3', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('restore', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('restore_password', sa.String(), nullable=False), + sa.Column('text', sa.String(), nullable=False), + sa.Column('button_text', sa.String(), nullable=False), + sa.Column('modal_title', sa.String(), nullable=False), + sa.Column('modal_agreements', sa.String(), nullable=False), + sa.Column('modal_option1', sa.String(), nullable=False), + sa.Column('modal_option2', sa.String(), nullable=False), + sa.Column('modal_option3', sa.String(), nullable=False), + sa.Column('modal_option4', sa.String(), nullable=False), + sa.Column('modal_check1', sa.String(), nullable=False), + sa.Column('modal_check2', sa.String(), nullable=False), + sa.Column('modal_check3', sa.String(), nullable=False), + sa.Column('modal_check4', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('subscription', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('button_text1', sa.String(), nullable=False), + sa.Column('button_text2', sa.String(), nullable=False), + sa.Column('button_text3', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('tasks', + sa.Column('locale_id', sa.Integer(), nullable=True), + sa.Column('breadcrumb', sa.String(), nullable=False), + sa.Column('loading', sa.String(), nullable=False), + sa.Column('button_text1', sa.String(), nullable=False), + sa.Column('button_text2', sa.String(), nullable=False), + sa.Column('button_text3', sa.String(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['locale_id'], ['locale.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('tasks') + op.drop_table('subscription') + op.drop_table('restore') + op.drop_table('main') + op.drop_table('help') + op.drop_table('header') + op.drop_table('errors') + op.drop_table('contacts') + op.drop_table('common') + op.drop_table('auth') + op.drop_table('locale') + # ### end Alembic commands ### diff --git a/app/api/endpoints/__init__.py b/app/api/endpoints/__init__.py index e3864a2..e6367a8 100644 --- a/app/api/endpoints/__init__.py +++ b/app/api/endpoints/__init__.py @@ -7,3 +7,4 @@ from .tariff import router as tariff_router # noqa from .task import router as task_router # noqa from .user import router as user_router # noqa +from .locale import router as locale_router # noqa diff --git a/app/api/endpoints/locale.py b/app/api/endpoints/locale.py new file mode 100644 index 0000000..9ad3382 --- /dev/null +++ b/app/api/endpoints/locale.py @@ -0,0 +1,50 @@ +from fastapi import APIRouter, Depends, status +from sqlalchemy.ext.asyncio import AsyncSession + +from app.core.db import get_async_session +from app.core.user import current_superuser +from app.schemas.locale import ( + LocaleCreate, LocaleReadByID, + LocaleRead, LocaleCreated +) +from app.crud import locale_crud + + +router = APIRouter() + + +@router.post( + '/', + response_model=LocaleCreated, + dependencies=[Depends(current_superuser)], + status_code=status.HTTP_201_CREATED +) +async def create_locale( + locale: LocaleCreate, + session: AsyncSession = Depends(get_async_session) +): + """Создать локаль.""" + return await locale_crud.create(locale=locale, session=session) + + +@router.get( + '/', + response_model=list[LocaleRead] +) +async def get_locales( + session: AsyncSession = Depends(get_async_session) +): + """Получить список доступных языков.""" + return await locale_crud.get_multi(session) + + +@router.get( + '/{locale_id}', + response_model=LocaleReadByID +) +async def get_locale_by_id( + locale_id: int, + session: AsyncSession = Depends(get_async_session) +): + """Получение локали по id.""" + return await locale_crud.get_by_id(locale_id, session) diff --git a/app/api/routers.py b/app/api/routers.py index fdba64c..f83d678 100644 --- a/app/api/routers.py +++ b/app/api/routers.py @@ -2,7 +2,7 @@ from app.api.endpoints import ( achievement_router, course_router, examination_router, group_router, - profile_router, tariff_router, task_router, user_router, + profile_router, tariff_router, task_router, user_router, locale_router ) main_router = APIRouter() @@ -21,3 +21,6 @@ main_router.include_router( profile_router, prefix='/profiles', tags=['Profiles'] ) +main_router.include_router( + locale_router, prefix='/locales', tags=['Locales'] +) diff --git a/app/crud/__init__.py b/app/crud/__init__.py index 527ec83..5df1aff 100644 --- a/app/crud/__init__.py +++ b/app/crud/__init__.py @@ -7,3 +7,4 @@ from .tariff import tariff_crud # noqa from .task import task_crud # noqa from .user import user_crud # noqa +from .locale import locale_crud # noqa diff --git a/app/crud/locale.py b/app/crud/locale.py new file mode 100644 index 0000000..101bd6c --- /dev/null +++ b/app/crud/locale.py @@ -0,0 +1,69 @@ +from sqlalchemy import select +from sqlalchemy.orm import selectinload +from sqlalchemy.ext.asyncio import AsyncSession +from app.crud.base import CRUDBase +from app.models import ( + Locale, Common, Header, Auth, Contacts, Help, Main, Restore, Subscription, + Tasks, Errors +) +from app.schemas.locale import LocaleCreate + + +class LocaleCRUD(CRUDBase): + async def create(self, locale: LocaleCreate, session: AsyncSession): + language = Locale(language=locale.language) + session.add(language) + await session.commit() + await session.refresh(language) + common_data = locale.common.model_dump() + common = Common(**common_data, locale_id=language.id) + header_data = locale.header.model_dump() + header = Header(**header_data, locale_id=language.id) + auth_data = locale.auth.model_dump() + auth = Auth(**auth_data, locale_id=language.id) + contacts_data = locale.contacts.model_dump() + contacts = Contacts(**contacts_data, locale_id=language.id) + help_data = locale.help.model_dump() + help_ = Help(**help_data, locale_id=language.id) + main_data = locale.main.model_dump() + main = Main(**main_data, locale_id=language.id) + restore_data = locale.restore.model_dump() + restore = Restore(**restore_data, locale_id=language.id) + subscription_data = locale.subscription.model_dump() + subscription = Subscription(**subscription_data, locale_id=language.id) + tasks_data = locale.tasks.model_dump() + tasks = Tasks(**tasks_data, locale_id=language.id) + errors_data = locale.errors.model_dump() + errors = Errors(**errors_data, locale_id=language.id) + session.add_all( + ( + common, header, auth, contacts, help_, main, + restore, subscription, tasks, errors + ) + ) + await session.commit() + await session.refresh(language) + return await self.get_by_id(language.id, session) + + async def get_by_id(self, id, session: AsyncSession): + stmt = ( + select(Locale) + .where(Locale.id == id) + .options( + selectinload(Locale.common), + selectinload(Locale.header), + selectinload(Locale.auth), + selectinload(Locale.contacts), + selectinload(Locale.help), + selectinload(Locale.main), + selectinload(Locale.restore), + selectinload(Locale.subscription), + selectinload(Locale.tasks), + selectinload(Locale.errors) + ) + ) + locale = await session.execute(stmt) + return locale.scalars().first() + + +locale_crud = LocaleCRUD(Locale) diff --git a/app/models/__init__.py b/app/models/__init__.py index 59b9338..bbcd472 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -7,3 +7,7 @@ from .tariff import Tariff # noqa from .task import Task # noqa from .user import User # noqa +from .locale import ( + Locale, Common, Header, Help, Auth, Subscription, Contacts, Main, + Restore, Tasks, Errors +) # noqa diff --git a/app/models/locale.py b/app/models/locale.py new file mode 100644 index 0000000..73be7b5 --- /dev/null +++ b/app/models/locale.py @@ -0,0 +1,170 @@ +from __future__ import annotations + +from sqlalchemy import ForeignKey, Integer +from sqlalchemy.orm import Mapped, mapped_column, relationship + +from app.core.db import Base + + +class Locale(Base): + language: Mapped[str] = mapped_column(unique=True) + common: Mapped[Common] = relationship(back_populates='locale') + header: Mapped[Header] = relationship(back_populates='locale') + auth: Mapped[Auth] = relationship(back_populates='locale') + contacts: Mapped[Contacts] = relationship(back_populates='locale') + help: Mapped[Help] = relationship(back_populates='locale') + main: Mapped[Main] = relationship(back_populates='locale') + restore: Mapped[Restore] = relationship(back_populates='locale') + subscription: Mapped[Subscription] = relationship(back_populates='locale') + tasks: Mapped[Tasks] = relationship(back_populates='locale') + errors: Mapped[Errors] = relationship(back_populates='locale') + + +class Common(Base): + all_notification: Mapped[str] + profile: Mapped[str] + ok: Mapped[str] + exit: Mapped[str] + cancel: Mapped[str] + main: Mapped[str] + tasks: Mapped[str] + subscription: Mapped[str] + account: Mapped[str] + notifications: Mapped[str] + help: Mapped[str] + contacts: Mapped[str] + email: Mapped[str] + email_placeholder: Mapped[str] + login: Mapped[str] + login_placeholder: Mapped[str] + password: Mapped[str] + password_placeholder: Mapped[str] + message: Mapped[str] + message_placeholder: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='common') + + +class Header(Base): + modal_title: Mapped[str] + modal_question: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='header') + + +class Auth(Base): + welcome: Mapped[str] + auth_title1: Mapped[str] + auth_title2: Mapped[str] + forgot_password: Mapped[str] + enter: Mapped[str] + register_: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='auth') + + +class Contacts(Base): + support: Mapped[str] + text: Mapped[str] + our_contacts: Mapped[str] + phones: Mapped[str] + phone1: Mapped[str] + phone2: Mapped[str] + select_label: Mapped[str] + select_placeholder: Mapped[str] + select_option1: Mapped[str] + select_option2: Mapped[str] + select_option3: Mapped[str] + email_placeholder: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='contacts') + + +class Help(Base): + title: Mapped[str] + questions: Mapped[str] + write_us: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='help') + + +class Main(Base): + title1: Mapped[str] + text1: Mapped[str] + text2: Mapped[str] + text3: Mapped[str] + title2: Mapped[str] + text4: Mapped[str] + button_text: Mapped[str] + title3: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='main') + + +class Restore(Base): + restore_password: Mapped[str] + text: Mapped[str] + button_text: Mapped[str] + modal_title: Mapped[str] + modal_agreements: Mapped[str] + modal_option1: Mapped[str] + modal_option2: Mapped[str] + modal_option3: Mapped[str] + modal_option4: Mapped[str] + modal_check1: Mapped[str] + modal_check2: Mapped[str] + modal_check3: Mapped[str] + modal_check4: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='restore') + + +class Subscription(Base): + button_text1: Mapped[str] + button_text2: Mapped[str] + button_text3: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='subscription') + + +class Tasks(Base): + breadcrumb: Mapped[str] + loading: Mapped[str] + button_text1: Mapped[str] + button_text2: Mapped[str] + button_text3: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='tasks') + + +class Errors(Base): + incorect_email: Mapped[str] + required_email: Mapped[str] + required_login: Mapped[str] + required_password: Mapped[str] + requirement_password: Mapped[str] + error400: Mapped[str] + error409: Mapped[str] + error500: Mapped[str] + locale_id = mapped_column( + Integer, ForeignKey('locale.id') + ) + locale: Mapped['Locale'] = relationship(back_populates='errors') diff --git a/app/schemas/locale.py b/app/schemas/locale.py new file mode 100644 index 0000000..40d0c6d --- /dev/null +++ b/app/schemas/locale.py @@ -0,0 +1,230 @@ +from pydantic import BaseModel, Field + + +class CommonCreate(BaseModel): + all_notification: str + profile: str + ok: str + exit: str + cancel: str + main: str + tasks: str + subscription: str + account: str + notifications: str + help: str + contacts: str + email: str + email_placeholder: str + login: str + login_placeholder: str + password: str + password_placeholder: str + message: str + message_placeholder: str + + +class CommonRead(CommonCreate): + all_notification: str = Field(serialization_alias='allNotification') + email_placeholder: str = Field(serialization_alias='emailPlaceholder') + login_placeholder: str = Field(serialization_alias='loginPlaceholder') + password_placeholder: str = Field( + serialization_alias='passwordPlaceholder' + ) + message_placeholder: str = Field(serialization_alias='messagePlaceholder') + + +class HeaderCreate(BaseModel): + modal_title: str + modal_question: str + + +class HeaderRead(HeaderCreate): + modal_title: str = Field(serialization_alias='modalTitle') + modal_question: str = Field(serialization_alias='modalQuestion') + + +class AuthCreate(BaseModel): + welcome: str + auth_title1: str + auth_title2: str + forgot_password: str + enter: str + register_: str + + +class AuthRead(AuthCreate): + auth_title1: str = Field(serialization_alias='authTitle1') + auth_title2: str = Field(serialization_alias='authTitle2') + forgot_password: str = Field(serialization_alias='forgotPassword') + register_: str = Field(serialization_alias='register') + + +class ContactsCreate(BaseModel): + support: str + text: str + our_contacts: str + phones: str + phone1: str + phone2: str + select_label: str + select_placeholder: str + select_option1: str + select_option2: str + select_option3: str + email_placeholder: str + + +class ContactsRead(ContactsCreate): + our_contacts: str = Field(serialization_alias='ourContacts') + select_label: str = Field(serialization_alias='selectLabel') + select_placeholder: str = Field(serialization_alias='selectPlaceholder') + select_option1: str = Field(serialization_alias='selectOption1') + select_option2: str = Field(serialization_alias='selectOption2') + select_option3: str = Field(serialization_alias='selectOption3') + email_placeholder: str = Field(serialization_alias='emailPlaceholder') + + +class HelpCreate(BaseModel): + title: str + questions: str + write_us: str + + +class HelpRead(HelpCreate): + write_us: str = Field(serialization_alias='writeUs') + + +class MainCreate(BaseModel): + title1: str + text1: str + text2: str + text3: str + title2: str + text4: str + button_text: str + title3: str + + +class MainRead(MainCreate): + button_text: str = Field(serialization_alias='buttonText') + + +class RestoreCreate(BaseModel): + restore_password: str + text: str + button_text: str + modal_title: str + modal_agreements: str + modal_option1: str + modal_option2: str + modal_option3: str + modal_option4: str + modal_check1: str + modal_check2: str + modal_check3: str + modal_check4: str + + +class RestoreRead(RestoreCreate): + restore_password: str = Field(serialization_alias='restorePassword') + button_text: str = Field(serialization_alias='buttonText') + modal_title: str = Field(serialization_alias='modalTitle') + modal_agreements: str = Field(serialization_alias='modalAgreements') + modal_option1: str = Field(serialization_alias='modalOption1') + modal_option2: str = Field(serialization_alias='modalOption2') + modal_option3: str = Field(serialization_alias='modalOption3') + modal_option4: str = Field(serialization_alias='modalOption4') + modal_check1: str = Field(serialization_alias='modalChek1') + modal_check2: str = Field(serialization_alias='modalChek2') + modal_check3: str = Field(serialization_alias='modalChek3') + modal_check4: str = Field(serialization_alias='modalChek4') + + +class SubscriptionCreate(BaseModel): + button_text1: str + button_text2: str + button_text3: str + + +class SubscriptionRead(SubscriptionCreate): + button_text1: str = Field(serialization_alias='buttonText1') + button_text2: str = Field(serialization_alias='buttonText2') + button_text3: str = Field(serialization_alias='buttonText3') + + +class TasksCreate(BaseModel): + breadcrumb: str + loading: str + button_text1: str + button_text2: str + button_text3: str + + +class TasksRead(TasksCreate): + button_text1: str = Field(serialization_alias='buttonText1') + button_text2: str = Field(serialization_alias='buttonText2') + button_text3: str = Field(serialization_alias='buttonText3') + + +class ErrorsCreate(BaseModel): + incorect_email: str + required_email: str + required_login: str + required_password: str + requirement_password: str + error400: str + error409: str + error500: str + + +class ErrorsRead(ErrorsCreate): + incorect_email: str = Field(serialization_alias='incorectEmail') + required_email: str = Field(serialization_alias='requiredEmail') + required_login: str = Field(serialization_alias='requiredLogin') + required_password: str = Field(serialization_alias='requiredPassword') + requirement_password: str = Field( + serialization_alias='requirementPassword' + ) + + +class LocaleCreate(BaseModel): + language: str + common: CommonCreate + header: HeaderCreate + auth: AuthCreate + contacts: ContactsCreate + help: HelpCreate + main: MainCreate + restore: RestoreCreate + subscription: SubscriptionCreate + tasks: TasksCreate + errors: ErrorsCreate + + +class LocaleCreated(LocaleCreate): + id: int + + class Config: + from_attributes = True + + +class LocaleRead(BaseModel): + id: int + language: str + + class Config: + from_attributes = True + + +class LocaleReadByID(BaseModel): + common: CommonRead + header: HeaderRead + auth: AuthRead + contacts: ContactsRead + help: HelpRead + main: MainRead + restore: RestoreRead + subscription: SubscriptionRead + tasks: TasksRead + errors: ErrorsRead diff --git a/tests/test_locale.py b/tests/test_locale.py new file mode 100644 index 0000000..a0d65a4 --- /dev/null +++ b/tests/test_locale.py @@ -0,0 +1,213 @@ +from fastapi import status, Response +from fastapi.testclient import TestClient + +from app.models import Locale + +from .utils import get_obj_count + + +CREATE_SCHEME = { + 'language': 'en', + 'common': { + 'allNotification': 'privet', + 'profile': 'privet', + 'ok': 'privet', + 'exit': 'privet', + 'cancel': 'privet', + 'main': 'privet', + 'tasks': 'privet', + 'subscription': 'privet', + 'account': 'privet', + 'notifications': 'privet', + 'help': 'privet', + 'contacts': 'privet', + 'email': 'privet', + 'emailPlaceholder': 'privet', + 'login': 'privet', + 'loginPlaceholder': 'privet', + 'password': 'privet', + 'passwordPlaceholder': 'privet', + 'message': 'privet', + 'messagePlaceholder': 'privet' + }, + 'header': { + 'modalTitle': 'privet', + 'modalQuestion': 'privet', + }, + 'auth': { + 'welcome': 'privet', + 'authTitle1': 'privet', + 'authTitle2': 'privet', + 'forgotPassword': 'privet', + 'enter': 'privet', + 'register': 'privet', + }, + 'contacts': { + 'support': 'privet', + 'text': 'privet', + 'ourContacts': 'privet', + 'phones': 'privet', + 'phone1': 'privet', + 'phone2': 'privet', + 'selectLabel': 'privet', + 'selectPlaceholder': 'privet', + 'selectOption1': 'privet', + 'selectOption2': 'privet', + 'selectOption3': 'privet', + 'emailPlaceholder': 'privet', + }, + 'help': { + 'title': 'privet', + 'questions': 'privet', + 'writeUs': 'privet', + }, + 'main': { + 'title1': 'privet', + 'text1': 'privet', + 'text2': 'privet', + 'text3': 'privet', + 'title2': 'privet', + 'text4': 'privet', + 'buttonText': 'privet', + 'title3': 'privet', + }, + 'restore': { + 'restorePassword': 'privet', + 'text': 'privet', + 'buttonText': 'privet', + 'modalTitle': 'privet', + 'modalAgreements': 'privet', + 'modalOption1': 'privet', + 'modalOption2': 'privet', + 'modalOption3': 'privet', + 'modalOption4': 'privet', + 'modalCheck1': 'privet', + 'modalCheck2': 'privet', + 'modalCheck3': 'privet', + 'modalCheck4': 'privet', + }, + 'subscription': { + 'buttonText1': 'privet', + 'buttonText2': 'privet', + 'buttonText3': 'privet', + }, + 'tasks': { + 'breadcrumb': 'privet', + 'loading': 'privet', + 'buttonText1': 'privet', + 'buttonText2': 'privet', + 'buttonText3': 'privet', + }, + 'errors': { + 'incorectEmail': 'privet', + 'requiredEmail': 'privet', + 'requiredLogin': 'privet', + 'requiredPassword': 'privet', + 'requirementPassword': 'privet', + 'error400': 'privet', + 'error409': 'privet', + 'error500': 'privet', + } +} + +CREATE_SCHEME1 = { + 'language': 'en', + 'all_notification': 'privet', + 'profile': 'privet', + 'ok': 'privet', + 'exit': 'privet', + 'cancel': 'privet', + 'main': 'privet', + 'tasks': 'privet', + 'subscription': 'privet', + 'account': 'privet', + 'notifications': 'privet', + 'help': 'privet', + 'contacts': 'privet', + 'email': 'privet', + 'email_placeholder': 'privet', + 'login': 'privet', + 'login_placeholder': 'privet', + 'password': 'privet', + 'password_placeholder': 'privet', + 'message': 'privet', + 'message_placeholder': 'privet', + 'modal_title': 'privet', + 'modal_question': 'privet', + 'welcome': 'privet', + 'auth_title1': 'privet', + 'auth_title2': 'privet', + 'forgot_password': 'privet', + 'enter': 'privet', + 'register_': 'privet', + 'support': 'privet', + 'text': 'privet', + 'our_contacts': 'privet', + 'phones': 'privet', + 'phone1': 'privet', + 'phone2': 'privet', + 'select_label': 'privet', + 'select_placeholder': 'privet', + 'select_option1': 'privet', + 'select_option2': 'privet', + 'select_option3': 'privet', + 'email_placeholder': 'privet', + 'title': 'privet', + 'questions': 'privet', + 'write_us': 'privet', + 'title1': 'privet', + 'text1': 'privet', + 'text2': 'privet', + 'text3': 'privet', + 'title2': 'privet', + 'text4': 'privet', + 'button_text': 'privet', + 'title3': 'privet', + 'restore_password': 'privet', + 'text': 'privet', + 'button_text': 'privet', + 'modal_title': 'privet', + 'modal_agreements': 'privet', + 'modal_option1': 'privet', + 'modal_option2': 'privet', + 'modal_option3': 'privet', + 'modal_option4': 'privet', + 'modal_check1': 'privet', + 'modal_check2': 'privet', + 'modal_check3': 'privet', + 'modal_check4': 'privet', + 'button_text1': 'privet', + 'button_text2': 'privet', + 'button_text3': 'privet', + 'breadcrumb': 'privet', + 'loading': 'privet', + 'button_text1': 'privet', + 'button_text2': 'privet', + 'button_text3': 'privet', + 'incorect_email': 'privet', + 'required_email': 'privet', + 'required_login': 'privet', + 'required_password': 'privet', + 'requirement_password': 'privet', + 'error400': 'privet', + 'error409': 'privet', + 'error500': 'privet', +} + + +class TestCreateLocale: + async def test_create_locale( + self, + db_session, + auth_superuser: TestClient, + ): + """Тест создания локали.""" + locales = await get_obj_count(Locale, db_session) + assert locales == 0 + response: Response = await auth_superuser.post( + '/locales/', + json=CREATE_SCHEME1 + ) + assert response.status_code == status.HTTP_201_CREATED + new_locale = await get_obj_count(Locale, db_session) + assert new_locale == locales + 1