Fix warnings in tests
authorLaurent Wouters <lwouters@cenotelie.fr>
Wed, 29 Apr 2020 15:06:28 +0200
changeset 15 cba52ce2eb91
parent 14 b7ea973e38d8
child 16 bc001415dcbe
Fix warnings in tests
cubicweb_graphql/querier.py
test/test_graphql.py
--- a/cubicweb_graphql/querier.py	Wed Apr 29 15:00:44 2020 +0200
+++ b/cubicweb_graphql/querier.py	Wed Apr 29 15:06:28 2020 +0200
@@ -74,7 +74,7 @@
         :param kwargs: The mapping of values for the named variables in the query
         :return: The GraphQL execution result
         """
-        return self._query_schema.execute(query, context={CONNECTION: connection}, variables=kwargs)
+        return self._query_schema.execute(query, context_value={CONNECTION: connection}, variable_values=kwargs)
 
 
 def default_format_error(error):
--- a/test/test_graphql.py	Wed Apr 29 15:00:44 2020 +0200
+++ b/test/test_graphql.py	Wed Apr 29 15:06:28 2020 +0200
@@ -80,7 +80,7 @@
         query = "{ Personne { nom, prenom, sexe } }"
         with self.admin_access.repo_cnx() as cnx:
             result = self.gql_ok(cnx, query)
-            self.assertEquals(len(result.data["Personne"]), 1)
+            self.assertEqual(len(result.data["Personne"]), 1)
 
     def test_empty_when_cannot_read_simple(self):
         query = "{ Affaire { sujet } }"
@@ -89,11 +89,11 @@
             with self.admin_access.repo_cnx() as cnx:
                 # Reading is OK for the manager
                 result = self.gql_ok(cnx, query)
-                self.assertEquals(len(result.data["Affaire"]), 1)
+                self.assertEqual(len(result.data["Affaire"]), 1)
             with self.new_access(u'anon').repo_cnx() as cnx:
                 # Reading is not OK for anonymous
                 result = self.gql_ok(cnx, query)
-                self.assertEquals(len(result.data["Affaire"]), 0)
+                self.assertEqual(len(result.data["Affaire"]), 0)
 
     def test_empty_when_cannot_read_with_args(self):
         query = "query getAffaire($sujet: String) { Affaire(sujet: $sujet) { sujet } }"
@@ -102,11 +102,11 @@
             with self.admin_access.repo_cnx() as cnx:
                 # Reading is OK for the manager
                 result = self.gql_ok(cnx, query, sujet="cool")
-                self.assertEquals(len(result.data["Affaire"]), 1)
+                self.assertEqual(len(result.data["Affaire"]), 1)
             with self.new_access(u'anon').repo_cnx() as cnx:
                 # Reading is not OK for anonymous
                 result = self.gql_ok(cnx, query, sujet="cool")
-                self.assertEquals(len(result.data["Affaire"]), 0)
+                self.assertEqual(len(result.data["Affaire"]), 0)
 
     def test_upassword_not_selectable(self):
         query = "{ CWUser { login, upassword } }"
@@ -138,11 +138,11 @@
             result = self.gql_nok(cnx, "query getStuff($x: ID) { Affaire(eid: $x) {eid, sujet} }", x=aff1)
             self.assertIsNone(result.data["Affaire"])
             result = self.gql_ok(cnx, "query getStuff($x: ID) { Affaire(eid: $x) {eid, sujet} }", x=aff2)
-            self.assertEquals(len(result.data["Affaire"]), 1)
-            self.assertEquals(result.data["Affaire"][0]["eid"], str(aff2))
+            self.assertEqual(len(result.data["Affaire"]), 1)
+            self.assertEqual(result.data["Affaire"][0]["eid"], str(aff2))
             result = self.gql_ok(cnx, "query getStuff($x: ID) { Card(eid: $x) {eid, title} }", x=card1)
-            self.assertEquals(len(result.data["Card"]), 1)
-            self.assertEquals(result.data["Card"][0]["eid"], str(card1))
+            self.assertEqual(len(result.data["Card"]), 1)
+            self.assertEqual(result.data["Card"][0]["eid"], str(card1))
 
     def test_insert_security(self):
         with self.new_access(u'anon').repo_cnx() as cnx:
@@ -252,13 +252,13 @@
             self.assertRaises(Unauthorized, ent.cw_check_perm, 'update')
 
             result = self.gql_ok(cnx, "{ Personne(travaille_as_Societe: {}) { eid } }")
-            self.assertEquals(len(result.data["Personne"]), 0)
+            self.assertEqual(len(result.data["Personne"]), 0)
             self.gql_nok(cnx, "mutation { updatePersonne(old: {}, new: {travaille_as_Societe: {}}) { eid } }")
             self.assertRaises(QueryError, cnx.commit)  # can't commit anymore
             cnx.rollback()
             # test nothing has actually been inserted:
             result = self.gql_ok(cnx, "{ Personne(travaille_as_Societe: {}) { eid } }")
-            self.assertEquals(len(result.data["Personne"]), 0)
+            self.assertEqual(len(result.data["Personne"]), 0)
             self.gql_ok(cnx, "mutation m($nom: String) { createSociete(nom: $nom) {nom} }", nom=u"chouette")
             self.gql_ok(cnx, "mutation m($nom: String) { updateAffaire(old: {}, new: {concerne_as_Societe: {nom: $nom}}) {sujet} }", nom=u"chouette")
             cnx.commit()
@@ -304,7 +304,7 @@
             result = GraphQLQuerier.execute(cnx, query)
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Affaire"]), 2)
+            self.assertEqual(len(result.data["Affaire"]), 2)
 
     def test_simple_query_with_eid_arg(self):
         """
