Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
test_should_create_and_update_staff (#14683)
Renata056a7dda5100
diff --git a/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.py b/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.pynew file mode 100644index 0000000000..91d6907109--- /dev/null+++ b/saleor/tests/e2e/users/test_create_and_update_staff_with_metadata.py@@ -0,0 +1,54 @@+import pytest++from ..utils import assign_permissions+from .utils import create_staff, update_staff+++def test_create_and_update_staff_with_metadata_core_1515(+ e2e_staff_api_client,+ permission_manage_staff,+):+ # Before+ permissions = [+ permission_manage_staff,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ # Step 1 - Create staff member with metadata+ metadata = [{"key": "code", "value": "abc"}]+ private_metadata = [{"key": "priv_code", "value": "priv_abc"}]+ input_data = {+ "firstName": "Leo",+ "lastName": "Test",+ "email": "[email protected]",+ "isActive": True,+ "metadata": metadata,+ "privateMetadata": private_metadata,+ }+ data = create_staff(+ e2e_staff_api_client,+ input_data,+ )++ assert data is not None+ staff_id = data["id"]+ assert staff_id is not None+ assert data["metadata"] == metadata+ assert data["privateMetadata"] == private_metadata++ # Step 2 - Update staff metadata+ updated_metadata = [{"key": "code", "value": "update_pub"}]+ updated_private_metadata = [{"key": "priv_code", "value": "update_priv"}]+ update_input = {+ "metadata": updated_metadata,+ "privateMetadata": updated_private_metadata,+ }+ data = update_staff(+ e2e_staff_api_client,+ staff_id,+ update_input,+ )+ assert data["id"] == staff_id+ assert data["metadata"] == updated_metadata+ assert data["privateMetadata"] == updated_private_metadatadiff --git a/saleor/tests/e2e/users/utils/__init__.py b/saleor/tests/e2e/users/utils/__init__.pyindex a7593d0731..4cd4ff633c 100644--- a/saleor/tests/e2e/users/utils/__init__.py+++ b/saleor/tests/e2e/users/utils/__init__.py@@ -1,9 +1,13 @@from .create_customer import create_customerfrom .customer_bulk_update import customer_bulk_updatefrom .customer_update import customer_update+from .staff_create import create_staff+from .staff_update import update_staff__all__ = ["create_customer","customer_bulk_update","customer_update",+ "create_staff",+ "update_staff",]diff --git a/saleor/tests/e2e/users/utils/staff_create.py b/saleor/tests/e2e/users/utils/staff_create.pynew file mode 100644index 0000000000..50fec832ed--- /dev/null+++ b/saleor/tests/e2e/users/utils/staff_create.py@@ -0,0 +1,42 @@+from ...utils import get_graphql_content++STAFF_CREATE_MUTATION = """+mutation CreateStaff($input: StaffCreateInput!){+ staffCreate(input:$input) {+ user {+ id+ metadata {+ key+ value+ }+ privateMetadata {+ key+ value+ }+ }+ errors {+ field+ message+ }+ }+}+"""+++def create_staff(+ staff_api_client,+ input_data,+):+ variables = {"input": input_data}++ response = staff_api_client.post_graphql(+ STAFF_CREATE_MUTATION,+ variables,+ )+ content = get_graphql_content(response)++ assert content["data"]["staffCreate"]["errors"] == []++ data = content["data"]["staffCreate"]["user"]++ return datadiff --git a/saleor/tests/e2e/users/utils/staff_update.py b/saleor/tests/e2e/users/utils/staff_update.pynew file mode 100644index 0000000000..ec7448c69d--- /dev/null+++ b/saleor/tests/e2e/users/utils/staff_update.py@@ -0,0 +1,45 @@+from ...utils import get_graphql_content++STAFF_UPDATE_MUTATION = """+mutation StaffUpdate($id: ID!, $input: StaffUpdateInput!){+ staffUpdate(id: $id,+ input: $input) {+ user {+ id+ metadata {+ key+ value+ }+ privateMetadata {+ key+ value+ }+ }+ errors {+ field+ message+ }+ }+}+"""+++def update_staff(+ staff_api_client,+ staff_id,+ input_data,+):+ variables = {+ "id": staff_id,+ "input": input_data,+ }++ response = staff_api_client.post_graphql(+ STAFF_UPDATE_MUTATION,+ variables,+ )+ content = get_graphql_content(response)+ assert content["data"]["staffUpdate"]["errors"] == []+ data = content["data"]["staffUpdate"]["user"]++ return data