Skip to content

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

Add tests for shipping method

akjanik1133b885dfd3
diff --git a/tests/api/test_shipping_method.py b/tests/api/test_shipping_method.py
index a169474703..221fd31352 100644
--- a/tests/api/test_shipping_method.py
+++ b/tests/api/test_shipping_method.py
@@ -1,6 +1,7 @@
import json
import graphene
+import pytest
from django.shortcuts import reverse
from tests.utils import get_graphql_content
@@ -40,10 +41,9 @@ def test_shipping_method_query(user_api_client, shipping_method):
no_ppc = shipping_method.price_per_country.count()
assert len(shipping_data['pricePerCountry']) == no_ppc
price_range = shipping.price_range
- assert shipping_data[
- 'priceRange']['start']['amount'] == price_range.start.amount
- assert shipping_data[
- 'priceRange']['stop']['amount'] == price_range.stop.amount
+ data_price_range = shipping_data['priceRange']
+ assert data_price_range['start']['amount'] == price_range.start.amount
+ assert data_price_range['stop']['amount'] == price_range.stop.amount
def test_shipping_methods_query(user_api_client, shipping_method):
@@ -61,3 +61,69 @@ def test_shipping_methods_query(user_api_client, shipping_method):
content = get_graphql_content(response)
assert 'errors' not in content
assert content['data']['shippingMethods']['totalCount'] == no_shippings
+
+
+def test_create_shipping_method(admin_api_client):
+ query = """
+ mutation createShipping{
+ shippingMethodCreate(
+ input: {name: "test shipping", description: "test desc"}) {
+ shippingMethod {
+ name
+ description
+ }
+ }
+ }
+ """
+ response = admin_api_client.post(reverse('api'), {'query': query})
+ content = get_graphql_content(response)
+ assert 'errors' not in content
+ data = content['data']['shippingMethodCreate']['shippingMethod']
+ assert data['name'] == 'test shipping'
+ assert data['description'] == 'test desc'
+
+
+def test_update_shipping_method(admin_api_client, shipping_method):
+ query = """
+ mutation updateShipping($id: ID!, $name: String) {
+ shippingMethodUpdate(id: $id, input: {name: $name}) {
+ shippingMethod {
+ name
+ }
+ }
+ }
+ """
+ name = 'Parabolic name'
+ shipping_id = graphene.Node.to_global_id(
+ 'ShippingMethod', shipping_method.pk)
+ assert shipping_method.name != name
+ variables = json.dumps({'id': shipping_id, 'name': name})
+ response = admin_api_client.post(
+ reverse('api'), {'query': query, 'variables': variables})
+ content = get_graphql_content(response)
+ assert 'errors' not in content
+ data = content['data']['shippingMethodUpdate']['shippingMethod']
+ assert data['name'] == name
+
+
+def test_delete_shipping_method(admin_api_client, shipping_method):
+ query = """
+ mutation deleteShippingMethod($id: ID!) {
+ shippingMethodDelete(id: $id) {
+ shippingMethod {
+ name
+ }
+ }
+ }
+ """
+ shipping_method_id = graphene.Node.to_global_id(
+ 'ShippingMethod', shipping_method.pk)
+ variables = json.dumps({'id': shipping_method_id})
+ response = admin_api_client.post(
+ reverse('api'), {'query': query, 'variables': variables})
+ content = get_graphql_content(response)
+ assert 'errors' not in content
+ data = content['data']['shippingMethodDelete']['shippingMethod']
+ assert data['name'] == shipping_method.name
+ with pytest.raises(shipping_method._meta.model.DoesNotExist):
+ shipping_method.refresh_from_db()