@@ -316,13 +316,13 @@
             result = GraphQLQuerier.execute(cnx, query, affaire_eid=self.affaire1)
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Affaire"]), 1)
-            self.assertEquals(result.data["Affaire"][0]["sujet"], "affaire1")
+            self.assertEqual(len(result.data["Affaire"]), 1)
+            self.assertEqual(result.data["Affaire"][0]["sujet"], "affaire1")
             result = GraphQLQuerier.execute(cnx, query, affaire_eid=self.affaire2)
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Affaire"]), 1)
-            self.assertEquals(result.data["Affaire"][0]["sujet"], "affaire2")
+            self.assertEqual(len(result.data["Affaire"]), 1)
+            self.assertEqual(result.data["Affaire"][0]["sujet"], "affaire2")
 
     def test_simple_query_with_eid_arg_double(self):
         """
@@ -334,8 +334,8 @@
             result = GraphQLQuerier.execute(cnx, query, eid1=self.affaire1, eid2=self.affaire2)
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(result.data["affaire1"][0]["sujet"], "affaire1")
-            self.assertEquals(result.data["affaire2"][0]["sujet"], "affaire2")
+            self.assertEqual(result.data["affaire1"][0]["sujet"], "affaire1")
+            self.assertEqual(result.data["affaire2"][0]["sujet"], "affaire2")
 
     def test_nested_query_arguments(self):
         """
@@ -352,10 +352,10 @@
             result = GraphQLQuerier.execute(cnx, query, pn="personne1", sn="societe1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Personne"]), 1)
