Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add build absolute uri test

TOMEKd0f7233bcb77
diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.py
index 56a9e932ed..9fa7d14943 100644
--- a/tests/dashboard/test_staff.py
+++ b/tests/dashboard/test_staff.py
@@ -100,8 +100,7 @@ def test_send_set_password_email(staff_user, site_settings):
site = site_settings.site
uid = urlsafe_base64_encode(force_bytes(staff_user.pk)).decode()
token = default_token_generator.make_token(staff_user)
- logo_url = build_absolute_uri(
- location=None) + static('images/logo-document.svg')
+ logo_url = build_absolute_uri(static('images/logo-document.svg'))
password_set_url = build_absolute_uri(
reverse(
'account:reset-password-confirm',
diff --git a/tests/test_core.py b/tests/test_core.py
index 405edea56b..c697899fa9 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1,20 +1,22 @@
import io
from contextlib import redirect_stdout
from unittest.mock import Mock, patch
+from urllib.parse import urljoin
import pytest
from django.conf import settings
from django.db.models import Case, F, When
from django.shortcuts import reverse
+from django.templatetags.static import static
from django.urls import translate_url
from measurement.measures import Weight
from prices import Money
from saleor.account.models import Address, User
from saleor.core.storages import S3MediaStorage
from saleor.core.utils import (
- Country, create_superuser, create_thumbnails, format_money,
- get_country_by_ip, get_currency_for_country, random_data)
+ Country, build_absolute_uri, create_superuser, create_thumbnails,
+ format_money, get_country_by_ip, get_currency_for_country, random_data)
from saleor.core.utils.text import get_cleaner, strip_html
from saleor.core.weight import WeightUnits, convert_weight
from saleor.discount.models import Sale, Voucher
@@ -299,3 +301,12 @@ def test_convert_weight():
weight = Weight(kg=1)
expected_result = Weight(g=1000)
assert convert_weight(weight, WeightUnits.GRAM) == expected_result
+
+def test_build_absolute_uri(site_settings):
+ url = 'https://example.com/static/images/image.jpg'
+ logo_url = build_absolute_uri(static('images/logo-document.svg'))
+ protocol = 'https' if settings.ENABLE_SSL else 'http'
+ current_url = '%s://%s' % (protocol, site_settings.site.domain)
+ logo_location = urljoin(current_url, static('images/logo-document.svg'))
+ assert build_absolute_uri(location=url) == url
+ assert logo_url == logo_location