Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test helper
Pacu2dd699cbefeff
diff --git a/tests/test_collection.py b/tests/test_collection.pyindex 3544920903..abfc188788 100644--- a/tests/test_collection.py+++ b/tests/test_collection.py@@ -2,7 +2,7 @@ import pytestfrom django.urls import reverse-from .utils import get_redirect_location+from .utils import get_redirect_location, seo_field_test_helperdef test_collection_index(client, collection):@@ -42,11 +42,10 @@ def test_collection_not_exists(client):('Title', None, 'Title')))def test_page_get_seo_title(admin_client, collection, title, seo_title, expected_result):- collection.name = title- collection.seo_title = seo_title- collection.save()- result = collection.get_seo_title()- expected_result == result+ seo_field_test_helper(+ collection, 'get_seo_title',+ {'name': title, 'seo_title': seo_title},+ expected_result)@pytest.mark.parametrize(@@ -56,7 +55,7 @@ def test_page_get_seo_title((None, '')))def test_page_get_seo_description(admin_client, collection, seo_description, expected_result):- collection.seo_description = seo_description- collection.save()- result = collection.get_seo_description()- expected_result == result+ seo_field_test_helper(+ collection, 'get_seo_description',+ {'seo_description': seo_description},+ expected_result)diff --git a/tests/test_page.py b/tests/test_page.pyindex 5880450860..b00dfc75c5 100644--- a/tests/test_page.py+++ b/tests/test_page.py@@ -1,5 +1,7 @@import pytest+from .utils import seo_field_test_helper+def test_draft_page_detail(client, admin_client, page):page_url = page.get_absolute_url()@@ -26,11 +28,10 @@ def test_public_page_detail(client, admin_client, page):('Title', None, 'Title')))def test_page_get_seo_title(admin_client, page, title, seo_title, expected_result):- page.title = title- page.seo_title = seo_title- page.save()- result = page.get_seo_title()- expected_result == result+ seo_field_test_helper(+ page, 'get_seo_title',+ {'title': title, 'seo_title': seo_title},+ expected_result)@pytest.mark.parametrize(@@ -40,7 +41,7 @@ def test_page_get_seo_title((None, '')))def test_page_get_seo_description(admin_client, page, seo_description, expected_result):- page.seo_description = seo_description- page.save()- result = page.get_seo_description()- expected_result == result+ seo_field_test_helper(+ page, 'get_seo_description',+ {'seo_description': seo_description},+ expected_result)diff --git a/tests/test_product.py b/tests/test_product.pyindex f850775167..a115e85481 100644--- a/tests/test_product.py+++ b/tests/test_product.py@@ -5,7 +5,7 @@ from unittest.mock import Mockimport pytestfrom django.urls import reversefrom django.utils.encoding import smart_text-from tests.utils import filter_products_by_attribute+from tests.utils import filter_products_by_attribute, seo_field_test_helperfrom saleor.cart import CartStatus, utilsfrom saleor.cart.models import Cart@@ -541,11 +541,10 @@ def test_include_products_from_subcategories_in_main_view(('Title', None, 'Title')))def test_product_get_seo_title(admin_client, product_in_stock, title, seo_title, expected_result):- product_in_stock.name = title- product_in_stock.seo_title = seo_title- product_in_stock.save()- result = product_in_stock.get_seo_title()- expected_result == result+ seo_field_test_helper(+ product_in_stock, 'get_seo_title',+ {'name': title, 'seo_title': seo_title},+ expected_result)@pytest.mark.parametrize(@@ -556,11 +555,10 @@ def test_product_get_seo_title(def test_product_get_seo_description(admin_client, product_in_stock, description, seo_description,expected_result):- product_in_stock.description = description- product_in_stock.seo_description = seo_description- product_in_stock.save()- result = product_in_stock.get_seo_description()- expected_result == result+ seo_field_test_helper(+ product_in_stock, 'get_seo_description',+ {'description': description, 'seo_description': seo_description},+ expected_result)@pytest.mark.parametrize(@@ -570,23 +568,21 @@ def test_product_get_seo_description(('Title', None, 'Title')))def test_category_get_seo_title(admin_client, default_category, title, seo_title, expected_result):- default_category.name = title- default_category.seo_title = seo_title- default_category.save()- result = default_category.get_seo_title()- expected_result == result+ seo_field_test_helper(+ default_category, 'get_seo_title',+ {'name': title, 'seo_title': seo_title},+ expected_result)@pytest.mark.parametrize('description, seo_description, expected_result',(('Description', 'Seo', 'Seo'),- ('Description', None, '')))+ ('Description', None, 'Description')))def test_category_get_seo_description(admin_client, default_category, description, seo_description,expected_result):- default_category.description = description- default_category.seo_description = seo_description- default_category.save()- result = default_category.get_seo_description()- expected_result == result+ seo_field_test_helper(+ default_category, 'get_seo_description',+ {'description': description, 'seo_description': seo_description},+ expected_result)diff --git a/tests/utils.py b/tests/utils.pyindex f79b74b5f5..a00c813ead 100644--- a/tests/utils.py+++ b/tests/utils.py@@ -25,3 +25,13 @@ def filter_products_by_attribute(queryset, attribute_id, value):def get_graphql_content(response):return json.loads(response.content.decode('utf8'))+++def seo_field_test_helper(object, function_name, field_values, expected_result):+ """Helper for testing seo fields."""+ for field_name, field_value in field_values.items():+ setattr(object, field_name, field_value)+ object.save()+ get_seo_field_function = getattr(object, function_name)+ result = get_seo_field_function()+ assert expected_result == result