Skip to content

Commit a049ee2

Browse files
authored
Added alt text for email_branding table (#2159)
* Added ialt text for email_branding table * test fix * fix
1 parent 522451e commit a049ee2

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

app/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ class EmailBranding(BaseModel):
280280
UUID(as_uuid=True), db.ForeignKey("organisation.id", ondelete="SET NULL"), index=True, nullable=True
281281
)
282282
organisation = db.relationship("Organisation", back_populates="email_branding", foreign_keys=[organisation_id])
283+
alt_text_en = db.Column(db.String(), nullable=True)
284+
alt_text_fr = db.Column(db.String(), nullable=True)
283285

284286
def serialize(self) -> dict:
285287
serialized = {
@@ -290,6 +292,8 @@ def serialize(self) -> dict:
290292
"text": self.text,
291293
"brand_type": self.brand_type,
292294
"organisation_id": str(self.organisation_id) if self.organisation_id else "",
295+
"alt_text_en": self.alt_text_en,
296+
"alt_text_fr": self.alt_text_fr,
293297
}
294298

295299
return serialized
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Revision ID: 0446_add_alt_text.py
3+
Revises: 0445_add_org_id_branding.py
4+
Create Date: 2024-04-23
5+
"""
6+
import sqlalchemy as sa
7+
from alembic import op
8+
from sqlalchemy import text
9+
10+
revision = "0446_add_alt_text"
11+
down_revision = "0445_add_org_id_branding"
12+
13+
14+
def upgrade():
15+
table_description = op.get_bind().execute(
16+
text("SELECT * FROM information_schema.columns WHERE table_name = 'email_branding'")
17+
)
18+
19+
# Check if the column exists
20+
if "alt_text_en" not in [column["column_name"] for column in table_description]:
21+
op.add_column(
22+
"email_branding",
23+
sa.Column("alt_text_en", sa.String(), nullable=True),
24+
)
25+
if "alt_text_fr" not in [column["column_name"] for column in table_description]:
26+
op.add_column(
27+
"email_branding",
28+
sa.Column("alt_text_fr", sa.String(), nullable=True),
29+
)
30+
31+
32+
def downgrade():
33+
op.drop_column("email_branding", "alt_text_fr")
34+
op.drop_column("email_branding", "alt_text_en")

tests/app/email_branding/test_rest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def test_get_email_branding_options_filter_org(admin_request, notify_db, notify_
3939

4040

4141
def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
42-
email_branding = EmailBranding(colour="#FFFFFF", logo="/path/image.png", name="Some Org", text="My Org")
42+
email_branding = EmailBranding(
43+
colour="#FFFFFF", logo="/path/image.png", name="Some Org", text="My Org", alt_text_en="hello world"
44+
)
4345
notify_db.session.add(email_branding)
4446
notify_db.session.commit()
4547

@@ -57,13 +59,17 @@ def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
5759
"text",
5860
"brand_type",
5961
"organisation_id",
62+
"alt_text_en",
63+
"alt_text_fr",
6064
}
6165
assert response["email_branding"]["colour"] == "#FFFFFF"
6266
assert response["email_branding"]["logo"] == "/path/image.png"
6367
assert response["email_branding"]["name"] == "Some Org"
6468
assert response["email_branding"]["text"] == "My Org"
6569
assert response["email_branding"]["id"] == str(email_branding.id)
6670
assert response["email_branding"]["brand_type"] == str(email_branding.brand_type)
71+
assert response["email_branding"]["alt_text_en"] == "hello world"
72+
assert response["email_branding"]["alt_text_fr"] is None
6773

6874

6975
def test_post_create_email_branding(admin_request, notify_db_session):

0 commit comments

Comments
 (0)