Skip to content

Commit

Permalink
Fix/create branding request (#1837)
Browse files Browse the repository at this point in the history
* fix(create branding request): pass alt text in from the form data

* test(create branding request): add unit test for create branding request

* chore: formatting

* fix(test_email_branding): mock send_branding_request a different way
  • Loading branch information
andrewleith authored May 8, 2024
1 parent de68687 commit 7a9e202
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/main/views/email_branding.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def create_branding_request(service_id):
current_service.organisation_id,
current_service.organisation.name,
upload_filename,
alt_text_en=email_branding["alt_text_en"],
alt_text_fr=email_branding["alt_text_fr"],
form.alt_text_en.data,
form.alt_text_fr.data,
)
# todo: remove unused params
return render_template(
Expand Down
44 changes: 43 additions & 1 deletion tests/app/main/views/test_email_branding.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from io import BytesIO
from unittest import mock
from unittest.mock import call
from unittest.mock import call, patch

import pytest
from bs4 import BeautifulSoup
from flask import url_for
from flask_login import current_user
from notifications_python_client.errors import HTTPError

from app.main.views.email_branding import get_preview_template
Expand Down Expand Up @@ -656,6 +657,7 @@ class MockService:
assert "The canada wordmark is displayed at the bottom right" in html_template

def test_get_preview_template_with_email_branding_and_custom_brand_logo(self, mocker, app_):

email_branding = {
"brand_type": "both_english",
"colour": "#ff0000",
Expand All @@ -679,3 +681,43 @@ class MockService:
html_template = get_preview_template(None)
assert "There’s a custom logo at the top left and no logo at the bottom." in html_template
assert "The canada wordmark is displayed at the bottom right" not in html_template

def test_create_branding_request(self, mocker, platform_admin_client):
class MockOrg:
name = "Test org"

class MockService:
email_branding_id = None
default_branding_is_french = False
id = "1234"
name = "Awesome"
organisation_id = "1234"
organisation = MockOrg

mocker.patch("app.main.views.email_branding.upload_email_logo", return_value="temp_filename")
mocker.patch("app.main.views.email_branding.current_service", new=MockService)

data = {
"name": "test-logo",
"file": (BytesIO("".encode("utf-8")), "test.png"),
"alt_text_en": "ALT_EN",
"alt_text_fr": "ALT_FR",
}

with patch.object(current_user, "send_branding_request", return_value="") as mock_create_branding_request:

platform_admin_client.post(
url_for(".create_branding_request", service_id="1234"),
data=data,
)

assert mock_create_branding_request.called
assert mock_create_branding_request.call_args == call(
MockService.id,
MockService.name,
MockService.organisation_id,
MockService.organisation.name,
"temp_filename",
data["alt_text_en"],
data["alt_text_fr"],
)

0 comments on commit 7a9e202

Please sign in to comment.