Skip to content

Commit

Permalink
Merge branch 'main' into fix/sms-content-length-error
Browse files Browse the repository at this point in the history
  • Loading branch information
whabanks authored Apr 24, 2024
2 parents 43e8220 + a049ee2 commit 6266b5b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ class EmailBranding(BaseModel):
UUID(as_uuid=True), db.ForeignKey("organisation.id", ondelete="SET NULL"), index=True, nullable=True
)
organisation = db.relationship("Organisation", back_populates="email_branding", foreign_keys=[organisation_id])
alt_text_en = db.Column(db.String(), nullable=True)
alt_text_fr = db.Column(db.String(), nullable=True)

def serialize(self) -> dict:
serialized = {
Expand All @@ -290,6 +292,8 @@ def serialize(self) -> dict:
"text": self.text,
"brand_type": self.brand_type,
"organisation_id": str(self.organisation_id) if self.organisation_id else "",
"alt_text_en": self.alt_text_en,
"alt_text_fr": self.alt_text_fr,
}

return serialized
Expand Down
34 changes: 34 additions & 0 deletions migrations/versions/0446_add_alt_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Revision ID: 0446_add_alt_text.py
Revises: 0445_add_org_id_branding.py
Create Date: 2024-04-23
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy import text

revision = "0446_add_alt_text"
down_revision = "0445_add_org_id_branding"


def upgrade():
table_description = op.get_bind().execute(
text("SELECT * FROM information_schema.columns WHERE table_name = 'email_branding'")
)

# Check if the column exists
if "alt_text_en" not in [column["column_name"] for column in table_description]:
op.add_column(
"email_branding",
sa.Column("alt_text_en", sa.String(), nullable=True),
)
if "alt_text_fr" not in [column["column_name"] for column in table_description]:
op.add_column(
"email_branding",
sa.Column("alt_text_fr", sa.String(), nullable=True),
)


def downgrade():
op.drop_column("email_branding", "alt_text_fr")
op.drop_column("email_branding", "alt_text_en")
8 changes: 7 additions & 1 deletion tests/app/email_branding/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_get_email_branding_options_filter_org(admin_request, notify_db, notify_


def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
email_branding = EmailBranding(colour="#FFFFFF", logo="/path/image.png", name="Some Org", text="My Org")
email_branding = EmailBranding(
colour="#FFFFFF", logo="/path/image.png", name="Some Org", text="My Org", alt_text_en="hello world"
)
notify_db.session.add(email_branding)
notify_db.session.commit()

Expand All @@ -57,13 +59,17 @@ def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
"text",
"brand_type",
"organisation_id",
"alt_text_en",
"alt_text_fr",
}
assert response["email_branding"]["colour"] == "#FFFFFF"
assert response["email_branding"]["logo"] == "/path/image.png"
assert response["email_branding"]["name"] == "Some Org"
assert response["email_branding"]["text"] == "My Org"
assert response["email_branding"]["id"] == str(email_branding.id)
assert response["email_branding"]["brand_type"] == str(email_branding.brand_type)
assert response["email_branding"]["alt_text_en"] == "hello world"
assert response["email_branding"]["alt_text_fr"] is None


def test_post_create_email_branding(admin_request, notify_db_session):
Expand Down

0 comments on commit 6266b5b

Please sign in to comment.