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_with_a_false_identifier(self, request_mock): method = "client.list" self.expect_a_ubersmith_call(request_mock, method=method) ubersmith_api = api.init(self.url, 'not_hapi', 'lol') with self.assertRaises(NoMockAddress) as ube: ubersmith_api.client.list() assert_that(str(ube.exception), equal_to("No mock address: GET " + self.url + "?method=" + method))
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_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_http_post_method_raises_on_result_500(self, request_mock): json_data = { 'data': '778', 'error_code': None, 'error_message': '', 'status': False } self.expect_a_ubersmith_call_post( request_mock, response_body=json_data, ) ubersmith_api = api.init(self.url, self.username, self.password) assert_that(calling(ubersmith_api.support.ticket_submit.http_post), raises(UbersmithException))
def test_api_http_post_method_result_200(self, request_mock): json_data = { 'data': '778', 'error_code': None, 'error_message': '', 'status': True } self.expect_a_ubersmith_call_post( request_mock, response_body=json_data, ) ubersmith_api = api.init(self.url, self.username, self.password) response = ubersmith_api.support.ticket_submit.http_post(body='ticket body', subject='ticket subject') assert_that(response, equal_to(json_data.get('data')))
def test_api_raises_exception_for_invalid_status_code(self, request_mock): method = "client.list" ubersmith_api = api.init(self.url, self.username, self.password) self.expect_a_ubersmith_call(request_mock, method=method, status_code=400) assert_that(calling(ubersmith_api.client.list), raises(BadRequest)) self.expect_a_ubersmith_call(request_mock, method=method, status_code=401) assert_that(calling(ubersmith_api.client.list), raises(Unauthorized)) self.expect_a_ubersmith_call(request_mock, method=method, status_code=403) assert_that(calling(ubersmith_api.client.list), raises(Forbidden)) self.expect_a_ubersmith_call(request_mock, method=method, status_code=404) assert_that(calling(ubersmith_api.client.list), raises(NotFound)) self.expect_a_ubersmith_call(request_mock, method=method, status_code=500) assert_that(calling(ubersmith_api.client.list), raises(UnknownError))