generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extension field with a max size of 254 (#421)
Closes #420 - Added Alembic script to add the extension column to contact_info - Added extension field to the contact info DAO and DTO - Added pytests to test the two things above. - Field is optional
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
db_revisions/versions/ba8234fe9eb5_add_extension_to_contactinfo.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,29 @@ | ||
"""add extension to contactinfo | ||
Revision ID: ba8234fe9eb5 | ||
Revises: 7356a7d7036d | ||
Create Date: 2024-09-24 12:26:46.755693 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "ba8234fe9eb5" | ||
down_revision: Union[str, None] = "7356a7d7036d" | ||
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") as batch_op: | ||
batch_op.add_column(sa.Column("phone_ext", sa.String(254), nullable=True)) | ||
|
||
|
||
def downgrade() -> None: | ||
with op.batch_alter_table("contact_info") as batch_op: | ||
batch_op.drop_column("phone_ext") |
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 |
---|---|---|
|
@@ -674,6 +674,7 @@ def test_put_contact_info( | |
hq_address_state="TS", | ||
hq_address_zip="12345", | ||
phone_number="112-345-6789", | ||
phone_ext="x54321", | ||
email="[email protected]", | ||
), | ||
creator_id=1, | ||
|
@@ -700,6 +701,7 @@ def test_put_contact_info( | |
"hq_address_zip": "12345", | ||
"phone_number": "112-345-6789", | ||
"email": "[email protected]", | ||
"phone_ext": "x54321", | ||
} | ||
|
||
res = client.put( | ||
|
@@ -722,6 +724,7 @@ def test_put_contact_info( | |
assert result["contact_info"]["hq_address_state"] == "TS" | ||
assert result["contact_info"]["hq_address_zip"] == "12345" | ||
assert result["contact_info"]["phone_number"] == "112-345-6789" | ||
assert result["contact_info"]["phone_ext"] == "x54321" | ||
assert result["contact_info"]["email"] == "[email protected]" | ||
|
||
mock.assert_called_with( | ||
|
@@ -739,9 +742,128 @@ def test_put_contact_info( | |
hq_address_zip="12345", | ||
email="[email protected]", | ||
phone_number="112-345-6789", | ||
phone_ext="x54321", | ||
), | ||
) | ||
|
||
def test_no_extension( | ||
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock, get_filing_mock: Mock | ||
): | ||
get_filing_mock.return_value | ||
|
||
mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.update_contact_info") | ||
mock.return_value = FilingDAO( | ||
id=1, | ||
lei="1234567890ZXWVUTSR00", | ||
institution_snapshot_id="Snapshot-1", | ||
filing_period="2024", | ||
contact_info=ContactInfoDAO( | ||
id=1, | ||
filing=1, | ||
first_name="test_first_name_1", | ||
last_name="test_last_name_1", | ||
hq_address_street_1="address street 1", | ||
hq_address_street_2="", | ||
hq_address_city="Test City 1", | ||
hq_address_state="TS", | ||
hq_address_zip="12345", | ||
phone_number="112-345-6789", | ||
email="[email protected]", | ||
), | ||
creator_id=1, | ||
creator=UserActionDAO( | ||
id=1, | ||
user_id="123456-7890-ABCDEF-GHIJ", | ||
user_name="test creator", | ||
user_email="[email protected]", | ||
action_type=UserActionType.CREATE, | ||
timestamp=datetime.datetime.now(), | ||
), | ||
) | ||
|
||
client = TestClient(app_fixture) | ||
contact_info_json = { | ||
"id": 1, | ||
"filing": 1, | ||
"first_name": "test_first_name_1", | ||
"last_name": "test_last_name_1", | ||
"hq_address_street_1": "address street 1", | ||
"hq_address_street_2": "", | ||
"hq_address_city": "Test City 1", | ||
"hq_address_state": "TS", | ||
"hq_address_zip": "12345", | ||
"phone_number": "112-345-6789", | ||
"email": "[email protected]", | ||
} | ||
|
||
res = client.put( | ||
"/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/contact-info", json=contact_info_json | ||
) | ||
|
||
assert res.status_code == 200 | ||
|
||
result = res.json() | ||
assert result["id"] == 1 | ||
assert result["lei"] == "1234567890ZXWVUTSR00" | ||
assert result["institution_snapshot_id"] == "Snapshot-1" | ||
assert result["filing_period"] == "2024" | ||
assert result["contact_info"]["id"] == 1 | ||
assert result["contact_info"]["first_name"] == "test_first_name_1" | ||
assert result["contact_info"]["last_name"] == "test_last_name_1" | ||
assert result["contact_info"]["hq_address_street_1"] == "address street 1" | ||
assert result["contact_info"]["hq_address_street_2"] == "" | ||
assert result["contact_info"]["hq_address_city"] == "Test City 1" | ||
assert result["contact_info"]["hq_address_state"] == "TS" | ||
assert result["contact_info"]["hq_address_zip"] == "12345" | ||
assert result["contact_info"]["phone_number"] == "112-345-6789" | ||
assert result["contact_info"]["email"] == "[email protected]" | ||
|
||
mock.assert_called_with( | ||
ANY, | ||
"1234567890ZXWVUTSR00", | ||
"2024", | ||
ContactInfoDTO( | ||
id=1, | ||
first_name="test_first_name_1", | ||
last_name="test_last_name_1", | ||
hq_address_street_1="address street 1", | ||
hq_address_street_2="", | ||
hq_address_city="Test City 1", | ||
hq_address_state="TS", | ||
hq_address_zip="12345", | ||
email="[email protected]", | ||
phone_number="112-345-6789", | ||
), | ||
) | ||
|
||
def test_bad_extension( | ||
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock, get_filing_mock: Mock | ||
): | ||
|
||
client = TestClient(app_fixture) | ||
contact_info_json = { | ||
"id": 1, | ||
"filing": 1, | ||
"first_name": "test_first_name_1", | ||
"last_name": "test_last_name_1", | ||
"hq_address_street_1": "address street 1", | ||
"hq_address_street_2": "", | ||
"hq_address_city": "Test City 1", | ||
"hq_address_state": "TS", | ||
"hq_address_zip": "12345", | ||
"phone_number": "112-345-6789", | ||
"phone_ext": "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
"email": "[email protected]", | ||
} | ||
|
||
res = client.put( | ||
"/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/contact-info", json=contact_info_json | ||
) | ||
|
||
assert res.status_code == 422 | ||
json_error = res.json() | ||
assert "'String should have at most 254 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( | ||
id=2, | ||
|
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 |
---|---|---|
|
@@ -194,6 +194,7 @@ async def setup( | |
hq_address_state="TS", | ||
hq_address_zip="12345", | ||
phone_number="212-345-6789", | ||
phone_ext="x54321", | ||
email="[email protected]", | ||
) | ||
transaction_session.add(contact_info1) | ||
|
@@ -483,6 +484,7 @@ async def test_get_contact_info(self, query_session: AsyncSession): | |
assert res.contact_info.hq_address_state == "TS" | ||
assert res.contact_info.hq_address_zip == "12345" | ||
assert res.contact_info.phone_number == "212-345-6789" | ||
assert res.contact_info.phone_ext == "x54321" | ||
assert res.contact_info.email == "[email protected]" | ||
|
||
async def test_create_contact_info(self, transaction_session: AsyncSession): | ||
|
@@ -538,6 +540,7 @@ async def test_update_contact_info(self, transaction_session: AsyncSession): | |
hq_address_state="TS", | ||
hq_address_zip="12345", | ||
phone_number="212-345-6789", | ||
phone_ext="x12345", | ||
email="[email protected]", | ||
), | ||
) | ||
|
@@ -555,6 +558,7 @@ async def test_update_contact_info(self, transaction_session: AsyncSession): | |
assert filing.contact_info.hq_address_state == "TS" | ||
assert filing.contact_info.hq_address_zip == "12345" | ||
assert filing.contact_info.phone_number == "212-345-6789" | ||
assert filing.contact_info.phone_ext == "x12345" | ||
assert filing.contact_info.email == "[email protected]" | ||
|
||
async def test_get_user_action(self, query_session: AsyncSession): | ||
|
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