Skip to content

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

Review fixes - graphql field type, simplified logic

k-brk04c5b22f3c8b
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 362fcd3a56..74eeda8b4f 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -110,7 +110,7 @@ class CollectionInput(graphene.InputObjectType):
description = graphene.String(description='Description of the collection.')
background_image = Upload(description='Background image file.')
seo = SeoInput(description='Search engine optimization fields.')
- published_date = graphene.String(
+ published_date = graphene.Date(
description='Publication date. ISO 8601 standard.')
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 2444b63ad0..ccb8c2cafa 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -439,7 +439,7 @@ input CollectionCreateInput {
description: String
backgroundImage: Upload
seo: SeoInput
- publishedDate: String
+ publishedDate: Date
products: [ID]
}
@@ -455,7 +455,7 @@ input CollectionInput {
description: String
backgroundImage: Upload
seo: SeoInput
- publishedDate: String
+ publishedDate: Date
}
type CollectionRemoveProducts {
diff --git a/templates/dashboard/includes/_collection_availability.html b/templates/dashboard/includes/_collection_availability.html
index 7cd9a2ad70..fdffa53018 100644
--- a/templates/dashboard/includes/_collection_availability.html
+++ b/templates/dashboard/includes/_collection_availability.html
@@ -3,14 +3,12 @@
<div class="label label-{{ label_cls }}">
{% if is_visible %}
{% trans "Published" context "Collection availability status" %}
- {% elif not collection.is_published %}
- {% trans "Hidden" context "Collection availability status" %}
{% elif collection.published_date is not None %}
- <div class="label">
- {% blocktrans with date=collection.published_date context "Collection availability status" %}
- Hidden (will become visible on {{ date }})
- {% endblocktrans %}
- </div>
+ <div class="label">
+ {% blocktrans with date=collection.published_date context "Collection availability status" %}
+ Hidden (will become visible on {{ date }})
+ {% endblocktrans %}
+ </div>
{% else %}
{% trans "Hidden" context "Collection availability status" %}
{% endif %}
diff --git a/tests/api/conftest.py b/tests/api/conftest.py
index b4e5b41f45..fbe4801ecb 100644
--- a/tests/api/conftest.py
+++ b/tests/api/conftest.py
@@ -1,5 +1,5 @@
import json
-
+from django.core.serializers.json import DjangoJSONEncoder
import pytest
from django.contrib.auth.models import AnonymousUser
from django.shortcuts import reverse
@@ -35,7 +35,7 @@ class ApiClient(Client):
handling multipart requests in Graphene.
"""
if data:
- data = json.dumps(data)
+ data = json.dumps(data, cls=DjangoJSONEncoder)
kwargs['content_type'] = 'application/json'
return super().post(API_PATH, data, **kwargs)
@@ -51,7 +51,7 @@ class ApiClient(Client):
if variables is not None:
data['variables'] = variables
if data:
- data = json.dumps(data)
+ data = json.dumps(data, cls=DjangoJSONEncoder)
kwargs['content_type'] = 'application/json'
if permissions:
diff --git a/tests/api/test_collection.py b/tests/api/test_collection.py
index 88ec3e71f9..accfe3c1c4 100644
--- a/tests/api/test_collection.py
+++ b/tests/api/test_collection.py
@@ -54,7 +54,7 @@ def test_create_collection(
monkeypatch, staff_api_client, product_list, permission_manage_products):
query = """
mutation createCollection(
- $name: String!, $slug: String!, $description: String, $products: [ID], $backgroundImage: Upload!, $isPublished: Boolean!, $publishedDate: String) {
+ $name: String!, $slug: String!, $description: String, $products: [ID], $backgroundImage: Upload!, $isPublished: Boolean!, $publishedDate: Date) {
collectionCreate(
input: {name: $name, slug: $slug, description: $description, products: $products, backgroundImage: $backgroundImage, isPublished: $isPublished, publishedDate: $publishedDate}) {
collection {
@@ -86,7 +86,7 @@ def test_create_collection(
name = 'test-name'
slug = 'test-slug'
description = 'test-description'
- published_date = date.today().isoformat()
+ published_date = date.today()
variables = {
'name': name, 'slug': slug, 'description': description,
'products': product_ids, 'backgroundImage': image_name,
@@ -99,7 +99,7 @@ def test_create_collection(
assert data['name'] == name
assert data['slug'] == slug
assert data['description'] == description
- assert data['publishedDate'] == published_date
+ assert data['publishedDate'] == published_date.isoformat()
assert data['products']['totalCount'] == len(product_ids)
collection = Collection.objects.get(slug=slug)
assert collection.background_image.file
@@ -139,7 +139,7 @@ def test_update_collection(
monkeypatch, staff_api_client, collection, permission_manage_products):
query = """
mutation updateCollection(
- $name: String!, $slug: String!, $description: String, $id: ID!, $isPublished: Boolean!, $publishedDate: String) {
+ $name: String!, $slug: String!, $description: String, $id: ID!, $isPublished: Boolean!, $publishedDate: Date) {
collectionUpdate(
id: $id, input: {name: $name, slug: $slug, description: $description, isPublished: $isPublished, publishedDate: $publishedDate}) {
collection {
@@ -161,7 +161,7 @@ def test_update_collection(
name = 'new-name'
slug = 'new-slug'
description = 'new-description'
- published_date = date.today().isoformat()
+ published_date = date.today()
variables = {
'name': name, 'slug': slug, 'description': description,
'id': to_global_id('Collection', collection.id), 'isPublished': True, 'publishedDate': published_date}
@@ -171,7 +171,7 @@ def test_update_collection(
data = content['data']['collectionUpdate']['collection']
assert data['name'] == name
assert data['slug'] == slug
- assert data['publishedDate'] == published_date
+ assert data['publishedDate'] == published_date.isoformat()
assert mock_create_thumbnails.call_count == 0
diff --git a/tests/api/utils.py b/tests/api/utils.py
index e85c63cce6..9a83312581 100644
--- a/tests/api/utils.py
+++ b/tests/api/utils.py
@@ -1,4 +1,5 @@
import json
+from django.core.serializers.json import DjangoJSONEncoder
from saleor.graphql.core.utils import snake_to_camel_case
@@ -31,8 +32,8 @@ def get_multipart_request_body(query, variables, file, file_name):
of additional 'operations' and 'map' keys.
"""
return {
- 'operations': json.dumps({'query': query, 'variables': variables}),
- 'map': json.dumps({file_name: ['variables.file']}), file_name: file}
+ 'operations': json.dumps({'query': query, 'variables': variables}, cls=DjangoJSONEncoder),
+ 'map': json.dumps({file_name: ['variables.file']}, cls=DjangoJSONEncoder), file_name: file}
def convert_dict_keys_to_camel_case(d):
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 5327ffbd4f..2a14c1a403 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -40,13 +40,13 @@ def test_collection_not_yet_published_returns_404(
response = client.get(url)
assert response.status_code == 404
- # A non staff user should not have access to collections yet to be published
- # A staff user should have access to collections yet to be published
draft_collection.is_published = True
draft_collection.published_date = date.today() + timedelta(days=1)
draft_collection.save()
+
+ # A non staff user should not have access to collections yet to be published
response = client.get(url)
assert response.status_code == 404
-
+ # A staff user should have access to collections yet to be published
response = admin_client.get(url)
assert response.status_code == 200