forked from OCA/rest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
35 additions
and
59 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import json | ||
|
||
from werkzeug.urls import url_encode | ||
|
||
from odoo.tests import HttpCase | ||
|
@@ -11,18 +12,14 @@ | |
|
||
class TestController(HttpCase): | ||
def url_open_json(self, url, json): | ||
return self.opener.post( | ||
"http://%s:%s%s" % (HOST, PORT, url), json=json | ||
) | ||
return self.opener.post("http://{}:{}{}".format(HOST, PORT, url), json=json) | ||
|
||
def _check_all_partners(self, all_partners, companies_only=False): | ||
domain = [] | ||
if companies_only: | ||
domain.append(("is_company", "=", True)) | ||
expected_names = set( | ||
self.env["res.partner"].search(domain).mapped("name") | ||
) | ||
actual_names = set(r["name"] for r in all_partners) | ||
expected_names = set(self.env["res.partner"].search(domain).mapped("name")) | ||
actual_names = {r["name"] for r in all_partners} | ||
self.assertEqual(actual_names, expected_names) | ||
|
||
def test_get(self): | ||
|
@@ -48,9 +45,7 @@ def test_get_with_variables(self): | |
r = self.url_open("/graphql/demo?" + url_encode(data)) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["Content-Type"], "application/json") | ||
self._check_all_partners( | ||
r.json()["data"]["allPartners"], companies_only=True | ||
) | ||
self._check_all_partners(r.json()["data"]["allPartners"], companies_only=True) | ||
|
||
def test_post_form(self): | ||
self.authenticate("admin", "admin") | ||
|
@@ -75,9 +70,7 @@ def test_post_form_with_variables(self): | |
r = self.url_open("/graphql/demo", data=data) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["Content-Type"], "application/json") | ||
self._check_all_partners( | ||
r.json()["data"]["allPartners"], companies_only=True | ||
) | ||
self._check_all_partners(r.json()["data"]["allPartners"], companies_only=True) | ||
|
||
def test_post_json_with_variables(self): | ||
self.authenticate("admin", "admin") | ||
|
@@ -93,9 +86,7 @@ def test_post_json_with_variables(self): | |
r = self.url_open_json("/graphql/demo", data) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["Content-Type"], "application/json") | ||
self._check_all_partners( | ||
r.json()["data"]["allPartners"], companies_only=True | ||
) | ||
self._check_all_partners(r.json()["data"]["allPartners"], companies_only=True) | ||
|
||
def test_post_form_mutation(self): | ||
self.authenticate("admin", "admin") | ||
|
@@ -112,16 +103,9 @@ def test_post_form_mutation(self): | |
r = self.url_open("/graphql/demo", data=data) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["Content-Type"], "application/json") | ||
self.assertEqual("Le Héro, Toto", r.json()["data"]["createPartner"]["name"]) | ||
self.assertEqual( | ||
"Le Héro, Toto", r.json()["data"]["createPartner"]["name"] | ||
) | ||
self.assertEqual( | ||
len( | ||
self.env["res.partner"].search( | ||
[("email", "=", "[email protected]")] | ||
) | ||
), | ||
1, | ||
len(self.env["res.partner"].search([("email", "=", "[email protected]")])), 1 | ||
) | ||
|
||
def test_get_mutation_not_allowed(self): | ||
|
@@ -168,10 +152,5 @@ def test_post_form_mutation_rollback(self): | |
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, | ||
len(self.env["res.partner"].search([("email", "=", "[email protected]")])), 0 | ||
) |
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