generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
88163f0
Added field lengths to contact info
guffee23 99c5a0f
Added alembic script and tests
guffee23 a00fd9c
Changed pydantic field length
guffee23 edfd134
Fixed test
guffee23 67e83a5
Fixed typo
guffee23 754ab92
Updated migration test to include check for field length
guffee23 0220913
Merge branch 'main' into 428_contact_info_char_limit
guffee23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
db_revisions/versions/6babc6109a5a_set_character_limit_in_contact_info.py
This file contains 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
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) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 = ( | ||
"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, | ||
|
@@ -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 = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
|
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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