|
| 1 | +from json import dumps |
| 2 | + |
| 3 | +from django.template import Context, Template |
| 4 | +from django.utils.html import escape |
| 5 | + |
| 6 | +from djadyen.settings import get_setting |
| 7 | +from tests.factories import OrderFactory |
| 8 | + |
| 9 | + |
| 10 | +def test_adyen_advanced_payment_component_no_styles(settings) -> None: |
| 11 | + """ |
| 12 | + Test donation component with a valid campaign |
| 13 | + :param donation_campaign_example: Example Donation Campaign |
| 14 | + """ |
| 15 | + |
| 16 | + settings.DJADYEN_STYLES = None |
| 17 | + order = OrderFactory.build() |
| 18 | + |
| 19 | + out = Template( |
| 20 | + "{% load adyen_tags %}" |
| 21 | + "{% adyen_advanced_payment_component language=adyen_language order=order %}" # noqa |
| 22 | + ).render( |
| 23 | + Context( |
| 24 | + { |
| 25 | + "adyen_language": "en-US", |
| 26 | + "order": order, |
| 27 | + } |
| 28 | + ) |
| 29 | + ) |
| 30 | + |
| 31 | + assert "data-styles=" not in out |
| 32 | + assert get_setting("DJADYEN_DEFAULT_COUNTRY_CODE") in out |
| 33 | + |
| 34 | + |
| 35 | +def test_adyen_advanced_payment_component_with_styles(settings) -> None: |
| 36 | + """ |
| 37 | + Test donation component with a valid campaign |
| 38 | + :param donation_campaign_example: Example Donation Campaign |
| 39 | + """ |
| 40 | + |
| 41 | + settings.DJADYEN_STYLES = { |
| 42 | + "base": { |
| 43 | + "color": "#000000", |
| 44 | + "fontSize": "16px", |
| 45 | + "fontFamily": "Arial, sans-serif", |
| 46 | + }, |
| 47 | + "placeholder": { |
| 48 | + "color": "#999999", |
| 49 | + }, |
| 50 | + "error": { |
| 51 | + "color": "#ff0000", |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + order = OrderFactory.build() |
| 56 | + |
| 57 | + out = Template( |
| 58 | + "{% load adyen_tags %}" |
| 59 | + "{% adyen_advanced_payment_component language=adyen_language order=order %}" # noqa |
| 60 | + ).render( |
| 61 | + Context( |
| 62 | + { |
| 63 | + "adyen_language": "en-US", |
| 64 | + "order": order, |
| 65 | + } |
| 66 | + ) |
| 67 | + ) |
| 68 | + |
| 69 | + assert "data-styles=" in out |
| 70 | + assert escape(dumps(settings.DJADYEN_STYLES)) in out |
| 71 | + assert get_setting("DJADYEN_DEFAULT_COUNTRY_CODE") in out |
0 commit comments