Adds tests for HTTPClient.raw_client
Imports mock in test file. Changes name for UrlGeneration tests Adds tests for HTTPClient.raw_client
This commit is contained in:

committed by
Jiri Stransky

parent
1eb8891ab8
commit
2ec4bbbc2e
@@ -17,11 +17,12 @@ from tuskarclient.tests import utils as tutils
|
||||
|
||||
from tuskarclient.common import http
|
||||
|
||||
import mock
|
||||
|
||||
fixtures = {}
|
||||
|
||||
|
||||
class HttpClientTest(tutils.TestCase):
|
||||
class HttpClientUrlGenerationTest(tutils.TestCase):
|
||||
|
||||
def test_url_generation_trailing_slash_in_base(self):
|
||||
client = http.HTTPClient('http://localhost/')
|
||||
@@ -46,3 +47,69 @@ class HttpClientTest(tutils.TestCase):
|
||||
url = client._make_connection_url('v1/resources')
|
||||
print client.connection_params
|
||||
self.assertEqual(url, '/v1/resources')
|
||||
|
||||
|
||||
class HttpClientRawRequestTest(tutils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(HttpClientRawRequestTest, self).setUp()
|
||||
|
||||
client = http.HTTPClient('http://localhost')
|
||||
client._http_request = mock.MagicMock(name='_http_request')
|
||||
self.client = client
|
||||
|
||||
self.call_args = {'provided_method': 'method',
|
||||
'expected_method': 'method',
|
||||
'provided_url': 'url',
|
||||
'expected_url': 'url',
|
||||
'provided_args': {
|
||||
'headers': {},
|
||||
'other': {}},
|
||||
'expected_args': {
|
||||
'headers': {
|
||||
'Content-Type': 'application/octet-stream'},
|
||||
'other': {}}}
|
||||
|
||||
def raw_request_calls_http_request(self,
|
||||
provided_method=None,
|
||||
provided_url=None,
|
||||
provided_args={},
|
||||
expected_method=None,
|
||||
expected_url=None,
|
||||
expected_args={}):
|
||||
self.client.raw_request(provided_method,
|
||||
provided_url,
|
||||
**provided_args)
|
||||
self.client._http_request.\
|
||||
assert_called_once_with(expected_url,
|
||||
expected_method,
|
||||
**expected_args)
|
||||
|
||||
def test_raw_request_set_default_headers_with_empty_kwargs(self):
|
||||
args = self.call_args.copy()
|
||||
self.raw_request_calls_http_request(**args)
|
||||
|
||||
def test_raw_request_set_default_headers_without_headers(self):
|
||||
args = self.call_args.copy()
|
||||
args['provided_args']['other'] = 'other_value'
|
||||
args['expected_args']['other'] = 'other_value'
|
||||
self.raw_request_calls_http_request(**args)
|
||||
|
||||
def test_raw_request_set_default_headers_with_other_headers(self):
|
||||
args = self.call_args.copy()
|
||||
args['provided_args']['other'] = 'other_value'
|
||||
args['expected_args']['other'] = 'other_value'
|
||||
args['provided_args']['headers'] = {'other_header': 'other_value'}
|
||||
args['expected_args']['headers'] = {'other_header':
|
||||
'other_value',
|
||||
'Content-Type':
|
||||
'application/octet-stream'}
|
||||
self.raw_request_calls_http_request(**args)
|
||||
|
||||
def test_raw_request_set_default_headers_with_conflicting_header(self):
|
||||
args = self.call_args.copy()
|
||||
args['provided_args']['headers'] = {'Content-Type':
|
||||
'conflicting_header_value'}
|
||||
args['expected_args']['headers'] = {'Content-Type':
|
||||
'conflicting_header_value'}
|
||||
self.raw_request_calls_http_request(**args)
|
||||
|
Reference in New Issue
Block a user