mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
REQUEST now supports POST (#588)
* REQUEST now supports POST * Add extra flag for enabling REQUEST, also update README and comments Co-authored-by: John Cant <a.jonncant@gmail.com> Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import unittest
|
||||
import test_engine
|
||||
import testutil
|
||||
from functions import CaseInsensitiveDict, Response, HTTPError
|
||||
from functions.info import _replicate_requests_body_args
|
||||
|
||||
|
||||
class TestCaseInsensitiveDict(unittest.TestCase):
|
||||
@@ -73,6 +74,45 @@ class TestResponse(unittest.TestCase):
|
||||
self.assertEqual(r.text, text)
|
||||
|
||||
|
||||
class TestRequestsPostInterface(unittest.TestCase):
|
||||
def test_no_post_args(self):
|
||||
body, headers = _replicate_requests_body_args()
|
||||
|
||||
assert body is None
|
||||
assert headers == {}
|
||||
|
||||
def test_data_as_dict(self):
|
||||
body, headers = _replicate_requests_body_args(data={"foo": "bar"})
|
||||
|
||||
assert body == "foo=bar"
|
||||
assert headers == {"Content-Type": "application/x-www-form-urlencoded"}
|
||||
|
||||
def test_data_as_string(self):
|
||||
body, headers = _replicate_requests_body_args(data="some_content")
|
||||
|
||||
assert body == "some_content"
|
||||
assert headers == {}
|
||||
|
||||
def test_json_as_dict(self):
|
||||
body, headers = _replicate_requests_body_args(json={"foo": "bar"})
|
||||
|
||||
assert body == '{"foo": "bar"}'
|
||||
assert headers == {"Content-Type": "application/json"}
|
||||
|
||||
def test_json_as_string(self):
|
||||
body, headers = _replicate_requests_body_args(json="invalid_but_ignored")
|
||||
|
||||
assert body == "invalid_but_ignored"
|
||||
assert headers == {"Content-Type": "application/json"}
|
||||
|
||||
def test_data_and_json_together(self):
|
||||
with self.assertRaises(ValueError):
|
||||
body, headers = _replicate_requests_body_args(
|
||||
json={"foo": "bar"},
|
||||
data={"quux": "jazz"}
|
||||
)
|
||||
|
||||
|
||||
class TestRequestFunction(test_engine.EngineTestCase):
|
||||
sample = testutil.parse_test_sample({
|
||||
"SCHEMA": [
|
||||
@@ -98,12 +138,14 @@ r = REQUEST('my_url', headers={'foo': 'bar'}, params={'b': 1, 'a': 2})
|
||||
r.__dict__
|
||||
"""
|
||||
out_actions = self.modify_column("Table1", "Request", formula=formula)
|
||||
key = '9d305be9664924aaaf7ebb0bab2e4155d1fa1b9dcde53e417f1a9f9a2c7e09b9'
|
||||
key = 'd7f8cedf177ab538bf7dadf66e77a525486a29a41ce4520b2c89a33e39095fed'
|
||||
deps = {'Table1': {'Request': [1, 2]}}
|
||||
args = {
|
||||
'url': 'my_url',
|
||||
'headers': {'foo': 'bar'},
|
||||
'params': {'a': 2, 'b': 1},
|
||||
'method': 'GET',
|
||||
'body': None,
|
||||
'deps': deps,
|
||||
}
|
||||
self.assertEqual(out_actions.requests, {key: args})
|
||||
|
||||
Reference in New Issue
Block a user