Here are the examples of the python api requests.post.assert_called_with taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
8 Examples
3
Example 1
Project: st2 Source File: test_ssl.py
@mock.patch.object(
requests, 'post',
mock.MagicMock(return_value=base.FakeResponse(json.dumps({}), 200, 'OK')))
def test_decorate_https_without_cacert(self):
self.shell.run(['auth', USERNAME, '-p', PASSWORD])
kwargs = {'verify': False, 'headers': HEADERS, 'auth': (USERNAME, PASSWORD)}
requests.post.assert_called_with(AUTH_URL, json.dumps({}), **kwargs)
3
Example 2
Project: st2 Source File: test_ssl.py
@mock.patch.object(
requests, 'post',
mock.MagicMock(return_value=base.FakeResponse(json.dumps({}), 200, 'OK')))
def test_decorate_https_with_cacert_from_cli(self):
self.shell.run(['--cacert', self.cacert_path, 'auth', USERNAME, '-p', PASSWORD])
kwargs = {'verify': self.cacert_path, 'headers': HEADERS, 'auth': (USERNAME, PASSWORD)}
requests.post.assert_called_with(AUTH_URL, json.dumps({}), **kwargs)
3
Example 3
Project: st2 Source File: test_ssl.py
@mock.patch.object(
requests, 'post',
mock.MagicMock(return_value=base.FakeResponse(json.dumps({}), 200, 'OK')))
def test_decorate_https_with_cacert_from_env(self):
os.environ['ST2_CACERT'] = self.cacert_path
self.shell.run(['auth', USERNAME, '-p', PASSWORD])
kwargs = {'verify': self.cacert_path, 'headers': HEADERS, 'auth': (USERNAME, PASSWORD)}
requests.post.assert_called_with(AUTH_URL, json.dumps({}), **kwargs)
3
Example 4
Project: gif2html5-app Source File: test_server.py
@patch('gif2html5.video_manager.convert')
@patch('requests.post')
def test_video_converter_task(self, mock_video_manager, mock_requests):
mock_video_manager.return_value = {'webm': 'file.webm', 'mp4': 'file.mp4', 'ogv': 'file.ogv', 'snapshot': 'snapshot.png'}
server.upload_resources = MagicMock(return_value={})
server.convert_video.apply(args=('http://media.giphy.com/media/WSqcqvTxgwfYs/giphy.gif', 'http://www.google.com?attachment_id=123')).get()
payload = {'attachment_id': '123'}
requests.post.assert_called_with('http://www.google.com?attachment_id=123', data=JsonPayloadAttachmentIdMatcher(payload))
3
Example 5
Project: python-mistralclient Source File: test_httpclient.py
@mock.patch.object(
requests,
'post',
mock.MagicMock(return_value=FakeResponse('post', EXPECTED_URL, 201))
)
def test_get_request_options_with_headers_for_post(self):
headers = {'foo': 'bar'}
self.client.post(API_URL, EXPECTED_BODY, headers=headers)
expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS)
expected_options['headers'].update(headers)
expected_options['headers']['content-type'] = 'application/json'
requests.post.assert_called_with(
EXPECTED_URL,
EXPECTED_BODY,
**expected_options
)
2
Example 6
Project: st2 Source File: test_auth.py
@mock.patch.object(
requests, 'post',
mock.MagicMock(return_value=base.FakeResponse(json.dumps(RULE), 200, 'OK')))
def test_decorate_resource_post(self):
url = 'http://127.0.0.1:9101/v1/rules'
data = {'name': RULE['name'], 'description': RULE['description']}
fd, path = tempfile.mkstemp(suffix='.json')
try:
with open(path, 'a') as f:
f.write(json.dumps(data, indent=4))
# Test without token.
self.shell.run(['rule', 'create', path])
kwargs = {'headers': {'content-type': 'application/json'}}
requests.post.assert_called_with(url, json.dumps(data), **kwargs)
# Test with token from cli.
token = uuid.uuid4().hex
self.shell.run(['rule', 'create', path, '-t', token])
kwargs = {'headers': {'content-type': 'application/json', 'X-Auth-Token': token}}
requests.post.assert_called_with(url, json.dumps(data), **kwargs)
# Test with token from env.
token = uuid.uuid4().hex
os.environ['ST2_AUTH_TOKEN'] = token
self.shell.run(['rule', 'create', path])
kwargs = {'headers': {'content-type': 'application/json', 'X-Auth-Token': token}}
requests.post.assert_called_with(url, json.dumps(data), **kwargs)
finally:
os.close(fd)
os.unlink(path)
0
Example 7
Project: gif2html5-app Source File: test_server.py
@patch('requests.post')
def test_video_converter_task_without_attachment_id(self, mock_requests):
server.convert_video.apply(args=('http://media.giphy.com/media/WSqcqvTxgwfYs/giphy.gif', 'http://www.google.com')).get()
requests.post.assert_called_with('http://www.google.com', data={'message': 'It looks like you are missing attachment_id'})
0
Example 8
@mock.patch.object(
httpclient.HTTPClient,
'_get_request_options',
mock.MagicMock(return_value=copy.deepcopy(EXPECTED_REQ_OPTIONS))
)
@mock.patch.object(
requests,
'post',
mock.MagicMock(return_value=FakeResponse('post', EXPECTED_URL, 201))
)
def test_http_post(self):
self.client.post(API_URL, EXPECTED_BODY)
httpclient.HTTPClient._get_request_options.assert_called_with(
'post',
None
)
requests.post.assert_called_with(
EXPECTED_URL,
EXPECTED_BODY,
**EXPECTED_REQ_OPTIONS
)