Skip to content

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

Add toggle between HTML and JSON

NyanKiyoshibb93ccce11ef
diff --git a/saleor/core/taxes/avatax/__init__.py b/saleor/core/taxes/avatax/__init__.py
index 3150990a9f..3554732405 100644
--- a/saleor/core/taxes/avatax/__init__.py
+++ b/saleor/core/taxes/avatax/__init__.py
@@ -197,7 +197,7 @@ def get_checkout_lines_data(
for line in lines:
if not line.variant.product.charge_taxes:
continue
- description = line.variant.product.description
+ description = line.variant.product.description # FIXME: description
product = line.variant.product
product_type = line.variant.product.product_type
tax_code = retrieve_tax_code_from_meta(product)
@@ -242,7 +242,7 @@ def get_order_lines_data(order: "Order") -> List[Dict[str, str]]:
amount=line.unit_price_net.amount * line.quantity,
tax_code=tax_code,
item_code=line.variant.sku,
- description=line.variant.product.description,
+ description=line.variant.product.description, # FIXME: description
)
if order.discount_amount and order.discount_amount.amount:
append_line_to_data(
diff --git a/saleor/core/templatetags/content_formatting.py b/saleor/core/templatetags/content_formatting.py
new file mode 100644
index 0000000000..06668c886b
--- /dev/null
+++ b/saleor/core/templatetags/content_formatting.py
@@ -0,0 +1,13 @@
+import json
+
+from django import template
+from django.conf import settings
+
+register = template.Library()
+
+
[email protected]_tag("_content_formatting.html")
+def format_content(content_json, content_html):
+ if settings.USE_JSON_CONTENT:
+ return {"content_json": json.dumps(content_json)}
+ return {"content_html": content_html}
diff --git a/saleor/core/utils/draftjs.py b/saleor/core/utils/draftjs.py
new file mode 100644
index 0000000000..bb1c5739fa
--- /dev/null
+++ b/saleor/core/utils/draftjs.py
@@ -0,0 +1,16 @@
+from typing import Dict
+
+
+def json_content_to_raw_text(content: Dict[str, dict], sep: str = "\n") -> str:
+ """Converts DraftJS JSON content to plain text."""
+
+ if not isinstance(content, dict) or "blocks" not in content:
+ return ""
+
+ blocks = []
+ for block in content["blocks"]:
+ block_text = block.get("text", None).strip()
+ if block_text is not None:
+ blocks.append(block_text)
+
+ return sep.join(blocks)
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.py
index 2da5e92287..381db05404 100644
--- a/saleor/data_feeds/google_merchant.py
+++ b/saleor/data_feeds/google_merchant.py
@@ -79,7 +79,7 @@ def item_title(item: ProductVariant):
def item_description(item: ProductVariant):
- return item.product.description[:100]
+ return item.product.plain_text_description[:100]
def item_condition(item: ProductVariant):
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index b402a8c6e8..8d471f1dee 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -10,10 +10,10 @@ from ..translations.types import PageTranslation
class Page(CountableDjangoObjectType):
available_on = graphene.Date(
- deprecation_reason=("availableOn is deprecated, use publicationDate instead")
+ deprecation_reason="availableOn is deprecated, use publicationDate instead"
)
is_visible = graphene.Boolean(
- deprecation_reason=("isVisible is deprecated, use isPublished instead")
+ deprecation_reason="isVisible is deprecated, use isPublished instead"
)
translation = graphene.Field(
PageTranslation,
@@ -22,7 +22,7 @@ class Page(CountableDjangoObjectType):
description="A language code to return the translation for.",
required=True,
),
- description=("Returns translated Page fields for the given language code."),
+ description="Returns translated Page fields for the given language code.",
resolver=resolve_translation,
)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 1a9d31c2c8..39f1f22473 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -105,12 +105,6 @@ class CategoryUpdate(CategoryCreate):
model = models.Category
permissions = ("product.manage_products",)
- @classmethod
- def save(cls, info, instance, cleaned_input):
- if cleaned_input.get("background_image"):
- create_category_background_image_thumbnails.delay(instance.pk)
- instance.save()
-
class CategoryDelete(ModelDeleteMutation):
class Arguments:
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 3c2dca5dfc..c353c67f54 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -452,7 +452,7 @@ class Product(CountableDjangoObjectType):
]
@staticmethod
- def resolve_tax_rate(root: models.ProductType, info, **_kwargs):
+ def resolve_tax_rate(root: models.Product, _info, **_kwargs):
# FIXME this resolver should be dropped after we drop tax_rate from API
tax_rate = vatlayer_interface.get_tax_from_object_meta(root).code
return tax_rate or None
diff --git a/saleor/page/migrations/0008_raw_html_to_json.py b/saleor/page/migrations/0008_raw_html_to_json.py
index fa8897d6b9..8363ce7ffe 100644
--- a/saleor/page/migrations/0008_raw_html_to_json.py
+++ b/saleor/page/migrations/0008_raw_html_to_json.py
@@ -3,29 +3,37 @@
from django.db import migrations
from html_to_draftjs import html_to_draftjs
+from ...core.utils.draftjs import json_content_to_raw_text
+
def convert_pages_html_to_json(apps, schema_editor):
Page = apps.get_model("page", "Page")
- qs = Page.objects.filter(content_json={})
+ qs = Page.objects.all()
for page in qs:
- page.content_json = html_to_draftjs(page.content)
- page.save(update_fields=["content_json"])
+ content_json = page.content_json
+ content_raw = json_content_to_raw_text(content_json)
+
+ # Override the the JSON content if there was nothing in it
+ if not content_raw.strip():
+ page.description_json = html_to_draftjs(page.content)
+ page.save(update_fields=["content_json"])
PageTranslation = apps.get_model("page", "PageTranslation")
- qs = PageTranslation.objects.filter(content_json={})
+ qs = PageTranslation.objects.all()
for translation in qs:
- translation.content_json = html_to_draftjs(translation.content)
- translation.save(update_fields=["content_json"])
+ content_json = translation.content_json
+ content_raw = json_content_to_raw_text(content_json)
+
+ # Override the the JSON content if there was nothing in it
+ if not content_raw.strip():
+ translation.description_json = html_to_draftjs(translation.content)
+ translation.save(update_fields=["content_json"])
class Migration(migrations.Migration):
dependencies = [("page", "0007_auto_20190225_0252")]
- operations = [
- migrations.RunPython(convert_pages_html_to_json),
- migrations.RemoveField(model_name="page", name="content"),
- migrations.RemoveField(model_name="pagetranslation", name="content"),
- ]
+ operations = [migrations.RunPython(convert_pages_html_to_json)]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index dc68b638c9..5278d879fa 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -1,10 +1,13 @@
+from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.urls import reverse
+from django.utils.html import strip_tags
from django.utils.translation import pgettext_lazy
from ..core.models import PublishableModel, PublishedQuerySet
from ..core.utils import build_absolute_uri
+from ..core.utils.draftjs import json_content_to_raw_text
from ..core.utils.translations import TranslationProxy
from ..seo.models import SeoModel, SeoModelTranslation
@@ -18,6 +21,7 @@ class PagePublishedQuerySet(PublishedQuerySet):
class Page(SeoModel, PublishableModel):
slug = models.SlugField(unique=True, max_length=100)
title = models.CharField(max_length=200)
+ content = models.TextField(blank=True)
content_json = JSONField(blank=True, default=dict)
created = models.DateTimeField(auto_now_add=True)
@@ -33,6 +37,12 @@ class Page(SeoModel, PublishableModel):
def __str__(self):
return self.title
+ @property
+ def plain_text_content(self):
+ if settings.USE_JSON_CONTENT:
+ return json_content_to_raw_text(self.content_json)
+ return strip_tags(self.content)
+
def get_absolute_url(self):
return reverse("page:details", kwargs={"slug": self.slug})
@@ -46,6 +56,7 @@ class PageTranslation(SeoModelTranslation):
Page, related_name="translations", on_delete=models.CASCADE
)
title = models.CharField(max_length=255, blank=True)
+ content = models.TextField(blank=True)
content_json = JSONField(blank=True, default=dict)
class Meta:
diff --git a/saleor/page/views.py b/saleor/page/views.py
index 0e38020c3f..6807b46d60 100644
--- a/saleor/page/views.py
+++ b/saleor/page/views.py
@@ -1,5 +1,4 @@
import datetime
-import json
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
@@ -17,6 +16,7 @@ def page_details(request, slug):
{
"page": page,
"is_visible": is_visible,
- "content_json": json.dumps(page.translated.content_json),
+ "content_json": page.translated.content_json,
+ "content_html": page.translated.content,
},
)
diff --git a/saleor/product/migrations/0096_raw_html_to_json.py b/saleor/product/migrations/0096_raw_html_to_json.py
index 551147ce9f..0432297cb8 100644
--- a/saleor/product/migrations/0096_raw_html_to_json.py
+++ b/saleor/product/migrations/0096_raw_html_to_json.py
@@ -3,29 +3,37 @@
from django.db import migrations
from html_to_draftjs import html_to_draftjs
+from ...core.utils.draftjs import json_content_to_raw_text
+
def convert_products_html_to_json(apps, schema_editor):
Product = apps.get_model("product", "Product")
- qs = Product.objects.filter(description_json={})
+ qs = Product.objects.all()
for product in qs:
- product.description_json = html_to_draftjs(product.description)
- product.save(update_fields=["description_json"])
+ description_json = product.description_json
+ description_raw = json_content_to_raw_text(description_json)
+
+ # Override the the JSON description if there was nothing in it
+ if not description_raw.strip():
+ product.description_json = html_to_draftjs(product.description)
+ product.save(update_fields=["description_json"])
ProductTranslation = apps.get_model("product", "ProductTranslation")
- qs = ProductTranslation.objects.filter(description_json={})
+ qs = ProductTranslation.objects.all()
for translation in qs:
- translation.description_json = html_to_draftjs(translation.description)
- translation.save(update_fields=["description_json"])
+ description_json = translation.description_json
+ description_raw = json_content_to_raw_text(description_json)
+
+ # Override the the JSON description if there was nothing in it
+ if not description_raw:
+ translation.description_json = html_to_draftjs(translation.description)
+ translation.save(update_fields=["description_json"])
class Migration(migrations.Migration):
dependencies = [("product", "0095_auto_20190618_0842")]
- operations = [
- migrations.RunPython(convert_products_html_to_json),
- migrations.RemoveField(model_name="product", name="description"),
- migrations.RemoveField(model_name="producttranslation", name="description"),
- ]
+ operations = [migrations.RunPython(convert_products_html_to_json)]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 6407f66dad..47d9fdd8e9 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -9,6 +9,7 @@ from django.db import models
from django.db.models import F
from django.urls import reverse
from django.utils.encoding import smart_text
+from django.utils.html import strip_tags
from django.utils.text import slugify
from django.utils.translation import pgettext_lazy
from django_measurement.models import MeasurementField
@@ -24,6 +25,7 @@ from versatileimagefield.fields import PPOIField, VersatileImageField
from ..core.exceptions import InsufficientStock
from ..core.models import PublishableModel, PublishedQuerySet, SortableModel
from ..core.utils import build_absolute_uri
+from ..core.utils.draftjs import json_content_to_raw_text
from ..core.utils.json_serializer import CustomJsonEncoder
from ..core.utils.translations import TranslationProxy
from ..core.weight import WeightUnits, zero_weight
@@ -123,6 +125,7 @@ class Product(SeoModel, PublishableModel):
ProductType, related_name="products", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
+ description = models.TextField(blank=True)
description_json = JSONField(blank=True, default=dict)
category = models.ForeignKey(
Category, related_name="products", on_delete=models.CASCADE
@@ -170,6 +173,12 @@ class Product(SeoModel, PublishableModel):
def __str__(self):
return self.name
+ @property
+ def plain_text_description(self):
+ if settings.USE_JSON_CONTENT:
+ return json_content_to_raw_text(self.description_json)
+ return strip_tags(self.description)
+
@property
def is_available(self):
return self.is_visible and self.is_in_stock()
@@ -203,6 +212,7 @@ class ProductTranslation(SeoModelTranslation):
Product, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
+ description = models.TextField(blank=True)
description_json = JSONField(blank=True, default=dict)
class Meta:
diff --git a/saleor/product/views.py b/saleor/product/views.py
index 65fc0e5fe3..48e037031e 100644
--- a/saleor/product/views.py
+++ b/saleor/product/views.py
@@ -90,7 +90,8 @@ def product_details(request, slug, product_id, form=None):
show_variant_picker = all([v.attributes for v in product.variants.all()])
json_ld_data = product_json_ld(product, product_attributes)
ctx = {
- "description_json": json.dumps(product.translated.description_json),
+ "description_json": product.translated.description_json,
+ "description_html": product.translated.description,
"is_visible": is_visible,
"form": form,
"availability": availability,
diff --git a/saleor/seo/schema/product.py b/saleor/seo/schema/product.py
index 09b8e7ebe9..06235209ca 100644
--- a/saleor/seo/schema/product.py
+++ b/saleor/seo/schema/product.py
@@ -25,7 +25,7 @@ def product_json_ld(product, attributes=None):
"@type": "Product",
"name": smart_text(product),
"image": [product_image.image.url for product_image in product.images.all()],
- "description": product.description,
+ "description": product.plain_text_description,
"offers": [],
}
diff --git a/saleor/settings.py b/saleor/settings.py
index becf9e452c..b29c3f5d6a 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -667,3 +667,8 @@ GRAPHENE = {
EXTENSIONS_MANAGER = "saleor.core.extensions.manager.ExtensionsManager"
PLUGINS = os.environ.get("PLUGINS", [])
+
+# Whether DraftJS should be used be used instead of HTML
+# True to use DraftJS (JSON based), for the 2.0 dashboard
+# False to use the old editor from dashboard 1.0
+USE_JSON_CONTENT = get_bool_from_env("USE_JSON_CONTENT", False)
diff --git a/templates/_content_formatting.html b/templates/_content_formatting.html
new file mode 100644
index 0000000000..c5d7f1f5a3
--- /dev/null
+++ b/templates/_content_formatting.html
@@ -0,0 +1,5 @@
+{% if content_json %}
+ <div data-description-json='{{ content_json|safe }}'></div>
+{% else %}
+ {{ content_html|safe }}
+{% endif %}
diff --git a/templates/dashboard/page/form.html b/templates/dashboard/page/form.html
index b6a56aeee9..c0c195e18e 100644
--- a/templates/dashboard/page/form.html
+++ b/templates/dashboard/page/form.html
@@ -64,7 +64,7 @@
{{ form.title|materializecss }}
</div>
<div class="row">
- {{ form.content|materializecss }}
+ {{ form.content|materializecss }} {# FIXME: warn? #}
</div>
{% include "dashboard/includes/_google_preview.html" with object=page form=form %}
</div>
diff --git a/templates/page/details.html b/templates/page/details.html
index bc0612e55c..87072203d0 100644
--- a/templates/page/details.html
+++ b/templates/page/details.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load materializecss %}
{% load build_absolute_uri from urls %}
+{% load format_content from content_formatting %}
{% block title %}
{% if page.seo_title %}
@@ -51,5 +52,7 @@
{% endblocktrans %}
</div>
{% endif %}
- <div data-description-json='{{ content_json|safe }}'></div>
+ <div class="content">
+ {% format_content content_json=content_json content_html=content_html %}
+ </div>
{% endblock %}
diff --git a/templates/product/details.html b/templates/product/details.html
index e39849ea00..1672a766e1 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -10,6 +10,7 @@
{% load placeholder %}
{% load static %}
{% load taxed_prices %}
+{% load format_content from content_formatting %}
{% block title %}
{% if product.seo_title %}
@@ -193,7 +194,7 @@
<div class="product__info__description">
<h3>{% trans "Description" context "Product details title" %}</h3>
<hr>
- <div data-description-json='{{ description_json|safe }}'></div>
+ {% format_content content_json=description_json content_html=description_html %}
</div>
<hr>
<table>
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 9624faab25..58e83909ad 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -668,7 +668,10 @@ def test_create_product(
product_type,
category,
size_attribute,
+ description_json,
+ description_raw,
permission_manage_products,
+ settings,
monkeypatch,
):
query = """
@@ -676,7 +679,6 @@ def test_create_product(
$productTypeId: ID!,
$categoryId: ID!,
$name: String!,
- $description: String!,
$descriptionJson: JSONString!,
$isPublished: Boolean!,
$chargeTaxes: Boolean!,
@@ -688,7 +690,6 @@ def test_create_product(
category: $categoryId,
productType: $productTypeId,
name: $name,
- description: $description,
descriptionJson: $descriptionJson,
isPublished: $isPublished,
chargeTaxes: $chargeTaxes,
@@ -700,7 +701,6 @@ def test_create_product(
category {
name
}
- description
descriptionJson
isPublished
chargeTaxes
@@ -732,10 +732,12 @@ def test_create_product(
}
"""
+ settings.USE_JSON_CONTENT = True
+
+ description_json = json.dumps(description_json)
+
product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)
category_id = graphene.Node.to_global_id("Category", category.pk)
- product_description = "test description"
- product_description_json = json.dumps({"content": "description"})
product_name = "test name"
product_is_published = True
product_charge_taxes = True
@@ -763,8 +765,7 @@ def test_create_product(
"productTypeId": product_type_id,
"categoryId": category_id,
"name": product_name,
- "description": product_description,
- "descriptionJson": product_description_json,
+ "descriptionJson": description_json,
"isPublished": product_is_published,
"chargeTaxes": product_charge_taxes,
"taxCode": product_tax_rate,
@@ -782,8 +783,7 @@ def test_create_product(
data = content["data"]["productCreate"]
assert data["errors"] == []
assert data["product"]["name"] == product_name
- assert data["product"]["description"] == product_description
- assert data["product"]["descriptionJson"] == product_description_json
+ assert data["product"]["descriptionJson"] == description_json
assert data["product"]["isPublished"] == product_is_published
assert data["product"]["chargeTaxes"] == product_charge_taxes
assert data["product"]["taxType"]["taxCode"] == product_tax_rate
@@ -802,7 +802,6 @@ QUERY_CREATE_PRODUCT_WITHOUT_VARIANTS = """
$productTypeId: ID!,
$categoryId: ID!
$name: String!,
- $description: String!,
$basePrice: Decimal!,
$sku: String,
$quantity: Int,
@@ -813,7 +812,6 @@ QUERY_CREATE_PRODUCT_WITHOUT_VARIANTS = """
category: $categoryId,
productType: $productTypeId,
name: $name,
- description: $description,
basePrice: $basePrice,
sku: $sku,
quantity: $quantity,
@@ -854,7 +852,6 @@ def test_create_product_without_variants(
product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)
category_id = graphene.Node.to_global_id("Category", category.pk)
product_name = "test name"
- product_description = "description"
product_price = 10
sku = "sku"
quantity = 1
@@ -864,7 +861,6 @@ def test_create_product_without_variants(
"productTypeId": product_type_id,
"categoryId": category_id,
"name": product_name,
- "description": product_description,
"basePrice": product_price,
"sku": sku,
"quantity": quantity,
@@ -894,7 +890,6 @@ def test_create_product_without_variants_sku_validation(
product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)
category_id = graphene.Node.to_global_id("Category", category.pk)
product_name = "test name"
- product_description = "description"
product_price = 10
quantity = 1
track_inventory = True
@@ -903,7 +898,6 @@ def test_create_product_without_variants_sku_validation(
"productTypeId": product_type_id,
"categoryId": category_id,
"name": product_name,
- "description": product_description,
"basePrice": product_price,
"sku": None,
"quantity": quantity,
@@ -932,7 +926,6 @@ def test_create_product_without_variants_sku_duplication(
product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)
category_id = graphene.Node.to_global_id("Category", category.pk)
product_name = "test name"
- product_description = "description"
product_price = 10
quantity = 1
track_inventory = True
@@ -942,7 +935,6 @@ def test_create_product_without_variants_sku_duplication(
"productTypeId": product_type_id,
"categoryId": category_id,
"name": product_name,
- "description": product_description,
"basePrice": product_price,
"sku": sku,
"quantity": quantity,
@@ -994,7 +986,10 @@ def test_update_product(
category,
non_default_category,
product,
+ other_description_json,
+ other_description_raw,
permission_manage_products,
+ settings,
monkeypatch,
):
query = """
@@ -1002,7 +997,7 @@ def test_update_product(
$productId: ID!,
$categoryId: ID!,
$name: String!,
- $description: String!,
+ $descriptionJson: JSONString!,
$isPublished: Boolean!,
$chargeTaxes: Boolean!,
$taxCode: String!,
@@ -1013,7 +1008,7 @@ def test_update_product(
input: {
category: $categoryId,
name: $name,
- description: $description,
+ descriptionJson: $descriptionJson,
isPublished: $isPublished,
chargeTaxes: $chargeTaxes,
taxCode: $taxCode,
@@ -1024,7 +1019,7 @@ def test_update_product(
category {
name
}
- description
+ descriptionJson
isPublished
chargeTaxes
taxType {
@@ -1054,9 +1049,13 @@ def test_update_product(
}
}
"""
+
+ settings.USE_JSON_CONTENT = True
+
+ other_description_json = json.dumps(other_description_json)
+
product_id = graphene.Node.to_global_id("Product", product.pk)
category_id = graphene.Node.to_global_id("Category", non_default_category.pk)
- product_description = "updated description"
product_name = "updated name"
product_is_published = True
product_charge_taxes = True
@@ -1073,7 +1072,7 @@ def test_update_product(
"productId": product_id,
"categoryId": category_id,
"name": product_name,
- "description": product_description,
+ "descriptionJson": other_description_json,
"isPublished": product_is_published,
"chargeTaxes": product_charge_taxes,
"taxCode": product_tax_rate,
@@ -1087,7 +1086,7 @@ def test_update_product(
data = content["data"]["productUpdate"]
assert data["errors"] == []
assert data["product"]["name"] == product_name
- assert data["product"]["description"] == product_description
+ assert data["product"]["descriptionJson"] == other_description_json
assert data["product"]["isPublished"] == product_is_published
assert data["product"]["chargeTaxes"] == product_charge_taxes
assert data["product"]["taxType"]["taxCode"] == product_tax_rate
@@ -1102,8 +1101,7 @@ def test_update_product_without_variants(
$productId: ID!,
$sku: String,
$quantity: Int,
- $trackInventory: Boolean,
- $description: String)
+ $trackInventory: Boolean)
{
productUpdate(
id: $productId,
@@ -1111,7 +1109,6 @@ def test_update_product_without_variants(
sku: $sku,
quantity: $quantity,
trackInventory: $trackInventory,
- description: $description
})
{
product {
@@ -1136,14 +1133,12 @@ def test_update_product_without_variants(
product_sku = "test_sku"
product_quantity = 10
product_track_inventory = False
- product_description = "test description"
variables = {
"productId": product_id,
"sku": product_sku,
"quantity": product_quantity,
"trackInventory": product_track_inventory,
- "description": product_description,
}
response = staff_api_client.post_graphql(
diff --git a/tests/conftest.py b/tests/conftest.py
index 71877d7316..925e6adcd9 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1232,3 +1232,138 @@ def digital_content_url(digital_content, order_line):
@pytest.fixture
def media_root(tmpdir, settings):
settings.MEDIA_ROOT = str(tmpdir.mkdir("media"))
+
+
+def description_json():
+ return {
+ "blocks": [
+ {
+ "key": "",
+ "data": {},
+ "text": "E-commerce for the PWA era",
+ "type": "header-two",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": (
+ "A modular, high performance e-commerce storefront "
+ "built with GraphQL, Django, and ReactJS."
+ ),
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": "",
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": (
+ "Saleor is a rapidly-growing open source e-commerce platform "
+ "that has served high-volume companies from branches "
+ "like publishing and apparel since 2012. Based on Python "
+ "and Django, the latest major update introduces a modular "
+ "front end with a GraphQL API and storefront and dashboard "
+ "written in React to make Saleor a full-functionality "
+ "open source e-commerce."
+ ),
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": "",
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": "Get Saleor today!",
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [{"key": 0, "length": 17, "offset": 0}],
+ "inlineStyleRanges": [],
+ },
+ ],
+ "entityMap": {
+ "0": {
+ "data": {"href": "https://github.com/mirumee/saleor"},
+ "type": "LINK",
+ "mutability": "MUTABLE",
+ }
+ },
+ }
+
+
+def description_raw():
+ return """\
+E-commerce for the PWA era
+A modular, high performance e-commerce storefront built with GraphQL, Django, \
+and ReactJS.
+
+Saleor is a rapidly-growing open source e-commerce platform that has served \
+high-volume companies from branches like publishing and apparel since 2012. \
+Based on Python and Django, the latest major update introduces a modular \
+front end with a GraphQL API and storefront and dashboard written in React \
+to make Saleor a full-functionality open source e-commerce.
+
+Get Saleor today!"""
+
+
+def other_description_json():
+ return {
+ "blocks": [
+ {
+ "key": "",
+ "data": {},
+ "text": "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS",
+ "type": "header-two",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ {
+ "key": "",
+ "data": {},
+ "text": (
+ "Saleor is powered by a GraphQL server running on "
+ "top of Python 3 and a Django 2 framework."
+ ),
+ "type": "unstyled",
+ "depth": 0,
+ "entityRanges": [],
+ "inlineStyleRanges": [],
+ },
+ ],
+ "entityMap": {},
+ }
+
+
+def other_description_raw():
+ return (
+ "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS\n"
+ "Saleor is powered by a GraphQL server running on top of Python 3 "
+ "and a Django 2 framework."
+ )
diff --git a/tests/settings.py b/tests/settings.py
index b83b7fe874..9d29313a48 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -41,3 +41,4 @@ MAX_CHECKOUT_LINE_QUANTITY = 50
PASSWORD_HASHERS = ["tests.dummy_password_hasher.DummyHasher"]
+USE_JSON_CONTENT = False