Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

428 contact info char limit #439

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Set character limit in contact info

Revision ID: 6babc6109a5a
Revises: ba8234fe9eb5
Create Date: 2024-10-07 16:33:18.213745

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = "6babc6109a5a"
down_revision: Union[str, None] = "ba8234fe9eb5"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.batch_alter_table("contact_info", schema=None) as batch_op:
batch_op.alter_column("first_name", type_=sa.String(255), nullable=False)
batch_op.alter_column("last_name", type_=sa.String(255), nullable=False)
batch_op.alter_column("hq_address_street_1", type_=sa.String(255), nullable=False)
batch_op.alter_column("hq_address_street_2", type_=sa.String(255), nullable=True)
batch_op.alter_column("hq_address_street_3", type_=sa.String(255), nullable=True)
batch_op.alter_column("hq_address_street_4", type_=sa.String(255), nullable=True)
batch_op.alter_column("hq_address_city", type_=sa.String(255), nullable=False)
batch_op.alter_column("hq_address_state", type_=sa.String(255), nullable=False)
batch_op.alter_column("email", type_=sa.String(255), nullable=False)
batch_op.alter_column("phone_number", type_=sa.String(255), nullable=False)
batch_op.alter_column("phone_ext", type_=sa.String(255), nullable=False)


def downgrade() -> None:
with op.batch_alter_table("contact_info", schema=None) as batch_op:
batch_op.alter_column("first_name", type_=sa.String, nullable=False)
batch_op.alter_column("last_name", type_=sa.String, nullable=False)
batch_op.alter_column("hq_address_street_1", type_=sa.String, nullable=False)
batch_op.alter_column("hq_address_street_2", type_=sa.String, nullable=True)
batch_op.alter_column("hq_address_street_3", type_=sa.String, nullable=True)
batch_op.alter_column("hq_address_street_4", type_=sa.String, nullable=True)
batch_op.alter_column("hq_address_city", type_=sa.String, nullable=False)
batch_op.alter_column("hq_address_state", type_=sa.String, nullable=False)
batch_op.alter_column("email", type_=sa.String, nullable=False)
batch_op.alter_column("phone_number", type_=sa.String, nullable=False)
batch_op.alter_column("phone_ext", type_=sa.String, nullable=False)
22 changes: 11 additions & 11 deletions src/sbl_filing_api/entities/models/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ class ContactInfoDAO(Base):
__tablename__ = "contact_info"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
filing: Mapped[int] = mapped_column(ForeignKey("filing.id"))
first_name: Mapped[str]
last_name: Mapped[str]
hq_address_street_1: Mapped[str]
hq_address_street_2: Mapped[str] = mapped_column(nullable=True)
hq_address_street_3: Mapped[str] = mapped_column(nullable=True)
hq_address_street_4: Mapped[str] = mapped_column(nullable=True)
hq_address_city: Mapped[str]
hq_address_state: Mapped[str]
first_name: Mapped[str] = mapped_column(String(255))
last_name: Mapped[str] = mapped_column(String(255))
hq_address_street_1: Mapped[str] = mapped_column(String(255))
hq_address_street_2: Mapped[str] = mapped_column(String(255), nullable=True)
hq_address_street_3: Mapped[str] = mapped_column(String(255), nullable=True)
hq_address_street_4: Mapped[str] = mapped_column(String(255), nullable=True)
hq_address_city: Mapped[str] = mapped_column(String(255))
hq_address_state: Mapped[str] = mapped_column(String(255))
hq_address_zip: Mapped[str] = mapped_column(String(5))
email: Mapped[str]
phone_number: Mapped[str]
phone_ext: Mapped[str] = mapped_column(String(254), nullable=True)
email: Mapped[str] = mapped_column(String(255))
phone_number: Mapped[str] = mapped_column(String(255))
phone_ext: Mapped[str] = mapped_column(String(255), nullable=True)

def __str__(self):
return f"ContactInfo ID: {self.id}, First Name: {self.first_name}, Last Name: {self.last_name}, Address Street 1: {self.hq_address_street_1}, Address Street 2: {self.hq_address_street_2}, Address City: {self.hq_address_city}, Address State: {self.hq_address_state}, Address Zip: {self.hq_address_zip}"
Expand Down
24 changes: 12 additions & 12 deletions src/sbl_filing_api/entities/models/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ class ContactInfoDTO(BaseModel):
model_config = ConfigDict(from_attributes=True)

