Skip to content

Commit

Permalink
Added extension field with a max size of 254 (#421)
Browse files Browse the repository at this point in the history
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
jcadam14 authored Sep 24, 2024
1 parent d30762a commit fb78e33
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
29 changes: 29 additions & 0 deletions db_revisions/versions/ba8234fe9eb5_add_extension_to_contactinfo.py
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")
1 change: 1 addition & 0 deletions src/sbl_filing_api/entities/models/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ContactInfoDAO(Base):
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)

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
1 change: 1 addition & 0 deletions src/sbl_filing_api/entities/models/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ContactInfoDTO(BaseModel):
hq_address_zip: str
email: str
phone_number: str
phone_ext: str | None = Field(None, max_length=254)

@model_validator(mode="after")
def validate_fi(self) -> "ContactInfoDTO":
Expand Down
122 changes: 122 additions & 0 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/entities/repos/test_submission_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]",
),
)
Expand All @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/migrations/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,11 @@ def test_migrations_to_7356a7d7036d(alembic_runner: MigrationContext, alembic_en
inspector = sqlalchemy.inspect(alembic_engine)

assert "total_records" in set([c["name"] for c in inspector.get_columns("submission")])


def test_migrations_to_ba8234fe9eb5(alembic_runner: MigrationContext, alembic_engine: Engine):
alembic_runner.migrate_up_to("ba8234fe9eb5")

inspector = sqlalchemy.inspect(alembic_engine)

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

0 comments on commit fb78e33

Please sign in to comment.