-            self.assertEquals(result.data["Personne"][0]["nom"], "personne1")
-            self.assertEquals(len(result.data["Personne"][0]["travaille"]), 1)
-            self.assertEquals(result.data["Personne"][0]["travaille"][0]["nom"], "societe1")
+            self.assertEqual(len(result.data["Personne"]), 1)
+            self.assertEqual(result.data["Personne"][0]["nom"], "personne1")
+            self.assertEqual(len(result.data["Personne"][0]["travaille"]), 1)
+            self.assertEqual(result.data["Personne"][0]["travaille"][0]["nom"], "societe1")
 
     def test_complex_query_arguments(self):
         """
@@ -372,10 +372,10 @@
             result = GraphQLQuerier.execute(cnx, query, nom="societe1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Personne"]), 1)
-            self.assertEquals(result.data["Personne"][0]["nom"], "personne1")
-            self.assertEquals(len(result.data["Personne"][0]["travaille"]), 1)
-            self.assertEquals(result.data["Personne"][0]["travaille"][0]["nom"], "societe1")
+            self.assertEqual(len(result.data["Personne"]), 1)
+            self.assertEqual(result.data["Personne"][0]["nom"], "personne1")
+            self.assertEqual(len(result.data["Personne"][0]["travaille"]), 1)
+            self.assertEqual(result.data["Personne"][0]["travaille"][0]["nom"], "societe1")
 
     def test_argument_on_scalar_field(self):
         """
@@ -392,11 +392,11 @@
             result = GraphQLQuerier.execute(cnx, query, title="fiche1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["Personne"]), 2)
-            self.assertEquals(result.data["Personne"][0]["nom"], "personne1")
-            self.assertEquals(result.data["Personne"][0]["fiche"]["title"], "fiche1")
-            self.assertEquals(result.data["Personne"][1]["nom"], "personne2")
-            self.assertEquals(result.data["Personne"][1]["fiche"], None)
+            self.assertEqual(len(result.data["Personne"]), 2)
+            self.assertEqual(result.data["Personne"][0]["nom"], "personne1")
+            self.assertEqual(result.data["Personne"][0]["fiche"]["title"], "fiche1")
+            self.assertEqual(result.data["Personne"][1]["nom"], "personne2")
+            self.assertEqual(result.data["Personne"][1]["fiche"], None)
 
     def test_mutation_insert_simple(self):
         """
@@ -407,9 +407,9 @@
             result = GraphQLQuerier.execute(cnx, query, sujet=u"cool")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["createAffaire"]), 2)
+            self.assertEqual(len(result.data["createAffaire"]), 2)
             self.assertIsNotNone(result.data["createAffaire"]["eid"])
-            self.assertEquals(result.data["createAffaire"]["sujet"], u"cool")
+            self.assertEqual(result.data["createAffaire"]["sujet"], u"cool")
 
     def test_mutation_insert_with_where(self):
         """
@@ -424,11 +424,11 @@
                                             sujet=u"affaire1", societe=u"societe1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["createAffaire"]), 3)
-            self.assertEquals(result.data["createAffaire"]["sujet"], u"affaire1")
-            self.assertEquals(len(result.data["createAffaire"]["concerne"]), 1)
-            self.assertEquals(result.data["createAffaire"]["concerne"][0]["nom"], u"societe1")
-            self.assertEquals(result.data["createAffaire"]["concerne"][0]["eid"], societe1)
+            self.assertEqual(len(result.data["createAffaire"]), 3)
+            self.assertEqual(result.data["createAffaire"]["sujet"], u"affaire1")
+            self.assertEqual(len(result.data["createAffaire"]["concerne"]), 1)
+            self.assertEqual(result.data["createAffaire"]["concerne"][0]["nom"], u"societe1")
+            self.assertEqual(result.data["createAffaire"]["concerne"][0]["eid"], societe1)
 
     def test_mutation_update_simple(self):
         """
@@ -443,10 +443,10 @@
                                             nom_new=u"societe2")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["updateSociete"]), 1)
-            self.assertEquals(len(result.data["updateSociete"][0]), 2)
-            self.assertEquals(result.data["updateSociete"][0]["eid"], societe1)
-            self.assertEquals(result.data["updateSociete"][0]["nom"], u"societe2")
+            self.assertEqual(len(result.data["updateSociete"]), 1)
+            self.assertEqual(len(result.data["updateSociete"][0]), 2)
+            self.assertEqual(result.data["updateSociete"][0]["eid"], societe1)
+            self.assertEqual(result.data["updateSociete"][0]["nom"], u"societe2")
 
     def test_mutation_update_object_field(self):
         """
@@ -468,13 +468,13 @@
                                             societe=u"societe1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["updateAffaire"]), 1)
-            self.assertEquals(len(result.data["updateAffaire"][0]), 3)
-            self.assertEquals(result.data["updateAffaire"][0]["eid"], str(self.affaire1))
-            self.assertEquals(result.data["updateAffaire"][0]["sujet"], u"affaire1")
-            self.assertEquals(len(result.data["updateAffaire"][0]["concerne"]), 1)
-            self.assertEquals(result.data["updateAffaire"][0]["concerne"][0]["eid"], societe1)
-            self.assertEquals(result.data["updateAffaire"][0]["concerne"][0]["nom"], u"societe1")
+            self.assertEqual(len(result.data["updateAffaire"]), 1)
+            self.assertEqual(len(result.data["updateAffaire"][0]), 3)
+            self.assertEqual(result.data["updateAffaire"][0]["eid"], str(self.affaire1))
+            self.assertEqual(result.data["updateAffaire"][0]["sujet"], u"affaire1")
+            self.assertEqual(len(result.data["updateAffaire"][0]["concerne"]), 1)
+            self.assertEqual(result.data["updateAffaire"][0]["concerne"][0]["eid"], societe1)
+            self.assertEqual(result.data["updateAffaire"][0]["concerne"][0]["nom"], u"societe1")
 
             result = GraphQLQuerier.execute(cnx, "mutation myMutation($sujet: String, $societe: String) { updateAffaire("
                                                  "old: {sujet: $sujet}"
@@ -484,13 +484,13 @@
                                             societe=u"societe2")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["updateAffaire"]), 1)
