Here are the examples of the python api third_party.requests.post taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
Example 1
def call_rpc(ctx, scopes):
r = requests.post(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps({
'scopes': scopes,
'secret': ctx['secret'],
}),
headers={'Content-Type': 'application/json'})
return r.json()
3
Example 2
Project: luci-py Source File: auth_server_test.py
def call_rpc(scopes):
ctx = luci_context.read('local_auth')
r = requests.post(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps({
'scopes': scopes,
'secret': ctx['secret'],
}),
headers={'Content-Type': 'application/json'})
return r.json()
0
Example 3
Project: luci-py Source File: auth_server_test.py
def test_http_level_errors(self):
def token_gen(_scopes):
self.fail('must not be called')
with local_auth_server(token_gen):
# Wrong URL.
ctx = luci_context.read('local_auth')
r = requests.post(
url='http://127.0.0.1:%d/blah/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps({
'scopes': ['A', 'B', 'C'],
'secret': ctx['secret'],
}),
headers={'Content-Type': 'application/json'})
self.assertEqual(404, r.status_code)
# Wrong HTTP method.
r = requests.get(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps({
'scopes': ['A', 'B', 'C'],
'secret': ctx['secret'],
}),
headers={'Content-Type': 'application/json'})
self.assertEqual(501, r.status_code)
# Wrong content type.
r = requests.post(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps({
'scopes': ['A', 'B', 'C'],
'secret': ctx['secret'],
}),
headers={'Content-Type': 'application/xml'})
self.assertEqual(400, r.status_code)
# Bad JSON.
r = requests.post(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data='not a json',
headers={'Content-Type': 'application/json'})
self.assertEqual(400, r.status_code)
0
Example 4
Project: luci-py Source File: auth_server_test.py
def test_validation(self):
def token_gen(_scopes):
self.fail('must not be called')
with local_auth_server(token_gen):
def must_fail(err, body, code=400):
ctx = luci_context.read('local_auth')
r = requests.post(
url='http://127.0.0.1:%d/rpc/LuciLocalAuthService.GetOAuthToken' %
ctx['rpc_port'],
data=json.dumps(body),
headers={'Content-Type': 'application/json'})
self.assertEqual(code, r.status_code)
self.assertIn(err, r.text)
must_fail('"scopes" is required', {})
must_fail('"scopes" is required', {'scopes': []})
must_fail('"scopes" must be a list of strings', {'scopes': 'abc'})
must_fail('"scopes" must be a list of strings', {'scopes': [1]})
must_fail('"secret" is required', {'scopes': ['a']})
must_fail('"secret" must be a string', {'scopes': ['a'], 'secret': 123})
must_fail(
'Invalid "secret"',
{'scopes': ['a'], 'secret': 'abc'},
code=403)