-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jenny Vong
authored and
Jenny Vong
committed
Nov 3, 2023
1 parent
1cd1702
commit 01518ad
Showing
20 changed files
with
867 additions
and
101 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
...thon/migrations/versions/2023-10-31_db7c2f31d3ea_add_relationship_to_child_enum_values.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,84 @@ | ||
"""add relationship_to_child enum values | ||
Revision ID: db7c2f31d3ea | ||
Revises: 2e3a95429cdf | ||
Create Date: 2023-10-31 11:43:49.965500 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "db7c2f31d3ea" | ||
down_revision = "2e3a95429cdf" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
# Enum 'type' for PostgreSQL | ||
enum_name = "caregivers_relationship_to_child" | ||
# Set temporary enum 'type' for PostgreSQL | ||
tmp_enum_name = "tmp_" + enum_name | ||
|
||
# Options for Enum | ||
old_options = ("FOSTER_CAREGIVER", "KINSHIP_CAREGIVER", "BIOLOGICAL_FAMILY") | ||
new_options = sorted( | ||
old_options | ||
+ ( | ||
"ADOPTIVE_PARENT", | ||
"FOSTER_PARENT", | ||
"BIOLOGICAL_PARENT", | ||
"STEP_PARENT", | ||
"MATERNAL_GRANDPARENT", | ||
"PATERNAL_GRANDPARENT", | ||
"SIBLING", | ||
"STEP_SIBLING", | ||
"HALF_SIBLING", | ||
"UNCLE/AUNT", | ||
"OTHER_RELATIVE", | ||
"OTHER", | ||
) | ||
) | ||
|
||
# Create enum fields | ||
old_type = sa.Enum(*old_options, name=enum_name) | ||
new_type = sa.Enum(*new_options, name=enum_name) | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
# Rename current enum type to tmp_ | ||
op.execute("ALTER TYPE " + enum_name + " RENAME TO " + tmp_enum_name) | ||
# Create new enum type in db | ||
new_type.create(op.get_bind()) | ||
# Update column to use new enum type | ||
op.execute( | ||
"ALTER TABLE caregivers ALTER COLUMN relationship_to_child TYPE " | ||
+ enum_name | ||
+ " USING relationship_to_child::text::" | ||
+ enum_name | ||
) | ||
# Drop old enum type | ||
op.execute("DROP TYPE " + tmp_enum_name) | ||
|
||
op.alter_column("caregivers", "email", existing_type=sa.String(), nullable=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
# Rename enum type to tmp_ | ||
op.execute("ALTER TYPE " + enum_name + " RENAME TO " + tmp_enum_name) | ||
# Create enum type using old values | ||
old_type.create(op.get_bind()) | ||
# Set enum type as type for event_type column | ||
op.execute( | ||
"ALTER TABLE caregivers ALTER COLUMN relationship_to_child TYPE " | ||
+ enum_name | ||
+ " USING relationship_to_child::text::" | ||
+ enum_name | ||
) | ||
# Drop temp enum type | ||
op.execute("DROP TYPE " + tmp_enum_name) | ||
|
||
op.alter_column("caregivers", "email", existing_type=sa.String(), nullable=False) | ||
# ### end Alembic commands ### |
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 |
---|---|---|
|
@@ -51,7 +51,7 @@ def caregiver_service(): | |
"secondary_phone_number": "2345678901", | ||
"email": "[email protected]", | ||
"address": "123 Fake Street", | ||
"relationship_to_child": "FOSTER_CAREGIVER", | ||
"relationship_to_child": "FOSTER_PARENT", | ||
"intake_id": 1, | ||
} | ||
|
||
|
@@ -87,7 +87,7 @@ def test_normal_case(self, caregiver_service): | |
secondary_phone_number="2345678901", | ||
email="[email protected]", | ||
address="1234 Lester Street", | ||
relationship_to_child="FOSTER_CAREGIVER", | ||
relationship_to_child="FOSTER_PARENT", | ||
intake_id=1, | ||
) | ||
caregiver_instance = caregiver_service.create_caregiver(param) | ||
|
@@ -101,7 +101,7 @@ def test_nullable_false_case(self, caregiver_service): | |
primary_phone_number="1234567890", | ||
email="[email protected]", | ||
address="1234 Lester Street", | ||
relationship_to_child="FOSTER_CAREGIVER", | ||
relationship_to_child="FOSTER_PARENT", | ||
intake_id=1, | ||
) | ||
caregiver_instance = caregiver_service.create_caregiver(param) | ||
|
@@ -116,7 +116,7 @@ def test_missing_field(self, caregiver_service): | |
primary_phone_number="1234567890", | ||
email="[email protected]", | ||
address="1234 Lester Street", | ||
relationship_to_child="FOSTER_CAREGIVER", | ||
relationship_to_child="FOSTER_PARENT", | ||
intake_id=1, | ||
) | ||
with pytest.raises(Exception): | ||
|
@@ -131,7 +131,7 @@ def test_empty_input_string(self): | |
secondary_phone_number="2345678901", | ||
email="[email protected]", | ||
address="1234 Lester Street", | ||
relationship_to_child="FOSTER_CAREGIVER", | ||
relationship_to_child="FOSTER_PARENT", | ||
intake_id=1, | ||
) | ||
with pytest.raises(Exception): | ||
|
@@ -150,3 +150,9 @@ def test_delete_success(self, caregiver_service): | |
def test_delete_nonexistent_id_fail(self, caregiver_service): | ||
with pytest.raises(Exception): | ||
caregiver_service.delete_caregiver(999) | ||
|
||
|
||
class GetCaregivers: | ||
def tet_get_caregivers_by_intake_id(self, caregiver_service): | ||
caregivers = caregiver_service.get_caregivers_by_intake_id(1) | ||
assert len(caregivers) is 1 |
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 |
---|---|---|
|
@@ -55,7 +55,7 @@ | |
"secondary_phone_number": "2345678901", | ||
"email": "[email protected]", | ||
"address": "123 Fake Street", | ||
"relationship_to_child": "FOSTER_CAREGIVER", | ||
"relationship_to_child": "FOSTER_PARENT", | ||
"intake_id": 1, | ||
} | ||
DUMMY_CHILD_DATA = { | ||
|
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 |
---|---|---|
|
@@ -94,8 +94,8 @@ def insert_test_data(): | |
|
||
# Caregivers | ||
values = [ | ||
('Yor Forger', '1999-01-01', 'considerations', '555-555-5555', '777-777-7777', '[email protected]', 'address', 'FOSTER_CAREGIVER', 'NULL', 1), | ||
('Loid Forger', '1999-01-01', 'considerations', '777-777-7777', '555-555-5555', '[email protected]', 'address', 'FOSTER_CAREGIVER', 'NULL', 1) | ||
('Yor Forger', '1999-01-01', 'considerations', '555-555-5555', '777-777-7777', '[email protected]', 'address', 'FOSTER_PARENT', 'NULL', 1), | ||
('Loid Forger', '1999-01-01', 'considerations', '777-777-7777', '555-555-5555', '[email protected]', 'address', 'MATERNAL_GRANDPARENT', 'NULL', 1) | ||
] | ||
|
||
for value in values: | ||
|
Oops, something went wrong.