def test_post_with_session(self): session = Mock() store_api_call('/path', method='POST', session=session) session.post.assert_called_once_with( 'http://example.com/path', data=None, headers={'Content-Type': 'application/json'})
def test_post_error(self): response_data = {'response': 'value'} responses.add(responses.POST, 'http://example.com/path', body=json.dumps(response_data), status=500) result = store_api_call('/path', method='POST') self.assertEqual(result, { 'success': False, 'data': None, 'errors': [json.dumps(response_data)], })
def test_post_success(self): response_data = {'response': 'value'} responses.add(responses.POST, 'http://example.com/path', body=json.dumps(response_data)) result = store_api_call('/path', method='POST') self.assertEqual(result, { 'success': True, 'data': response_data, 'errors': [], })
def test_post_with_data(self): response_data = {'response': 'value'} responses.add(responses.POST, 'http://example.com/path', body=json.dumps(response_data)) result = store_api_call( '/path', method='POST', data={'request': 'value'}) self.assertEqual(result, { 'success': True, 'data': response_data, 'errors': [], }) self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.headers['Content-Type'], 'application/json') self.assertEqual(responses.calls[0].request.body, json.dumps({'request': 'value'}))
def test_get_with_session(self): session = Mock() store_api_call('/path', session=session) session.get.assert_called_once_with('http://example.com/path')