Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Split channel tests (#11184)
Iga Karbowiakadbdcba16e41
diff --git a/saleor/graphql/channel/tests/mutations/__init__.py b/saleor/graphql/channel/tests/mutations/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/graphql/channel/tests/test_base_channel_listing.py b/saleor/graphql/channel/tests/mutations/test_base_channel_listing.pysimilarity index 97%rename from saleor/graphql/channel/tests/test_base_channel_listing.pyrename to saleor/graphql/channel/tests/mutations/test_base_channel_listing.pyindex 1c7e58a147..ad76096ed2 100644--- a/saleor/graphql/channel/tests/test_base_channel_listing.py+++ b/saleor/graphql/channel/tests/mutations/test_base_channel_listing.py@@ -4,8 +4,8 @@ import grapheneimport pytestfrom django.core.exceptions import ValidationError-from ....shipping.error_codes import ShippingErrorCode-from ..mutations import BaseChannelListingMutation+from .....shipping.error_codes import ShippingErrorCode+from ...mutations import BaseChannelListingMutationdef test_validate_duplicated_channel_ids(channel_PLN, channel_USD):diff --git a/saleor/graphql/channel/tests/mutations/test_channel_activate.py b/saleor/graphql/channel/tests/mutations/test_channel_activate.pynew file mode 100644index 0000000000..0951cf010c--- /dev/null+++ b/saleor/graphql/channel/tests/mutations/test_channel_activate.py@@ -0,0 +1,125 @@+import json+from unittest import mock++import graphene+from django.utils.functional import SimpleLazyObject+from freezegun import freeze_time++from .....channel.error_codes import ChannelErrorCode+from .....core.utils.json_serializer import CustomJsonEncoder+from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.payloads import generate_meta, generate_requestor+from ....tests.utils import get_graphql_content++CHANNEL_ACTIVATE_MUTATION = """+ mutation ActivateChannel($id: ID!) {+ channelActivate(id: $id){+ channel {+ id+ name+ isActive+ }+ errors{+ field+ code+ message+ }+ }+ }+"""+++def test_channel_activate_mutation(+ permission_manage_channels, staff_api_client, channel_USD+):+ # given+ channel_USD.is_active = False+ channel_USD.save()+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {"id": channel_id}+ # when+ response = staff_api_client.post_graphql(+ CHANNEL_ACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ data = content["data"]["channelActivate"]+ assert not data["errors"]+ assert data["channel"]["name"] == channel_USD.name+ assert data["channel"]["isActive"] is True+++@freeze_time("2022-05-12 12:00:00")[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")+def test_channel_activate_mutation_trigger_webhook(+ mocked_webhook_trigger,+ mocked_get_webhooks_for_event,+ any_webhook,+ permission_manage_channels,+ staff_api_client,+ channel_USD,+ settings,+):+ # given+ mocked_get_webhooks_for_event.return_value = [any_webhook]+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]++ channel_USD.is_active = False+ channel_USD.save()+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {"id": channel_id}+ # when+ response = staff_api_client.post_graphql(+ CHANNEL_ACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ assert not content["data"]["channelActivate"]["errors"]+ mocked_webhook_trigger.assert_called_once_with(+ json.dumps(+ {+ "id": variables["id"],+ "is_active": True,+ "meta": generate_meta(+ requestor_data=generate_requestor(+ SimpleLazyObject(lambda: staff_api_client.user)+ )+ ),+ },+ cls=CustomJsonEncoder,+ ),+ WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,+ [any_webhook],+ channel_USD,+ SimpleLazyObject(lambda: staff_api_client.user),+ )+++def test_channel_activate_mutation_on_activated_channel(+ permission_manage_channels, staff_api_client, channel_USD+):+ # given+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {"id": channel_id}+ # when+ response = staff_api_client.post_graphql(+ CHANNEL_ACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ data = content["data"]["channelActivate"]+ assert data["errors"][0]["field"] == "id"+ assert data["errors"][0]["code"] == ChannelErrorCode.INVALID.namediff --git a/saleor/graphql/channel/tests/test_channel_create_mutations.py b/saleor/graphql/channel/tests/mutations/test_channel_create.pysimilarity index 96%rename from saleor/graphql/channel/tests/test_channel_create_mutations.pyrename to saleor/graphql/channel/tests/mutations/test_channel_create.pyindex 3a72fe37a1..d09d6ec979 100644--- a/saleor/graphql/channel/tests/test_channel_create_mutations.py+++ b/saleor/graphql/channel/tests/mutations/test_channel_create.py@@ -6,13 +6,13 @@ from django.utils.functional import SimpleLazyObjectfrom django.utils.text import slugifyfrom freezegun import freeze_time-from ....channel.error_codes import ChannelErrorCode-from ....channel.models import Channel-from ....core.utils.json_serializer import CustomJsonEncoder-from ....webhook.event_types import WebhookEventAsyncType-from ....webhook.payloads import generate_meta, generate_requestor-from ...tests.utils import assert_no_permission, get_graphql_content-from ..enums import AllocationStrategyEnum+from .....channel.error_codes import ChannelErrorCode+from .....channel.models import Channel+from .....core.utils.json_serializer import CustomJsonEncoder+from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.payloads import generate_meta, generate_requestor+from ....tests.utils import assert_no_permission, get_graphql_content+from ...enums import AllocationStrategyEnumCHANNEL_CREATE_MUTATION = """mutation CreateChannel($input: ChannelCreateInput!){diff --git a/saleor/graphql/channel/tests/mutations/test_channel_deactivate.py b/saleor/graphql/channel/tests/mutations/test_channel_deactivate.pynew file mode 100644index 0000000000..3dfec4ab29--- /dev/null+++ b/saleor/graphql/channel/tests/mutations/test_channel_deactivate.py@@ -0,0 +1,123 @@+import json+from unittest import mock++import graphene+from django.utils.functional import SimpleLazyObject+from freezegun import freeze_time++from .....channel.error_codes import ChannelErrorCode+from .....core.utils.json_serializer import CustomJsonEncoder+from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.payloads import generate_meta, generate_requestor+from ....tests.utils import get_graphql_content++CHANNEL_DEACTIVATE_MUTATION = """+ mutation DeactivateChannel($id: ID!) {+ channelDeactivate(id: $id){+ channel {+ id+ name+ isActive+ }+ errors{+ field+ code+ message+ }+ }+ }+"""+++def test_channel_deactivate_mutation(+ permission_manage_channels, staff_api_client, channel_USD+):+ # given+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {"id": channel_id}+ # when+ response = staff_api_client.post_graphql(+ CHANNEL_DEACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ data = content["data"]["channelDeactivate"]+ assert not data["errors"]+ assert data["channel"]["name"] == channel_USD.name+ assert data["channel"]["isActive"] is False+++@freeze_time("2022-05-12 12:00:00")[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")+def test_channel_deactivate_mutation_trigger_webhook(+ mocked_webhook_trigger,+ mocked_get_webhooks_for_event,+ any_webhook,+ permission_manage_channels,+ staff_api_client,+ channel_USD,+ settings,+):+ # given+ mocked_get_webhooks_for_event.return_value = [any_webhook]+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]++ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {"id": channel_id}+ # when+ response = staff_api_client.post_graphql(+ CHANNEL_DEACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ assert not content["data"]["channelDeactivate"]["errors"]+ mocked_webhook_trigger.assert_called_once_with(+ json.dumps(+ {+ "id": variables["id"],+ "is_active": False,+ "meta": generate_meta(+ requestor_data=generate_requestor(+ SimpleLazyObject(lambda: staff_api_client.user)+ )+ ),+ },+ cls=CustomJsonEncoder,+ ),+ WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,+ [any_webhook],+ channel_USD,+ SimpleLazyObject(lambda: staff_api_client.user),+ )+++def test_channel_deactivate_mutation_on_deactivated_channel(+ permission_manage_channels, staff_api_client, channel_USD+):+ # given+ channel_USD.is_active = False+ channel_USD.save()+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)+ variables = {"id": channel_id}++ # when+ response = staff_api_client.post_graphql(+ CHANNEL_DEACTIVATE_MUTATION,+ variables=variables,+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ data = content["data"]["channelDeactivate"]+ assert data["errors"][0]["field"] == "id"+ assert data["errors"][0]["code"] == ChannelErrorCode.INVALID.namediff --git a/saleor/graphql/channel/tests/test_channel_delete_mutations.py b/saleor/graphql/channel/tests/mutations/test_channel_delete.pysimilarity index 96%rename from saleor/graphql/channel/tests/test_channel_delete_mutations.pyrename to saleor/graphql/channel/tests/mutations/test_channel_delete.pyindex c77bf7056c..59c8ab9a7a 100644--- a/saleor/graphql/channel/tests/test_channel_delete_mutations.py+++ b/saleor/graphql/channel/tests/mutations/test_channel_delete.py@@ -5,14 +5,14 @@ import graphenefrom django.utils.functional import SimpleLazyObjectfrom freezegun import freeze_time-from ....channel.error_codes import ChannelErrorCode-from ....channel.models import Channel-from ....checkout.models import Checkout-from ....core.utils.json_serializer import CustomJsonEncoder-from ....order.models import Order-from ....webhook.event_types import WebhookEventAsyncType-from ....webhook.payloads import generate_meta, generate_requestor-from ...tests.utils import assert_no_permission, get_graphql_content+from .....channel.error_codes import ChannelErrorCode+from .....channel.models import Channel+from .....checkout.models import Checkout+from .....core.utils.json_serializer import CustomJsonEncoder+from .....order.models import Order+from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.payloads import generate_meta, generate_requestor+from ....tests.utils import assert_no_permission, get_graphql_contentCHANNEL_DELETE_MUTATION = """mutation deleteChannel($id: ID!, $input: ChannelDeleteInput){diff --git a/saleor/graphql/channel/tests/test_channel_reorder_warehouses.py b/saleor/graphql/channel/tests/mutations/test_channel_reorder_warehouses.pysimilarity index 97%rename from saleor/graphql/channel/tests/test_channel_reorder_warehouses.pyrename to saleor/graphql/channel/tests/mutations/test_channel_reorder_warehouses.pyindex 754f7e1035..6651b3fa6e 100644--- a/saleor/graphql/channel/tests/test_channel_reorder_warehouses.py+++ b/saleor/graphql/channel/tests/mutations/test_channel_reorder_warehouses.py@@ -3,9 +3,9 @@ import uuidimport grapheneimport pytest-from ....channel.error_codes import ChannelErrorCode-from ....warehouse.models import ChannelWarehouse-from ...tests.utils import get_graphql_content+from .....channel.error_codes import ChannelErrorCode+from .....warehouse.models import ChannelWarehouse+from ....tests.utils import get_graphql_contentCHANNEL_REORDER_WAREHOUSES = """mutation ChannelReorderWarehouses($channelId: ID!, $moves: [ReorderInput!]!) {diff --git a/saleor/graphql/channel/tests/test_channel_update_mutations.py b/saleor/graphql/channel/tests/mutations/test_channel_update.pysimilarity index 98%rename from saleor/graphql/channel/tests/test_channel_update_mutations.pyrename to saleor/graphql/channel/tests/mutations/test_channel_update.pyindex 9ab58259ec..cde546614a 100644--- a/saleor/graphql/channel/tests/test_channel_update_mutations.py+++ b/saleor/graphql/channel/tests/mutations/test_channel_update.py@@ -7,12 +7,12 @@ from django.utils.functional import SimpleLazyObjectfrom django.utils.text import slugifyfrom freezegun import freeze_time-from ....channel.error_codes import ChannelErrorCode-from ....core.utils.json_serializer import CustomJsonEncoder-from ....webhook.event_types import WebhookEventAsyncType-from ....webhook.payloads import generate_meta, generate_requestor-from ...tests.utils import assert_no_permission, get_graphql_content-from ..enums import AllocationStrategyEnum+from .....channel.error_codes import ChannelErrorCode+from .....core.utils.json_serializer import CustomJsonEncoder+from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.payloads import generate_meta, generate_requestor+from ....tests.utils import assert_no_permission, get_graphql_content+from ...enums import AllocationStrategyEnumCHANNEL_UPDATE_MUTATION = """mutation UpdateChannel($id: ID!,$input: ChannelUpdateInput!){diff --git a/saleor/graphql/channel/tests/queries/__init__.py b/saleor/graphql/channel/tests/queries/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/graphql/channel/tests/test_channel_queries.py b/saleor/graphql/channel/tests/queries/test_channel.pysimilarity index 69%rename from saleor/graphql/channel/tests/test_channel_queries.pyrename to saleor/graphql/channel/tests/queries/test_channel.pyindex 3ff6342ffd..fc89dc7c61 100644--- a/saleor/graphql/channel/tests/test_channel_queries.py+++ b/saleor/graphql/channel/tests/queries/test_channel.py@@ -1,162 +1,13 @@import graphenefrom prices import Money-from ....shipping.models import ShippingMethodChannelListing, ShippingZone-from ...tests.utils import (+from .....shipping.models import ShippingMethodChannelListing, ShippingZone+from ....tests.utils import (assert_no_permission,get_graphql_content,get_graphql_content_from_response,)-from ..enums import AllocationStrategyEnum--QUERY_CHANNELS = """-query {- channels {- name- slug- currencyCode- defaultCountry {- code- country- }- }-}-"""---def test_query_channels_as_staff_user(staff_api_client, channel_USD, channel_PLN):- # given-- # when- response = staff_api_client.post_graphql(QUERY_CHANNELS, {})- content = get_graphql_content(response)-- # then- channels = content["data"]["channels"]- assert len(channels) == 2- assert {- "slug": channel_PLN.slug,- "name": channel_PLN.name,- "currencyCode": channel_PLN.currency_code,- "defaultCountry": {- "code": channel_PLN.default_country.code,- "country": channel_PLN.default_country.name,- },- } in channels- assert {- "slug": channel_USD.slug,- "name": channel_USD.name,- "currencyCode": channel_USD.currency_code,- "defaultCountry": {- "code": channel_USD.default_country.code,- "country": channel_USD.default_country.name,- },- } in channels---def test_query_channels_as_app(app_api_client, channel_USD, channel_PLN):- # given-- # when- response = app_api_client.post_graphql(QUERY_CHANNELS, {})- content = get_graphql_content(response)-- # then- channels = content["data"]["channels"]- assert len(channels) == 2- assert {- "slug": channel_PLN.slug,- "name": channel_PLN.name,- "currencyCode": channel_PLN.currency_code,- "defaultCountry": {- "code": channel_PLN.default_country.code,- "country": channel_PLN.default_country.name,- },- } in channels- assert {- "slug": channel_USD.slug,- "name": channel_USD.name,- "currencyCode": channel_USD.currency_code,- "defaultCountry": {- "code": channel_USD.default_country.code,- "country": channel_USD.default_country.name,- },- } in channels---def test_query_channels_as_customer(user_api_client, channel_USD, channel_PLN):- # given-- # when- response = user_api_client.post_graphql(QUERY_CHANNELS, {})-- # then- assert_no_permission(response)---def test_query_channels_as_anonymous(api_client, channel_USD, channel_PLN):- # given-- # when- response = api_client.post_graphql(QUERY_CHANNELS, {})-- # then- assert_no_permission(response)---QUERY_CHANNELS_WITH_HAS_ORDERS = """-query {- channels {- name- slug- currencyCode- hasOrders- }-}-"""---def test_query_channels_with_has_orders_order(- staff_api_client, permission_manage_channels, channel_USD, channel_PLN, order_list-):- # given-- # when- response = staff_api_client.post_graphql(- QUERY_CHANNELS_WITH_HAS_ORDERS,- {},- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- channels = content["data"]["channels"]- assert len(channels) == 2- assert {- "slug": channel_PLN.slug,- "name": channel_PLN.name,- "currencyCode": channel_PLN.currency_code,- "hasOrders": False,- } in channels- assert {- "slug": channel_USD.slug,- "name": channel_USD.name,- "currencyCode": channel_USD.currency_code,- "hasOrders": True,- } in channels---def test_query_channels_with_has_orders_without_permission(- staff_api_client, channel_USD, channel_PLN-):- # given-- # when- response = staff_api_client.post_graphql(QUERY_CHANNELS_WITH_HAS_ORDERS, {})-- # then- assert_no_permission(response)-+from ...enums import AllocationStrategyEnumQUERY_CHANNEL = """query getChannel($id: ID){diff --git a/saleor/graphql/channel/tests/queries/test_channels.py b/saleor/graphql/channel/tests/queries/test_channels.pynew file mode 100644index 0000000000..b3628f2990--- /dev/null+++ b/saleor/graphql/channel/tests/queries/test_channels.py@@ -0,0 +1,149 @@+from ....tests.utils import assert_no_permission, get_graphql_content++QUERY_CHANNELS = """+ query {+ channels {+ name+ slug+ currencyCode+ defaultCountry {+ code+ country+ }+ }+ }+"""+++def test_query_channels_as_staff_user(staff_api_client, channel_USD, channel_PLN):+ # given++ # when+ response = staff_api_client.post_graphql(QUERY_CHANNELS, {})+ content = get_graphql_content(response)++ # then+ channels = content["data"]["channels"]+ assert len(channels) == 2+ assert {+ "slug": channel_PLN.slug,+ "name": channel_PLN.name,+ "currencyCode": channel_PLN.currency_code,+ "defaultCountry": {+ "code": channel_PLN.default_country.code,+ "country": channel_PLN.default_country.name,+ },+ } in channels+ assert {+ "slug": channel_USD.slug,+ "name": channel_USD.name,+ "currencyCode": channel_USD.currency_code,+ "defaultCountry": {+ "code": channel_USD.default_country.code,+ "country": channel_USD.default_country.name,+ },+ } in channels+++def test_query_channels_as_app(app_api_client, channel_USD, channel_PLN):+ # given++ # when+ response = app_api_client.post_graphql(QUERY_CHANNELS, {})+ content = get_graphql_content(response)++ # then+ channels = content["data"]["channels"]+ assert len(channels) == 2+ assert {+ "slug": channel_PLN.slug,+ "name": channel_PLN.name,+ "currencyCode": channel_PLN.currency_code,+ "defaultCountry": {+ "code": channel_PLN.default_country.code,+ "country": channel_PLN.default_country.name,+ },+ } in channels+ assert {+ "slug": channel_USD.slug,+ "name": channel_USD.name,+ "currencyCode": channel_USD.currency_code,+ "defaultCountry": {+ "code": channel_USD.default_country.code,+ "country": channel_USD.default_country.name,+ },+ } in channels+++def test_query_channels_as_customer(user_api_client, channel_USD, channel_PLN):+ # given++ # when+ response = user_api_client.post_graphql(QUERY_CHANNELS, {})++ # then+ assert_no_permission(response)+++def test_query_channels_as_anonymous(api_client, channel_USD, channel_PLN):+ # given++ # when+ response = api_client.post_graphql(QUERY_CHANNELS, {})++ # then+ assert_no_permission(response)+++QUERY_CHANNELS_WITH_HAS_ORDERS = """+query {+ channels {+ name+ slug+ currencyCode+ hasOrders+ }+}+"""+++def test_query_channels_with_has_orders_order(+ staff_api_client, permission_manage_channels, channel_USD, channel_PLN, order_list+):+ # given++ # when+ response = staff_api_client.post_graphql(+ QUERY_CHANNELS_WITH_HAS_ORDERS,+ {},+ permissions=(permission_manage_channels,),+ )+ content = get_graphql_content(response)++ # then+ channels = content["data"]["channels"]+ assert len(channels) == 2+ assert {+ "slug": channel_PLN.slug,+ "name": channel_PLN.name,+ "currencyCode": channel_PLN.currency_code,+ "hasOrders": False,+ } in channels+ assert {+ "slug": channel_USD.slug,+ "name": channel_USD.name,+ "currencyCode": channel_USD.currency_code,+ "hasOrders": True,+ } in channels+++def test_query_channels_with_has_orders_without_permission(+ staff_api_client, channel_USD, channel_PLN+):+ # given++ # when+ response = staff_api_client.post_graphql(QUERY_CHANNELS_WITH_HAS_ORDERS, {})++ # then+ assert_no_permission(response)diff --git a/saleor/graphql/channel/tests/test_channel_availability.py b/saleor/graphql/channel/tests/test_channel_availability.pydeleted file mode 100644index 12c2d81cd0..0000000000--- a/saleor/graphql/channel/tests/test_channel_availability.py+++ /dev/null@@ -1,237 +0,0 @@-import json-from unittest import mock--import graphene-from django.utils.functional import SimpleLazyObject-from freezegun import freeze_time--from ....channel.error_codes import ChannelErrorCode-from ....core.utils.json_serializer import CustomJsonEncoder-from ....webhook.event_types import WebhookEventAsyncType-from ....webhook.payloads import generate_meta, generate_requestor-from ...tests.utils import get_graphql_content--CHANNEL_ACTIVATE_MUTATION = """- mutation ActivateChannel($id: ID!) {- channelActivate(id: $id){- channel {- id- name- isActive- }- errors{- field- code- message- }- }- }-"""---def test_channel_activate_mutation(- permission_manage_channels, staff_api_client, channel_USD-):- # given- channel_USD.is_active = False- channel_USD.save()- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)-- variables = {"id": channel_id}- # when- response = staff_api_client.post_graphql(- CHANNEL_ACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- data = content["data"]["channelActivate"]- assert not data["errors"]- assert data["channel"]["name"] == channel_USD.name- assert data["channel"]["isActive"] is True---@freeze_time("2022-05-12 12:00:00")[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")-def test_channel_activate_mutation_trigger_webhook(- mocked_webhook_trigger,- mocked_get_webhooks_for_event,- any_webhook,- permission_manage_channels,- staff_api_client,- channel_USD,- settings,-):- # given- mocked_get_webhooks_for_event.return_value = [any_webhook]- settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]-- channel_USD.is_active = False- channel_USD.save()- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)-- variables = {"id": channel_id}- # when- response = staff_api_client.post_graphql(- CHANNEL_ACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- assert not content["data"]["channelActivate"]["errors"]- mocked_webhook_trigger.assert_called_once_with(- json.dumps(- {- "id": variables["id"],- "is_active": True,- "meta": generate_meta(- requestor_data=generate_requestor(- SimpleLazyObject(lambda: staff_api_client.user)- )- ),- },- cls=CustomJsonEncoder,- ),- WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,- [any_webhook],- channel_USD,- SimpleLazyObject(lambda: staff_api_client.user),- )---def test_channel_activate_mutation_on_activated_channel(- permission_manage_channels, staff_api_client, channel_USD-):- # given- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)-- variables = {"id": channel_id}- # when- response = staff_api_client.post_graphql(- CHANNEL_ACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- data = content["data"]["channelActivate"]- assert data["errors"][0]["field"] == "id"- assert data["errors"][0]["code"] == ChannelErrorCode.INVALID.name---CHANNEL_DEACTIVATE_MUTATION = """- mutation DeactivateChannel($id: ID!) {- channelDeactivate(id: $id){- channel {- id- name- isActive- }- errors{- field- code- message- }- }- }-"""---def test_channel_deactivate_mutation(- permission_manage_channels, staff_api_client, channel_USD-):- # given- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)-- variables = {"id": channel_id}- # when- response = staff_api_client.post_graphql(- CHANNEL_DEACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- data = content["data"]["channelDeactivate"]- assert not data["errors"]- assert data["channel"]["name"] == channel_USD.name- assert data["channel"]["isActive"] is False---@freeze_time("2022-05-12 12:00:00")[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")-def test_channel_deactivate_mutation_trigger_webhook(- mocked_webhook_trigger,- mocked_get_webhooks_for_event,- any_webhook,- permission_manage_channels,- staff_api_client,- channel_USD,- settings,-):- # given- mocked_get_webhooks_for_event.return_value = [any_webhook]- settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]-- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)-- variables = {"id": channel_id}- # when- response = staff_api_client.post_graphql(- CHANNEL_DEACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- assert not content["data"]["channelDeactivate"]["errors"]- mocked_webhook_trigger.assert_called_once_with(- json.dumps(- {- "id": variables["id"],- "is_active": False,- "meta": generate_meta(- requestor_data=generate_requestor(- SimpleLazyObject(lambda: staff_api_client.user)- )- ),- },- cls=CustomJsonEncoder,- ),- WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,- [any_webhook],- channel_USD,- SimpleLazyObject(lambda: staff_api_client.user),- )---def test_channel_deactivate_mutation_on_deactivated_channel(- permission_manage_channels, staff_api_client, channel_USD-):- # given- channel_USD.is_active = False- channel_USD.save()- channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)- variables = {"id": channel_id}-- # when- response = staff_api_client.post_graphql(- CHANNEL_DEACTIVATE_MUTATION,- variables=variables,- permissions=(permission_manage_channels,),- )- content = get_graphql_content(response)-- # then- data = content["data"]["channelDeactivate"]- assert data["errors"][0]["field"] == "id"- assert data["errors"][0]["code"] == ChannelErrorCode.INVALID.name