def test_api_raises_exception_with_if_data_status_is_false(self, request_mock): data = a_response_data(status=False, error_code=1, error_message="invalid method specified: client.miss", data=None) ubersmith_api = api.init(self.url, self.username, self.password) self.expect_a_ubersmith_call(request_mock, method="client.miss", data=data) assert_that(calling(ubersmith_api.client.miss), raises(UbersmithException))
def test_api_raises_exception_with_if_data_status_is_false(self, requests_mock): data = a_response_data(status=False, error_code=1, error_message='invalid method specified: client.miss', data='schwifty') ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) self.expect_a_ubersmith_call_post(requests_mock, method='client.miss', returning=data) assert_that(calling(ubersmith_api.client.miss), raises(ubersmith_client.exceptions.UbersmithException))
def test_api_get_method_returns_without_arguments(self, requests_mock): json_data = {"company": "council of ricks"} expected_call = self.expect_a_ubersmith_call( requests_mock=requests_mock, method="client.list", returning=a_response_data(data=json_data) ) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password, use_http_get=True) response = ubersmith_api.client.list() assert_that(response, equal_to(json_data)) expected_call()
def test_process_ubersmith_response(self): response = Mock(status_code=200, headers={'content-type': 'application/json'}) json_data = { 'client_id': '1', 'first': 'Rick', 'last': 'Sanchez', 'company': 'Wubba lubba dub dub!' } response.json = Mock(return_value=a_response_data(data=json_data)) self.assertDictEqual(json_data, UbersmithRequest.process_ubersmith_response(response))
def test_api_method_returns_with_arguments(self, request_mock): json_data = { 'group_id': '1', 'client_id': '30001', 'assignment_count': '1' } data = a_response_data(data=json_data) self.expect_a_ubersmith_call(request_mock, method="device.ip_group_list", fac_id='1', client_id='30001', data=data) ubersmith_api = api.init(self.url, self.username, self.password) response = ubersmith_api.device.ip_group_list(fac_id=1, client_id=30001) assert_that(response, equal_to(json_data))
def test_api_http_get_method(self, request_mock): json_data = { 'group_id': '666', 'client_id': '30666', 'assignment_count': '1' } data = a_response_data(data=json_data) self.expect_a_ubersmith_call(request_mock, method="device.ip_group_list", fac_id='666', client_id='30666', data=data) ubersmith_api = api.init(self.url, self.username, self.password) response = ubersmith_api.device.ip_group_list.http_get(fac_id=666, client_id=30666) assert_that(response, equal_to(json_data))
def test_api_post_method_returns_without_arguments(self, requests_mock): json_data = {'company': 'schwifty'} expected_call = self.expect_a_ubersmith_call_post( requests_mock=requests_mock, method='client.list', returning=a_response_data(data=json_data)) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) response = ubersmith_api.client.list() assert_that(response, equal_to(json_data)) expected_call()
def test_api_http_post_method_default(self, request_mock): json_data = { 'group_id': '666', 'client_id': '30666', 'assignment_count': '1' } data = a_response_data(data=json_data) self.expect_a_ubersmith_call_post(request_mock, method='device.ip_group_list', fac_id='666', client_id='30666', response_body=data) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password, use_http_post=True) response = ubersmith_api.device.ip_group_list(fac_id=666, client_id=30666) assert_that(response, equal_to(json_data))
def test_api_post_method_returns_without_arguments(self, requests_mock): json_data = { 'company': 'schwifty' } expected_call = self.expect_a_ubersmith_call_post(requests_mock=requests_mock, method='client.list', returning=a_response_data(data=json_data)) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) response = ubersmith_api.client.list() assert_that(response, equal_to(json_data)) expected_call()
def test_process_ubersmith_response(self): response = Mock(status_code=200, headers={'content-type': 'application/json'}) json_data = { 'client_id': '1', 'first': 'Rick', 'last': 'Sanchez', 'company': 'Wubba lubba dub dub!' } response.json = Mock(return_value=a_response_data(data=json_data)) self.assertDictEqual( json_data, UbersmithRequest.process_ubersmith_response(response))
def test_api_raises_exception_with_if_data_status_is_false( self, requests_mock): data = a_response_data( status=False, error_code=1, error_message='invalid method specified: client.miss', data='schwifty') ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) self.expect_a_ubersmith_call_post(requests_mock, method='client.miss', returning=data) assert_that(calling(ubersmith_api.client.miss), raises(ubersmith_client.exceptions.UbersmithException))
def test_api_method_returns_without_arguments(self, request_mock): json_data = [ { 'client_id': '1', 'first': 'John', 'last': 'Snow', 'company': 'The Night Watch' } ] data = a_response_data(data=json_data) self.expect_a_ubersmith_call(request_mock, "client.list", data=data) ubersmith_api = api.init(self.url, self.username, self.password) response = ubersmith_api.client.list() assert_that(response, equal_to(json_data))
def test_api_get_method_returns_with_arguments(self, request_mock): json_data = {"group_id": "1", "client_id": "30001", "assignment_count": "1"} expected_call = self.expect_a_ubersmith_call( requests_mock=request_mock, method="device.ip_group_list", fac_id=1, client_id=30001, returning=a_response_data(data=json_data), ) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password, use_http_get=True) response = ubersmith_api.device.ip_group_list(fac_id=1, client_id=30001) assert_that(response, equal_to(json_data)) expected_call()
def test_api_post_method_returns_with_arguments(self, request_mock): json_data = { 'group_id': '1', 'client_id': '30001', 'assignment_count': '1' } expected_call = self.expect_a_ubersmith_call_post(requests_mock=request_mock, method='device.ip_group_list', fac_id=1, client_id=30001, returning=a_response_data(data=json_data)) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) response = ubersmith_api.device.ip_group_list(fac_id=1, client_id=30001) assert_that(response, equal_to(json_data)) expected_call()
def test_api_post_method_returns_with_arguments(self, request_mock): json_data = { 'group_id': '1', 'client_id': '30001', 'assignment_count': '1' } expected_call = self.expect_a_ubersmith_call_post( requests_mock=request_mock, method='device.ip_group_list', fac_id=1, client_id=30001, returning=a_response_data(data=json_data)) ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) response = ubersmith_api.device.ip_group_list(fac_id=1, client_id=30001) assert_that(response, equal_to(json_data)) expected_call()