Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test fetching user in graphql federation with both keys
Jakub Draganek451ebc05746e
diff --git a/tests/api/test_federation.py b/tests/api/test_federation.pynew file mode 100644index 0000000000..231fddd3b9--- /dev/null+++ b/tests/api/test_federation.py@@ -0,0 +1,50 @@+import graphene+import pytest++from .utils import get_graphql_content+++def user_representation_by_id(staff_user):+ user_id = graphene.Node.to_global_id("User", staff_user.id)+ return {"_representations": [{"id": user_id, "__typename": "User"}]}+++def user_representation_by_email(staff_user):+ return {"_representations": [{"email": staff_user.email, "__typename": "User"}]}+++FEDERATED_QUERY = """+query($_representations: [_Any!]!) {+ _entities(representations: $_representations) {+ ... on User {+ id+ isStaff+ }+ }+}+"""+++def test_get_user_data_through_federated_query_by_id(+ staff_api_client, user_representation_by_id, staff_user+):+ response = staff_api_client.post_graphql(FEDERATED_QUERY, user_representation_by_id)+ content = get_graphql_content(response)["data"]["_entities"]+ assert len(content) == 1+ assert content[0]["email"] == staff_user.email+ assert content[0]["isStaff"] == staff_user.is_staff+++def test_get_user_data_through_federated_query_by_email(+ staff_api_client, user_representation_by_email, staff_user+):+ response = staff_api_client.post_graphql(+ FEDERATED_QUERY, user_representation_by_email+ )+ content = get_graphql_content(response)["data"]["_entities"]+ assert len(content) == 1+ assert content[0]["id"] == graphene.Node.to_global_id("User", staff_user.id)+ assert content[0]["isStaff"] == staff_user.is_staff