-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_http_request: support form-urlencoded requests (#43)
* test_http_request: support form-urlencoded requests * Typo * Add unit tets for mock_odoo_request
- Loading branch information
1 parent
3bd88e5
commit 5bc156d
Showing
3 changed files
with
106 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import json | ||
from collections import OrderedDict | ||
from ddt import data, ddt, unpack | ||
from odoo.http import request | ||
from odoo.tests import common | ||
from werkzeug.datastructures import ImmutableMultiDict | ||
from ..common import mock_odoo_request | ||
|
||
|
||
@ddt | ||
class TestMockHttpRequest(common.TransactionCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.data = OrderedDict([ | ||
('firstname', 'John'), | ||
('lastname', 'Doe'), | ||
]) | ||
|
||
def test_env_propagated_to_request(self): | ||
with mock_odoo_request(self.env, data=self.data): | ||
assert request.env == self.env | ||
|
||
def test_method_propagated_to_request(self): | ||
method = 'PATCH' | ||
with mock_odoo_request(self.env, data=self.data, method=method): | ||
assert request.httprequest.method == method | ||
|
||
def test_headers_propagated_to_request(self): | ||
header_key = 'Some-Header' | ||
header_value = 'some value' | ||
headers = { | ||
header_key: header_value, | ||
} | ||
with mock_odoo_request(self.env, data=self.data, headers=headers): | ||
assert request.httprequest.headers[header_key] == header_value | ||
|
||
@data( | ||
('http', 'application/x-www-form-urlencoded'), | ||
('json', 'application/json'), | ||
) | ||
@unpack | ||
def test_content_type(self, routing_type, content_type): | ||
with mock_odoo_request(self.env, data=self.data, routing_type=routing_type): | ||
assert request.httprequest.content_type == content_type | ||
|
||
def test_if_http_routing__data_contained_in_request_form(self): | ||
with mock_odoo_request(self.env, data=self.data): | ||
assert request.httprequest.form == ImmutableMultiDict(self.data) | ||
assert not request.httprequest.data | ||
|
||
def test_if_json_routing__data_contained_in_request_data(self): | ||
json_data = json.dumps(self.data).encode() | ||
with mock_odoo_request(self.env, data=self.data, routing_type='json'): | ||
assert not request.httprequest.form | ||
assert request.httprequest.data == json_data |