-            self.assertEquals(len(result.data["updateAffaire"][0]), 3)
-            self.assertEquals(result.data["updateAffaire"][0]["eid"], str(self.affaire2))
-            self.assertEquals(result.data["updateAffaire"][0]["sujet"], u"affaire2")
-            self.assertEquals(len(result.data["updateAffaire"][0]["concerne"]), 1)
-            self.assertEquals(result.data["updateAffaire"][0]["concerne"][0]["eid"], societe2)
-            self.assertEquals(result.data["updateAffaire"][0]["concerne"][0]["nom"], u"societe2")
+            self.assertEqual(len(result.data["updateAffaire"]), 1)
+            self.assertEqual(len(result.data["updateAffaire"][0]), 3)
+            self.assertEqual(result.data["updateAffaire"][0]["eid"], str(self.affaire2))
+            self.assertEqual(result.data["updateAffaire"][0]["sujet"], u"affaire2")
+            self.assertEqual(len(result.data["updateAffaire"][0]["concerne"]), 1)
+            self.assertEqual(result.data["updateAffaire"][0]["concerne"][0]["eid"], societe2)
+            self.assertEqual(result.data["updateAffaire"][0]["concerne"][0]["nom"], u"societe2")
 
     def test_mutation_delete_simple_single(self):
         """
@@ -508,8 +508,8 @@
                                             societe=u"societe1")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["deleteSociete"]), 1)
-            self.assertEquals(result.data["deleteSociete"][0], societe1)
+            self.assertEqual(len(result.data["deleteSociete"]), 1)
+            self.assertEqual(result.data["deleteSociete"][0], societe1)
 
     def test_mutation_delete_simple_multiple(self):
         """
@@ -526,9 +526,9 @@
             result = GraphQLQuerier.execute(cnx, "mutation myMutation { deleteSociete }")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["deleteSociete"]), 2)
