コード例 #1
0
class ApiCallerPayloadUnitTest(unittest.TestCase):
    def setUp(self):
        configuration = Configuration(**dict(ApiEndpoint=API_ENDPOINT))
        self.api_caller = ApiCaller(configuration)

    def test_payload_given(self):
        params, kwargs = self.api_caller._build_request(RESOURCE, payload=PAYLOAD)
        self.assertIn("data", kwargs)
        self.assertEqual(kwargs["data"], json.dumps(PAYLOAD))

    def test_payload_not_given(self):
        params, kwargs = self.api_caller._build_request(RESOURCE)
        self.assertNotIn("data", kwargs)
コード例 #2
0
    def _check_endpoint_connection(cls, can_run, configuration):
        if can_run:
            service_root = ApiCaller(configuration)
            link, kwargs = service_root._build_request(
                configuration.ApiEndpoint)
            url = link.link[:link.link.rfind("/") + 1] + "redfish/v1"

            response, status_code = service_root._do_request(
                kwargs, url, "Get")
            if status_code in range(400, 600):
                cts_error("{url:id} Get failed. Status code: {code}",
                          url=url,
                          code=status_code)
                try:
                    cts_error(
                        '{code} : {description}. Please check your configuration.',
                        code=status_code,
                        description=ErrorReturnCodes.ErrorCodes[status_code])
                except KeyError:
                    pass
                return False
            else:
                return True
        else:
            return False