Skip to content

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

Swipe Site.get_current() for fixture in tests

Pacu245a70a0cad08
diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.py
index 7a4f729943..e7d5efe2e8 100644
--- a/tests/dashboard/test_staff.py
+++ b/tests/dashboard/test_staff.py
@@ -1,5 +1,4 @@
from django.contrib.auth.tokens import default_token_generator
-from django.contrib.sites.models import Site
from django.core import mail
from django.urls import reverse
from django.utils.encoding import force_bytes
@@ -96,8 +95,8 @@ def test_staff_create_email_with_set_link_password(
assert response['Location'] == reverse('dashboard:staff-list')
-def test_send_set_password_email(staff_user):
- site = Site.objects.get_current()
+def test_send_set_password_email(staff_user, site_settings):
+ site = site_settings.site
ctx = {
'protocol': 'http',
'domain': site.domain,
diff --git a/tests/test_data_feeds.py b/tests/test_data_feeds.py
index 22b19a0af9..45dd53d2f6 100644
--- a/tests/test_data_feeds.py
+++ b/tests/test_data_feeds.py
@@ -2,7 +2,6 @@ import csv
from io import StringIO
from unittest.mock import Mock, patch
-from django.contrib.sites.models import Site
from django.utils.encoding import smart_text
from saleor.data_feeds.google_merchant import (
@@ -10,7 +9,7 @@ from saleor.data_feeds.google_merchant import (
from saleor.product.models import AttributeChoiceValue, Category
-def test_saleor_feed_items(product_in_stock):
+def test_saleor_feed_items(product_in_stock, site_settings):
valid_variant = product_in_stock.variants.first()
items = get_feed_items()
assert len(items) == 1
@@ -18,7 +17,7 @@ def test_saleor_feed_items(product_in_stock):
discounts = []
category_paths = {}
attributes_dict = {}
- current_site = Site.objects.get_current()
+ current_site = site_settings.site
attribute_values_dict = {smart_text(a.pk): smart_text(a) for a
in AttributeChoiceValue.objects.all()}
attributes = item_attributes(items[0], categories, category_paths,
@@ -59,7 +58,7 @@ def test_write_feed(product_in_stock, monkeypatch):
@patch('saleor.data_feeds.google_merchant.item_link')
def test_feed_contains_site_settings_domain(
- mocked_item_link, product_in_stock):
+ mocked_item_link, product_in_stock, site_settings):
write_feed(StringIO())
mocked_item_link.assert_called_once_with(
- product_in_stock.variants.first(), Site.objects.get_current())
+ product_in_stock.variants.first(), site_settings.site)
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 65dae6ad5e..e1c9e0305c 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -2,15 +2,14 @@ from unittest import mock
import pytest
from django.conf import settings
-from django.contrib.sites.models import Site
from django.urls import reverse
import saleor.order.emails as emails
from saleor.core.utils import build_absolute_uri
-def test_get_email_context(order):
- site = Site.objects.get_current()
+def test_get_email_context(order, site_settings):
+ site = site_settings.site
order_url = build_absolute_uri(
reverse('order:details', kwargs={'token': order.token}))
proper_context = {
diff --git a/tests/test_emails_helpers.py b/tests/test_emails_helpers.py
index 78e24e4219..95c2d5d746 100644
--- a/tests/test_emails_helpers.py
+++ b/tests/test_emails_helpers.py
@@ -2,15 +2,13 @@ import json
import pytest
-from django.contrib.sites.models import Site
-
from saleor.order.emails_helpers import (
get_order_confirmation_markup, get_organization, get_product_data)
-def test_get_organization():
+def test_get_organization(site_settings):
example_name = 'Saleor Brand Name'
- site = Site.objects.get_current()
+ site = site_settings.site
site.name = example_name
site.save()
@@ -22,21 +20,16 @@ def test_get_product_data_without_image(order_with_lines):
"""Tested OrderLine Product has no image assigned."""
order_line = order_with_lines.get_lines()[0]
organization = get_organization()
-
result = get_product_data(order_line, organization)
assert 'image' not in result['itemOffered']
def test_get_product_data_with_image(delivery_group, product_with_image):
- order = delivery_group.order
order_line = delivery_group.order.get_lines()[0]
order_line.product = product_with_image
order_line.product_name = product_with_image.name
order_line.save()
-
- currency = order.total.currency
organization = get_organization()
-
result = get_product_data(order_line, organization)
assert 'image' in result['itemOffered']
assert result['itemOffered']['name'] == product_with_image.name
diff --git a/tests/test_sitemap.py b/tests/test_sitemap.py
index 6f0ac31f99..003a67b225 100644
--- a/tests/test_sitemap.py
+++ b/tests/test_sitemap.py
@@ -1,9 +1,9 @@
-from django.contrib.sites.models import Site
from django.urls import reverse
-def test_sitemap_uses_site_settings_domain(client, product_in_stock):
- domain = Site.objects.get_current().domain
+def test_sitemap_uses_site_settings_domain(
+ client, product_in_stock, site_settings):
+ domain = site_settings.site.domain
product_url = 'http://%(domain)s%(product_url)s' % {
'domain': domain,
'product_url': product_in_stock.get_absolute_url()}