Skip to content

Commit

Permalink
Merge pull request #16 from fga-eps-mds/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
VictorAmaralC authored Dec 3, 2023
2 parents db2fe4d + 4fcf35b commit 7ea24a1
Show file tree
Hide file tree
Showing 11 changed files with 677 additions and 103 deletions.
190 changes: 190 additions & 0 deletions gestao/db/migrations/versions/2023-12-01-21-33_02379f0ee4ac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
"""Fix: Refactoring user fields
Revision ID: 02379f0ee4ac
Revises: 89f33fa986f8
Create Date: 2023-12-01 21:33:24.578159
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "02379f0ee4ac"
down_revision = "89f33fa986f8"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.drop_table("dependent")
op.drop_table("user")

op.create_table(
"user",
sa.Column("id", sa.String(length=200), primary_key=True, nullable=False),
sa.Column("fullName", sa.String(length=200), nullable=False),
sa.Column("warName", sa.String(length=200), nullable=True),
sa.Column("registration", sa.String(length=200), unique=True, nullable=False),
sa.Column("birthDate", sa.Date(), nullable=False),
sa.Column("rg", sa.String(length=200), unique=True, nullable=False),
sa.Column("cpf", sa.String(length=200), unique=True, nullable=False),
sa.Column("placeOfBirth", sa.String(length=200), nullable=False),
sa.Column("ufNatural", sa.String(length=200), nullable=False),
sa.Column("civilState", sa.String(length=200), nullable=False),
sa.Column("cep", sa.String(length=200), nullable=False),
sa.Column("address", sa.String(length=200), nullable=False),
sa.Column("number", sa.String(length=200), nullable=False),
sa.Column("neighborhood", sa.String(length=200), nullable=False),
sa.Column("city", sa.String(length=200), nullable=False),
sa.Column("complement", sa.String(length=200), nullable=False),
sa.Column("uf", sa.String(length=200), nullable=False),
sa.Column("email", sa.String(length=200), unique=True, nullable=False),
sa.Column("cellphone", sa.String(length=200), nullable=False),
sa.Column("phone", sa.String(length=200), nullable=False),
sa.Column("gender", sa.String(length=200), nullable=False),
sa.Column("motherName", sa.String(length=200), nullable=False),
sa.Column("fatherName", sa.String(length=200), nullable=False),
sa.Column("scolarity", sa.String(length=200), nullable=False),
sa.Column("religion", sa.String(length=200), nullable=False),
sa.Column("bloodType", sa.String(length=200), nullable=False),
sa.Column("actualWorkSituation", sa.String(length=200), nullable=False),
sa.Column("admissionDate", sa.Date(), nullable=False),
sa.Column("jobRole", sa.String(length=200), nullable=False),
sa.Column("bodyOfLaw", sa.String(length=200), nullable=False),
sa.Column("lotation", sa.String(length=200), nullable=False),
sa.Column("workPost", sa.String(length=200), nullable=False),
sa.Column("systemRole", sa.String(length=200), nullable=False),
sa.Column("password", sa.String(length=200), nullable=False),
sa.Column("status", sa.String(length=200), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
schema="public",
)

op.create_table(
"dependent",
sa.Column("id", sa.String(length=200), primary_key=True, nullable=False),
sa.Column(
"user_id",
sa.String(length=200),
sa.ForeignKey("user.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("name", sa.String(length=200), nullable=False),
sa.Column("birth_date", sa.Date(), nullable=False),
sa.Column("relationship", sa.String(length=200), nullable=False),
sa.Column("cpf", sa.String(200), nullable=True, unique=True),
sa.Column("gender", sa.String(200), nullable=True),
sa.Column("phone", sa.String(200), nullable=True),
sa.Column("pensioner", sa.Boolean(), default=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
schema="public",
)


def downgrade() -> None:
op.drop_table("dependent")
op.drop_table("user")

op.create_table(
"user",
sa.Column("id", sa.String(length=200), primary_key=True, nullable=False),
sa.Column("name", sa.String(length=200), nullable=False),
sa.Column("address", sa.String(length=200), nullable=True),
sa.Column("neighborhood", sa.String(length=200), nullable=False),
sa.Column("city", sa.String(length=200), nullable=False),
sa.Column("state", sa.String(length=200), nullable=False),
sa.Column("zipcode", sa.String(length=200), nullable=False),
sa.Column("cpf", sa.String(length=200), unique=True, nullable=False),
sa.Column("rg", sa.String(length=200), unique=True, nullable=False),
sa.Column("birth_date", sa.Date(), nullable=False),
sa.Column("place_of_birth", sa.String(length=200), nullable=False),
sa.Column("blood_type", sa.String(length=200), nullable=False),
sa.Column("gender", sa.String(length=200), nullable=False),
sa.Column("father_name", sa.String(length=200), nullable=False),
sa.Column("mother_name", sa.String(length=200), nullable=False),
sa.Column("position", sa.String(length=200), nullable=False),
sa.Column("admission_date", sa.Date(), nullable=False),
sa.Column("situation", sa.String(length=200), nullable=False),
sa.Column("phone", sa.String(length=200), nullable=False),
sa.Column("email", sa.String(length=200), unique=True, nullable=False),
sa.Column("marital_status", sa.String(length=200), nullable=False),
sa.Column("education", sa.String(length=200), nullable=False),
sa.Column("registration", sa.String(length=200), unique=True, nullable=False),
sa.Column("role", sa.String(length=200), nullable=False),
sa.Column("category", sa.String(length=200), nullable=False),
sa.Column("pattern", sa.String(length=200), nullable=False),
sa.Column("status", sa.String(length=200), nullable=False),
sa.Column("workstation", sa.String(length=200), nullable=False),
sa.Column("nickname", sa.String(length=200), nullable=False),
sa.Column("password", sa.String(length=200), nullable=False),
sa.Column("religion", sa.String(length=200), nullable=False),
sa.Column("dispatcher", sa.String(length=200), nullable=False),
sa.Column("dispatched_date", sa.Date(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
schema="public",
)

op.create_table(
"dependent",
sa.Column("id", sa.String(length=200), primary_key=True, nullable=False),
sa.Column(
"user_id",
sa.String(length=200),
sa.ForeignKey("user.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("name", sa.String(length=200), nullable=False),
sa.Column("birth_date", sa.Date(), nullable=False),
sa.Column("relationship", sa.String(length=200), nullable=False),
sa.Column("cpf", sa.String(200), nullable=True, unique=True),
sa.Column("gender", sa.String(200), nullable=True),
sa.Column("phone", sa.String(200), nullable=True),
sa.Column("pensioner", sa.Boolean(), default=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
schema="public",
)
63 changes: 31 additions & 32 deletions gestao/db/models/user.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
from datetime import date, datetime
from typing import Optional

import ormar

from gestao.db.base import BaseMeta
import ormar


class User(ormar.Model):
class Meta(BaseMeta):
tablename = "user"

id: str = ormar.String(max_length=200, primary_key=True)
name: str = ormar.String(max_length=200)
fullName: str = ormar.String(max_length=200)
warName: str = ormar.String(max_length=200, nullable=True)
registration: str = ormar.String(max_length=200, unique=True)
birthDate: date = ormar.Date()
rg: str = ormar.String(max_length=200, unique=True)
cpf: str = ormar.String(max_length=200, unique=True)
placeOfBirth: str = ormar.String(max_length=200)
ufNatural: str = ormar.String(max_length=100)
civilState: str = ormar.String(max_length=200, nullable=True)
cep: str = ormar.String(max_length=100)
address: str = ormar.String(max_length=200)
neighborhood: str = ormar.String(max_length=200)
number: str = ormar.String(max_length=100, nullable=True)
neighborhood: str = ormar.String(max_length=100, nullable=True)
city: str = ormar.String(max_length=100)
state: str = ormar.String(max_length=100)
zipcode: str = ormar.String(max_length=100)
cpf: str = ormar.String(max_length=200, unique=True)
rg: str = ormar.String(max_length=200, unique=True)
birth_date: date = ormar.Date()
place_of_birth: str = ormar.String(max_length=200)
blood_type: str = ormar.String(max_length=200)
gender: str = ormar.String(max_length=200)
father_name: str = ormar.String(max_length=200)
mother_name: str = ormar.String(max_length=200)
position: str = ormar.String(max_length=200)
occupancy: str = ormar.String(max_length=200)
admission_date: date = ormar.Date()
situation: str = ormar.String(max_length=200)
phone: str = ormar.String(max_length=200)
complement: str = ormar.String(max_length=200, nullable=True)
uf: str = ormar.String(max_length=100)
email: str = ormar.String(max_length=200)
marital_status: str = ormar.String(max_length=200)
education: str = ormar.String(max_length=200)
registration: str = ormar.String(max_length=200, unique=True)
role: str = ormar.String(max_length=200)
category: str = ormar.String(max_length=200)
pattern: str = ormar.String(max_length=200)
status: str = ormar.String(max_length=200, default="active")
workstation: Optional[str] = ormar.String(max_length=200, nullable=True)
nickname: Optional[str] = ormar.String(max_length=200, unique=True, nullable=True)
cellphone: str = ormar.String(max_length=200)
phone: str = ormar.String(max_length=200, nullable=True)
gender: str = ormar.String(max_length=200)
motherName: str = ormar.String(max_length=200)
fatherName: str = ormar.String(max_length=200, nullable=True)
scolarity: str = ormar.String(max_length=200, nullable=True)
religion: str = ormar.String(max_length=200, nullable=True)
bloodType: str = ormar.String(max_length=200, nullable=True)
actualWorkSituation: str = ormar.String(max_length=200)
admissionDate: date = ormar.Date()
jobRole: str = ormar.String(max_length=200, nullable=True)
bodyOfLaw: str = ormar.String(max_length=200)
lotation: str = ormar.String(max_length=200, nullable=True)
workPost: str = ormar.String(max_length=200, nullable=True)
systemRole: str = ormar.String(max_length=200, nullable=True)
password: str = ormar.String(max_length=200, nullable=True)
religion: Optional[str] = ormar.String(max_length=200, nullable=True)
dispatcher: str = ormar.String(max_length=200)
dispatched_date: date = ormar.Date()
status: str = ormar.String(max_length=200, default="active")
created_at: datetime = ormar.DateTime(timezone=True, default=datetime.now)
updated_at: datetime = ormar.DateTime(
timezone=True,
Expand Down
59 changes: 59 additions & 0 deletions gestao/tests/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest
from fastapi import FastAPI
from httpx import AsyncClient
from starlette import status

from gestao.tests.utils import generate_fake_user
from gestao.web.api.login.utils import generate_password, send_email


def test_generate_password_correct() -> None:
password = generate_password()
assert isinstance(password, str)
assert len(password) == 8
length = 15
password = generate_password(length)
assert isinstance(password, str)
assert len(password) == 15


@pytest.mark.anyio
async def test_login_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None:
url = fastapi_app.url_path_for("create_user")
user = generate_fake_user()
response = await client.post(url, json=user)
assert response.status_code == 200
user_data = response.json()
user_credentials = {
"registration": user_data["registration"],
"password": user_data["password"],
}

url = fastapi_app.url_path_for("login_user")
response = await client.post(url, json=user_credentials)
assert response.status_code == 200


@pytest.mark.anyio
async def test_login_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None:
user_credentials = {
"registration": "[email protected]",
"password": "password_example",
}

url = fastapi_app.url_path_for("login_user")
response = await client.post(url, json=user_credentials)
assert response.status_code == 404


@pytest.mark.anyio
async def test_recover_password_incorrect(
client: AsyncClient, fastapi_app: FastAPI
) -> None:
user_credentials = {
"email": "[email protected]",
}

url = fastapi_app.url_path_for("recover_password")
response = await client.post(url, json=user_credentials)
assert response.status_code == 404
Loading

0 comments on commit 7ea24a1

Please sign in to comment.