-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] graphql: controller must rollback in case of error
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from odoo.tests import HttpCase | ||
from odoo.tests.common import HOST, PORT | ||
from odoo.tools import mute_logger | ||
|
||
|
||
class TestController(HttpCase): | ||
|
@@ -114,6 +115,14 @@ def test_post_form_mutation(self): | |
self.assertEqual( | ||
"Le Héro, Toto", r.json()["data"]["createPartner"]["name"] | ||
) | ||
self.assertEqual( | ||
len( | ||
self.env["res.partner"].search( | ||
[("email", "=", "[email protected]")] | ||
) | ||
), | ||
1, | ||
) | ||
|
||
def test_get_mutation_not_allowed(self): | ||
""" | ||
|
@@ -137,3 +146,32 @@ def test_get_mutation_not_allowed(self): | |
"Can only perform a mutation operation from a POST request.", | ||
r.json()["errors"][0]["message"], | ||
) | ||
|
||
@mute_logger("graphql.execution.executor", "graphql.execution.utils") | ||
def test_post_form_mutation_rollback(self): | ||
self.authenticate("admin", "admin") | ||
query = """ | ||
mutation { | ||
createPartner( | ||
name: "Le Héro, Toto", | ||
email: "[email protected]", | ||
raiseAfterCreate: true | ||
) { | ||
name | ||
} | ||
} | ||
""" | ||
data = {"query": query} | ||
r = self.url_open("/graphql/demo", data=data) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["Content-Type"], "application/json") | ||
self.assertIn("as requested", r.json()["errors"][0]["message"]) | ||
# a rollback must have occured | ||
self.assertEqual( | ||
len( | ||
self.env["res.partner"].search( | ||
[("email", "=", "[email protected]")] | ||
) | ||
), | ||
0, | ||
) |