id: int | None = None
first_name: str
last_name: str
hq_address_street_1: str
hq_address_street_2: str | None = None
hq_address_street_3: str | None = None
hq_address_street_4: str | None = None
hq_address_city: str
hq_address_state: str
hq_address_zip: str
email: str
phone_number: str
phone_ext: str | None = Field(None, max_length=254)
first_name: str = Field(max_length=255)
last_name: str = Field(max_length=255)
hq_address_street_1: str = Field(max_length=255)
hq_address_street_2: str | None = Field(None, max_length=255)
hq_address_street_3: str | None = Field(None, max_length=255)
hq_address_street_4: str | None = Field(None, max_length=255)
hq_address_city: str = Field(max_length=255)
hq_address_state: str = Field(max_length=255)
hq_address_zip: str = Field(max_length=5)
email: str = Field(max_length=255)
phone_number: str = Field(max_length=255)
phone_ext: str | None = Field(None, max_length=255)

@model_validator(mode="after")
def validate_fi(self) -> "ContactInfoDTO":
Expand Down
2 changes: 1 addition & 1 deletion tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def test_bad_extension(

assert res.status_code == 422
json_error = res.json()
assert "'String should have at most 254 characters'" in json_error["error_detail"]
assert "'String should have at most 255 characters'" in json_error["error_detail"]

async def test_accept_submission(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
user_action_submit = UserActionDAO(
Expand Down
60 changes: 60 additions & 0 deletions tests/entities/repos/test_submission_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import datetime
from datetime import datetime as dt

from pydantic_core._pydantic_core import ValidationError
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession, async_scoped_session

Expand Down Expand Up @@ -522,6 +524,34 @@ async def test_create_contact_info(self, transaction_session: AsyncSession):
assert filing.contact_info.phone_number == "312-345-6789"
assert filing.contact_info.email == "[email protected]"

async def test_create_contact_info_invalid_field_length(self, transaction_session: AsyncSession):
out_of_rang_text = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on the var name assuming you meant to say range

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget "
"dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, "
"nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis..."
)
with pytest.raises(Exception) as e:
await repo.update_contact_info(
transaction_session,
lei="ZYXWVUTSRQP",
filing_period="2024",
new_contact_info=ContactInfoDTO(
first_name=out_of_rang_text,
last_name="test_last_name_3",
hq_address_street_1="address street 1",
hq_address_street_2="",
hq_address_street_3="",
hq_address_street_4="",
hq_address_city="Test City",
hq_address_state="TS",
hq_address_zip="12345",
phone_number="312-345-6789",
phone_ext="x12345",
email="[email protected]",
),
)
assert isinstance(e.value, ValidationError)

async def test_update_contact_info(self, transaction_session: AsyncSession):
filing = await repo.update_contact_info(
transaction_session,
Expand Down Expand Up @@ -561,6 +591,36 @@ async def test_update_contact_info(self, transaction_session: AsyncSession):
assert filing.contact_info.phone_ext == "x12345"
assert filing.contact_info.email == "[email protected]"

async def test_update_contact_info_invalid_field_length(self, transaction_session: AsyncSession):
out_of_rang_text = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget "
"dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, "
"nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis..."
)
with pytest.raises(Exception) as e:
await repo.update_contact_info(
transaction_session,
lei="ABCDEFGHIJ",
filing_period="2024",
new_contact_info=ContactInfoDTO(
id=2,
filing=2,
first_name="test_first_name_upd",
last_name="test_last_name_upd",
hq_address_street_1="address street upd",
hq_address_street_2="",
hq_address_street_3="",
hq_address_street_4="",
hq_address_city="Test City upd",
hq_address_state="TS",
hq_address_zip="12345",
phone_number="212-345-6789",
phone_ext="x12345",
email=out_of_rang_text,
),
)
assert isinstance(e.value, ValidationError)

async def test_get_user_action(self, query_session: AsyncSession):
res = await repo.get_user_action(session=query_session, id=3)

Expand Down
18 changes: 18 additions & 0 deletions tests/migrations/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,21 @@ def test_migrations_to_ba8234fe9eb5(alembic_runner: MigrationContext, alembic_en
inspector = sqlalchemy.inspect(alembic_engine)

assert "phone_ext" in set([c["name"] for c in inspector.get_columns("contact_info")])


def test_migrations_to_6babc6109a5a(alembic_runner: MigrationContext, alembic_engine: Engine):
guffee23 marked this conversation as resolved.
Show resolved Hide resolved
alembic_runner.migrate_up_to("6babc6109a5a")

inspector = sqlalchemy.inspect(alembic_engine)

assert "first_name" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "last_name" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_street_1" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_street_2" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_street_3" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_street_4" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_city" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "hq_address_state" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "email" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "phone_number" in set([c["name"] for c in inspector.get_columns("contact_info")])
assert "phone_ext" in set([c["name"] for c in inspector.get_columns("contact_info")])
Loading