-            self.assertEquals(result.data["deleteSociete"][0], societe1)
-            self.assertEquals(result.data["deleteSociete"][1], societe2)
+            self.assertEqual(len(result.data["deleteSociete"]), 2)
+            self.assertEqual(result.data["deleteSociete"][0], societe1)
+            self.assertEqual(result.data["deleteSociete"][1], societe2)
 
     def test_mutation_delete_relation(self):
         """
@@ -539,17 +539,17 @@
                                             nom=u"societe1")
             societe1 = result.data["createSociete"]["eid"]
             result = GraphQLQuerier.execute(cnx, "mutation m($s: ID, $a: ID) { updateAffaire(old: {eid: $a}, new: {concerne_as_Societe: {eid: $s}}) {eid, concerne {... on Societe {eid}}} }", s=societe1, a=self.affaire1)
-            self.assertEquals(result.data["updateAffaire"][0]["eid"], str(self.affaire1))
-            self.assertEquals(result.data["updateAffaire"][0]["concerne"][0]["eid"], str(societe1))
+            self.assertEqual(result.data["updateAffaire"][0]["eid"], str(self.affaire1))
+            self.assertEqual(result.data["updateAffaire"][0]["concerne"][0]["eid"], str(societe1))
             result = GraphQLQuerier.execute(cnx, "{ Affaire { eid, concerne { ... on Societe { eid } } } }")
-            self.assertEquals(result.data["Affaire"][0]["eid"], str(self.affaire1))
-            self.assertEquals(result.data["Affaire"][0]["concerne"][0]["eid"], str(societe1))
+            self.assertEqual(result.data["Affaire"][0]["eid"], str(self.affaire1))
+            self.assertEqual(result.data["Affaire"][0]["concerne"][0]["eid"], str(societe1))
             result = GraphQLQuerier.execute(cnx, "mutation m($s: ID, $a: ID) { deleteFromAffaire(from: {eid: $a}, concerne_as_Societe: {eid: $s}) }", s=societe1, a=self.affaire1)
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
             result = GraphQLQuerier.execute(cnx, "{ Affaire { eid, concerne { ... on Societe { eid } } } }")
-            self.assertEquals(result.data["Affaire"][0]["eid"], str(self.affaire1))
-            self.assertEquals(len(result.data["Affaire"][0]["concerne"]), 0)
+            self.assertEqual(result.data["Affaire"][0]["eid"], str(self.affaire1))
+            self.assertEqual(len(result.data["Affaire"][0]["concerne"]), 0)
             pass
 
 
@@ -566,7 +566,7 @@
             result = GraphQLQuerier.execute(cnx, "{ __schema { queryType { fields { name } } } }")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["__schema"]["queryType"]["fields"]), 45)
+            self.assertEqual(len(result.data["__schema"]["queryType"]["fields"]), 45)
             found_affaire = False
             for t in result.data["__schema"]["queryType"]["fields"]:
                 if t["name"] == "Affaire":
@@ -581,7 +581,7 @@
             result = GraphQLQuerier.execute(cnx, "{ CWEType(final: false) { name } }")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["CWEType"]), 45)
+            self.assertEqual(len(result.data["CWEType"]), 45)
             found_affaire = False
             for t in result.data["CWEType"]:
                 if t["name"] == "Affaire":
@@ -596,7 +596,7 @@
             result = GraphQLQuerier.execute(cnx, "query q($name: String!) { __type(name: $name) { name, fields { name, type { name, kind } } } }", name="Affaire")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["__type"]["fields"]), 28)
+            self.assertEqual(len(result.data["__type"]["fields"]), 28)
             found = False
             for f in result.data["__type"]["fields"]:
                 if f["name"] == "todo_by":
@@ -611,7 +611,7 @@
             result = GraphQLQuerier.execute(cnx, "query q($name: String!) { CWRelation(from_entity: {name: $name}) { relation_type { name }, to_entity { name } } }", name="Affaire")
             self.assertIsNone(result.errors)
             self.assertIsNotNone(result.data)
-            self.assertEquals(len(result.data["CWRelation"]), 16)
+            self.assertEqual(len(result.data["CWRelation"]), 16)
             found = False
             for f in result.data["CWRelation"]:
                 if f["relation_type"][0]["name"] == "todo_by":