Skip to content
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

Added alt text for email_branding table #2159

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading