Skip to content

Commit

Permalink
[FIX] Fixed failing test for py310-django42
Browse files Browse the repository at this point in the history
rendered html was not escaped
  • Loading branch information
sam-b0t committed May 30, 2024
1 parent 59f2f89 commit 6baf21f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/constantes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}


SERILAIZED_SOCIAL_LINKS = {
SERIALIZED_SOCIAL_LINKS = {
"facebook": "http://facebook.com/example",
"twitter": "http://twitter.com/example",
}
Expand Down
4 changes: 2 additions & 2 deletions tests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from .constantes import (
SERILAIZED_SOCIAL_LINKS
SERIALIZED_SOCIAL_LINKS
)


Expand All @@ -34,7 +34,7 @@ def test_serialize_firm_info(db, firm_contact_obj):

def test_serialize_firm_social(db, firm_social_links_objs):
queryset = Link.objects.all()
expected_output = SERILAIZED_SOCIAL_LINKS
expected_output = SERIALIZED_SOCIAL_LINKS
assert serialize_firm_social(queryset) == expected_output


Expand Down
23 changes: 13 additions & 10 deletions tests/templatetags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.test import RequestFactory
import pytest

from html import escape

from django.template import RequestContext, Template
from django.test import RequestFactory

from firm_info.models import FirmContact, Link
from firm_info.factories import TrackingFactory
from firm_info.templatetags.firm_info import (
Expand All @@ -11,7 +14,7 @@
firm_tag_analytic,
)

from .constantes import SERILAIZED_SOCIAL_LINKS
from .constantes import SERIALIZED_SOCIAL_LINKS


def test_firm_contact_tag(db, firm_contact_obj):
Expand All @@ -33,10 +36,10 @@ def test_firm_contact_tag(db, firm_contact_obj):
firm_contact_obj.city,
firm_contact_obj.country,
),
"<p>Address: {}</p>".format(firm_contact_obj.address),
"<p>city: {}</p>".format(firm_contact_obj.city),
"<p>postal code: {}</p>".format(firm_contact_obj.postal_code),
"<p>country: {}</p>".format(firm_contact_obj.country)
"<p>Address: {}</p>".format(escape(firm_contact_obj.address)),
"<p>city: {}</p>".format(escape(firm_contact_obj.city)),
"<p>postal code: {}</p>".format(escape(firm_contact_obj.postal_code)),
"<p>country: {}</p>".format(escape(firm_contact_obj.country))
])
assert rendered == expected_output

Expand All @@ -52,8 +55,8 @@ def test_firm_social_links_tag(db, firm_social_links_objs):
template = Template(output)
rendered = template.render(context)
expected_output = "\n".join([
f"<a href=\"{SERILAIZED_SOCIAL_LINKS['facebook']}\">facebook</a><br>",
f"<a href=\"{SERILAIZED_SOCIAL_LINKS['twitter']}\">twitter</a><br>"
f"<a href=\"{SERIALIZED_SOCIAL_LINKS['facebook']}\">facebook</a><br>",
f"<a href=\"{SERIALIZED_SOCIAL_LINKS['twitter']}\">twitter</a><br>"
])
assert rendered == expected_output

Expand All @@ -70,8 +73,8 @@ def test_firm_description_tag(firm_contact_obj):
template = Template(output)
rendered = template.render(context)
expected_output = "\n".join([
f"<p>Baseline: {firm_contact_obj.baseline}</p>",
f"<p>Short_description: {firm_contact_obj.short_description}</p>",
f"<p>Baseline: {escape(firm_contact_obj.baseline)}</p>",
f"<p>Short_description: {escape(firm_contact_obj.short_description)}</p>",
])
assert rendered == expected_output

Expand Down

0 comments on commit 6baf21f

Please sign in to comment.