4040 'from' : {'id' : FRED_USER ['id' ]}
4141}
4242
43+ UPDATED_FRED_EMAIL = {
44+ 'id' : FRED_EMAIL ['id' ],
45+ 'subject' : 'updated subject' ,
46+ 'date' : '2026-07-31' ,
47+ 'text' : 'updated body text!' ,
48+ 'from' : {'id' : FRED_USER ['id' ]}
49+ }
50+
4351INITIAL_STATE = {
4452 'users' : [FRED_USER , JEFF_USER ],
4553 'emails' : [FRED_EMAIL ]
97105 }})
98106 }}"""
99107
108+ UPSERT_UPDATED_FRED_EMAIL = f"""
109+ mutation email {{
110+ email_upsert(data: {{
111+ id:"{ UPDATED_FRED_EMAIL ['id' ]} ",
112+ subject: "{ UPDATED_FRED_EMAIL ['subject' ]} ",
113+ date: "{ UPDATED_FRED_EMAIL ['date' ]} ",
114+ text: "{ UPDATED_FRED_EMAIL ['text' ]} ",
115+ fromId: "{ UPDATED_FRED_EMAIL ['from' ]['id' ]} "
116+ }})
117+ }}"""
118+
100119DELETE_ALL = """
101120 mutation delete {
102121 email_deleteMany(all: true)
125144class TestExecuteGraphql :
126145 """Integration tests for execute_graphql method."""
127146
128- def test_execute_graphql_mutation (self ):
129- """Tests executing mutations via execute_graphql."""
130- dc_client = dataconnect .client (CONNECTOR_CONFIG )
131- fred_resp = dc_client .execute_graphql (UPSERT_FRED_USER )
132- assert fred_resp .data ['user_upsert' ]['id' ] == FRED_USER ['id' ]
133-
134- jeff_resp = dc_client .execute_graphql (UPSERT_JEFF_USER )
135- assert jeff_resp .data ['user_upsert' ]['id' ] == JEFF_USER ['id' ]
136-
137- upsert_email_resp = dc_client .execute_graphql (UPSERT_FRED_EMAIL )
138- email_id = upsert_email_resp .data ['email_upsert' ]['id' ]
139- assert email_id
140-
141- get_email_options = dataconnect .GraphqlOptions (variables = {'id' : email_id })
142- query_email_resp = dc_client .execute_graphql (
143- QUERY_GET_EMAIL , options = get_email_options
144- )
145- assert query_email_resp .data ['email' ] == FRED_EMAIL
146-
147147 def test_execute_graphql_query (self ):
148148 """Tests executing a query via execute_graphql."""
149149 dc_client = dataconnect .client (CONNECTOR_CONFIG )
150150 resp = dc_client .execute_graphql (QUERY_LIST_USERS )
151- assert sorted (resp .data ['users' ], key = lambda x : x ['id' ]) == sorted (
152- INITIAL_STATE ['users' ], key = lambda x : x ['id' ]
151+ assert sorted (resp .data ['users' ], key = lambda user : user ['id' ]) == sorted (
152+ INITIAL_STATE ['users' ], key = lambda user : user ['id' ]
153153 )
154154
155+ def test_execute_graphql_query_with_variables (self ):
156+ """Tests query execution with variables."""
157+ dc_client = dataconnect .client (CONNECTOR_CONFIG )
158+ user_id = INITIAL_STATE ['users' ][0 ]['id' ]
159+ options = dataconnect .GraphqlOptions (variables = {'id' : {'id' : user_id }})
160+ resp = dc_client .execute_graphql (QUERY_GET_USER_BY_ID , options = options )
161+ assert resp .data ['user' ] == INITIAL_STATE ['users' ][0 ]
162+
155163 def test_execute_graphql_operation_name_multiple_queries (self ):
156164 """Tests operation_name with multi-query document."""
157165 dc_client = dataconnect .client (CONNECTOR_CONFIG )
@@ -166,13 +174,25 @@ def test_execute_graphql_query_error_missing_variables(self):
166174 dc_client .execute_graphql (QUERY_GET_USER_BY_ID )
167175 assert excinfo .value .code == 'query-error'
168176
169- def test_execute_graphql_query_with_variables (self ):
170- """Tests query execution with variables ."""
177+ def test_execute_graphql_mutation (self ):
178+ """Tests executing mutations via execute_graphql ."""
171179 dc_client = dataconnect .client (CONNECTOR_CONFIG )
172- user_id = INITIAL_STATE ['users' ][0 ]['id' ]
173- options = dataconnect .GraphqlOptions (variables = {'id' : {'id' : user_id }})
174- resp = dc_client .execute_graphql (QUERY_GET_USER_BY_ID , options = options )
175- assert resp .data ['user' ] == INITIAL_STATE ['users' ][0 ]
180+ fred_resp = dc_client .execute_graphql (UPSERT_FRED_USER )
181+ assert fred_resp .data ['user_upsert' ]['id' ] == FRED_USER ['id' ]
182+
183+ jeff_resp = dc_client .execute_graphql (UPSERT_JEFF_USER )
184+ assert jeff_resp .data ['user_upsert' ]['id' ] == JEFF_USER ['id' ]
185+
186+ upsert_email_resp = dc_client .execute_graphql (UPSERT_UPDATED_FRED_EMAIL )
187+ email_id = upsert_email_resp .data ['email_upsert' ]['id' ]
188+ assert email_id == UPDATED_FRED_EMAIL ['id' ]
189+
190+ get_email_options = dataconnect .GraphqlOptions (variables = {'id' : email_id })
191+ query_email_resp = dc_client .execute_graphql (
192+ QUERY_GET_EMAIL , options = get_email_options
193+ )
194+ assert query_email_resp .data ['email' ] == UPDATED_FRED_EMAIL
195+ dc_client .execute_graphql (UPSERT_FRED_EMAIL )
176196
177197
178198class TestExecuteGraphqlRead :
@@ -182,8 +202,8 @@ def test_execute_graphql_read_query(self):
182202 """Tests read-only query execution."""
183203 dc_client = dataconnect .client (CONNECTOR_CONFIG )
184204 resp = dc_client .execute_graphql_read (QUERY_LIST_USERS )
185- assert sorted (resp .data ['users' ], key = lambda x : x ['id' ]) == sorted (
186- INITIAL_STATE ['users' ], key = lambda x : x ['id' ]
205+ assert sorted (resp .data ['users' ], key = lambda user : user ['id' ]) == sorted (
206+ INITIAL_STATE ['users' ], key = lambda user : user ['id' ]
187207 )
188208
189209 def test_execute_graphql_read_mutation_fails (self ):
@@ -273,8 +293,8 @@ def test_impersonated_authenticated(self):
273293 resp = dc_client .execute_graphql (
274294 QUERY_LIST_USERS , options = OPTS_AUTHORIZED_FRED_CLAIMS
275295 )
276- assert sorted (resp .data ['users' ], key = lambda x : x ['id' ]) == sorted (
277- INITIAL_STATE ['users' ], key = lambda x : x ['id' ]
296+ assert sorted (resp .data ['users' ], key = lambda user : user ['id' ]) == sorted (
297+ INITIAL_STATE ['users' ], key = lambda user : user ['id' ]
278298 )
279299
280300 def test_impersonated_unauthenticated (self ):
@@ -283,8 +303,8 @@ def test_impersonated_unauthenticated(self):
283303 resp = dc_client .execute_graphql (
284304 QUERY_LIST_USERS , options = OPTS_UNAUTHORIZED_CLAIMS
285305 )
286- assert sorted (resp .data ['users' ], key = lambda x : x ['id' ]) == sorted (
287- INITIAL_STATE ['users' ], key = lambda x : x ['id' ]
306+ assert sorted (resp .data ['users' ], key = lambda user : user ['id' ]) == sorted (
307+ INITIAL_STATE ['users' ], key = lambda user : user ['id' ]
288308 )
289309
290310 def test_impersonated_non_existing_claims (self ):
@@ -293,8 +313,8 @@ def test_impersonated_non_existing_claims(self):
293313 resp = dc_client .execute_graphql (
294314 QUERY_LIST_USERS , options = OPTS_NON_EXISTING_CLAIMS
295315 )
296- assert sorted (resp .data ['users' ], key = lambda x : x ['id' ]) == sorted (
297- INITIAL_STATE ['users' ], key = lambda x : x ['id' ]
316+ assert sorted (resp .data ['users' ], key = lambda user : user ['id' ]) == sorted (
317+ INITIAL_STATE ['users' ], key = lambda user : user ['id' ]
298318 )
299319
300320
0 commit comments