Skip to content

Commit

Permalink
Review fixes - graphql field type, simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
k-brk committed Dec 6, 2018
1 parent 5906c4c commit 04c5b22
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion saleor/graphql/product/mutations/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')


Expand Down
4 changes: 2 additions & 2 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ input CollectionCreateInput {
description: String
backgroundImage: Upload
seo: SeoInput
publishedDate: String
publishedDate: Date
products: [ID]
}

Expand All @@ -455,7 +455,7 @@ input CollectionInput {
description: String
backgroundImage: Upload
seo: SeoInput
publishedDate: String
publishedDate: Date
}

type CollectionRemoveProducts {
Expand Down
12 changes: 5 additions & 7 deletions templates/dashboard/includes/_collection_availability.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
6 changes: 3 additions & 3 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ def post(self, data=None, **kwargs):
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)

Expand All @@ -51,7 +51,7 @@ def post_graphql(
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:
Expand Down
12 changes: 6 additions & 6 deletions tests/api/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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}
Expand All @@ -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


Expand Down
5 changes: 3 additions & 2 deletions tests/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from django.core.serializers.json import DjangoJSONEncoder

from saleor.graphql.core.utils import snake_to_camel_case

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 04c5b22

Please sign in to comment.