Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove code from graphql gift card query
fowczarekff5db8267aa1
diff --git a/saleor/graphql/giftcard/types.py b/saleor/graphql/giftcard/types.pyindex 5b4747b803..3809840772 100644--- a/saleor/graphql/giftcard/types.py+++ b/saleor/graphql/giftcard/types.py@@ -24,7 +24,6 @@ class GiftCard(CountableDjangoObjectType):card codes. """)only_fields = [- "code","user","created","start_date",@@ -37,9 +36,11 @@ class GiftCard(CountableDjangoObjectType):interfaces = [graphene.relay.Node]model = models.GiftCard- def resolve_display_code(self, _info):- return self.display_code+ @staticmethod+ def resolve_display_code(root: models.GiftCard, *_args, **_kwargs):+ return root.display_code+ @staticmethod@permission_required("giftcard.manage_gift_card")- def resolve_user(self, _info):- return self.user+ def resolve_user(root: models.GiftCard, *_args, **_kwargs):+ return root.userdiff --git a/tests/api/test_checkout_promo_codes.py b/tests/api/test_checkout_promo_codes.pyindex c9349b66b4..0c72d1f9af 100644--- a/tests/api/test_checkout_promo_codes.py+++ b/tests/api/test_checkout_promo_codes.py@@ -9,7 +9,6 @@ from tests.api.utils import get_graphql_contentfrom saleor.checkout.utils import add_voucher_to_checkout-MUTATION_CHECKOUT_UPDATE_VOUCHER = """mutation($checkoutId: ID!, $voucherCode: String) {checkoutUpdateVoucher(@@ -268,7 +267,8 @@ MUTATION_CHECKOUT_ADD_PROMO_CODE = """id,voucherCodegiftCards {- code+ id+ displayCode}totalPrice {gross {@@ -313,12 +313,14 @@ def test_checkout_add_voucher_code_not_applicable_voucher(def test_checkout_add_gift_card_code(api_client, checkout_with_item, gift_card):checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}data = _mutate_checkout_add_promo_code(api_client, variables)assert not data["errors"]assert data["checkout"]["id"] == checkout_id- assert data["checkout"]["giftCards"][0]["code"] == gift_card.code+ assert data["checkout"]["giftCards"][0]["id"] == gift_card_id+ assert data["checkout"]["giftCards"][0]["displayCode"] == gift_card.display_codedef test_checkout_add_many_gift_card_code(@@ -326,6 +328,7 @@ def test_checkout_add_many_gift_card_code():assert checkout_with_gift_card.gift_cards.count() > 0checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card_created_by_staff.pk)variables = {"checkoutId": checkout_id,"promoCode": gift_card_created_by_staff.code,@@ -334,7 +337,9 @@ def test_checkout_add_many_gift_card_code(assert not data["errors"]assert data["checkout"]["id"] == checkout_id- assert data["checkout"]["giftCards"][-1]["code"] == gift_card_created_by_staff.code+ gift_card_data = data["checkout"]["giftCards"][-1]+ assert gift_card_data["id"] == gift_card_id+ assert gift_card_data["displayCode"] == gift_card_created_by_staff.display_codedef test_checkout_get_total_with_gift_card(api_client, checkout_with_item, gift_card):@@ -388,6 +393,7 @@ def test_checkout_get_total_with_more_money_on_gift_card(def test_checkout_add_same_gift_card_code(api_client, checkout_with_gift_card):gift_card = checkout_with_gift_card.gift_cards.first()+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)gift_card_count = checkout_with_gift_card.gift_cards.count()checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_gift_card.pk)variables = {"checkoutId": checkout_id, "promoCode": gift_card.code}@@ -395,7 +401,8 @@ def test_checkout_add_same_gift_card_code(api_client, checkout_with_gift_card):assert not data["errors"]assert data["checkout"]["id"] == checkout_id- assert data["checkout"]["giftCards"][0]["code"] == gift_card.code+ assert data["checkout"]["giftCards"][0]["id"] == gift_card_id+ assert data["checkout"]["giftCards"][0]["displayCode"] == gift_card.display_codeassert len(data["checkout"]["giftCards"]) == gift_card_count@@ -456,7 +463,8 @@ MUTATION_CHECKOUT_REMOVE_PROMO_CODE = """id,voucherCodegiftCards {- code+ id+ displayCode}}}diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex 9414465a79..ffde75c0c0 100644--- a/tests/api/test_gift_card.py+++ b/tests/api/test_gift_card.py@@ -12,7 +12,8 @@ def test_query_gift_card_with_premissions(query = """query giftCard($id: ID!) {giftCard(id: $id){- code+ id+ displayCodeuser {}@@ -25,7 +26,8 @@ def test_query_gift_card_with_premissions(response = staff_api_client.post_graphql(query, variables)content = get_graphql_content(response)data = content["data"]["giftCard"]- assert data["code"] == gift_card.code+ assert data["id"] == gift_card_id+ assert data["displayCode"] == gift_card.display_codeassert data["user"]["email"] == gift_card.user.email@@ -35,7 +37,7 @@ def test_query_gift_card_without_premissions(query = """query giftCard($id: ID!) {giftCard(id: $id){- code+ id}}"""@@ -53,19 +55,26 @@ def test_query_gift_cards(giftCards(first: 10) {edges {node {- code+ id+ displayCode}}}}"""+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)+ gift_card_created_by_staff_id = graphene.Node.to_global_id(+ "GiftCard", gift_card_created_by_staff.pk+ )response = staff_api_client.post_graphql(query, permissions=[permission_manage_gift_card])content = get_graphql_content(response)data = content["data"]["giftCards"]["edges"]- assert data[0]["node"]["code"] == gift_card.code- assert data[1]["node"]["code"] == gift_card_created_by_staff.code+ assert data[0]["node"]["id"] == gift_card_id+ assert data[0]["node"]["displayCode"] == gift_card.display_code+ assert data[1]["node"]["id"] == gift_card_created_by_staff_id+ assert data[1]["node"]["displayCode"] == gift_card_created_by_staff.display_codedef test_query_own_gift_cards(user_api_client, gift_card, gift_card_created_by_staff):@@ -75,7 +84,8 @@ def test_query_own_gift_cards(user_api_client, gift_card, gift_card_created_by_sgiftCards(first: 10) {edges {node {- code+ id+ displayCode}}totalCount@@ -83,10 +93,12 @@ def test_query_own_gift_cards(user_api_client, gift_card, gift_card_created_by_s}}"""+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)response = user_api_client.post_graphql(query)content = get_graphql_content(response)data = content["data"]["me"]["giftCards"]- assert data["edges"][0]["node"]["code"] == gift_card.code+ assert data["edges"][0]["node"]["id"] == gift_card_id+ assert data["edges"][0]["node"]["displayCode"] == gift_card.display_codeassert data["totalCount"] == 1@@ -103,7 +115,7 @@ mutation giftCardCreate(message}giftCard {- code+ displayCodeuser {}@@ -141,7 +153,7 @@ def test_create_gift_card(staff_api_client, customer_user, permission_manage_gif)content = get_graphql_content(response)data = content["data"]["giftCardCreate"]["giftCard"]- assert data["code"] == code+ assert data["displayCode"]assert data["user"]["email"] == customer_user.emailassert data["startDate"] == start_date.isoformat()assert data["endDate"] == end_date.isoformat()@@ -169,7 +181,7 @@ def test_create_gift_card_with_empty_code()content = get_graphql_content(response)data = content["data"]["giftCardCreate"]["giftCard"]- assert data["code"] != ""+ assert len(data["displayCode"]) > 4def test_create_gift_card_without_code(staff_api_client, permission_manage_gift_card):@@ -187,7 +199,7 @@ def test_create_gift_card_without_code(staff_api_client, permission_manage_gift_)content = get_graphql_content(response)data = content["data"]["giftCardCreate"]["giftCard"]- assert data["code"] != ""+ assert len(data["displayCode"]) > 4def test_create_gift_card_with_existing_voucher_code(@@ -239,7 +251,8 @@ def test_create_gift_card_without_user(staff_api_client, permission_manage_gift_)content = get_graphql_content(response)data = content["data"]["giftCardCreate"]["giftCard"]- assert data["code"] == code+ assert data["initialBalance"]["amount"] == initial_balance+ assert data["currentBalance"]["amount"] == initial_balanceassert not data["user"]@@ -296,7 +309,8 @@ mutation giftCardUpdate(message}giftCard {- code+ id+ displayCodecurrentBalance {amount}@@ -311,6 +325,7 @@ mutation giftCardUpdate(def test_update_gift_card(staff_api_client, gift_card, permission_manage_gift_card):balance = 150+ gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)assert gift_card.current_balance != balanceassert gift_card.user != staff_api_client.uservariables = {@@ -323,7 +338,8 @@ def test_update_gift_card(staff_api_client, gift_card, permission_manage_gift_ca)content = get_graphql_content(response)data = content["data"]["giftCardUpdate"]["giftCard"]- assert data["code"] == gift_card.code+ assert data["id"] == gift_card_id+ assert data["displayCode"] == gift_card.display_codeassert data["currentBalance"]["amount"] == balanceassert data["user"]["email"] == staff_api_client.user.emaildiff --git a/tests/conftest.py b/tests/conftest.pyindex 6bb813815b..d6439e5df3 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -636,7 +636,7 @@ def gift_card(customer_user, staff_user):@pytest.fixturedef gift_card_used(staff_user):return GiftCard.objects.create(- code="used_gift_card",+ code="gift_card_used",initial_balance=150,current_balance=100,)