示例#1
0
def test_power_command_error():
    # Test unset header error
    response = power_pb2.PowerCommandResponse()
    response.license_status = license_pb2.LicenseInfo.STATUS_VALID
    assert isinstance(_power_command_error_from_response(response),
                      UnsetStatusError)
    # Test header internal server error
    response.header.error.code = response.header.error.CODE_INTERNAL_SERVER_ERROR
    assert isinstance(_power_command_error_from_response(response),
                      InternalServerError)
    # Test header invalid request error
    response.header.error.code = response.header.error.CODE_INVALID_REQUEST
    assert isinstance(_power_command_error_from_response(response),
                      InvalidRequestError)
    # Test lease use error
    response.header.error.code = response.header.error.CODE_OK
    response.lease_use_result.status = response.lease_use_result.STATUS_INVALID_LEASE
    assert isinstance(_power_command_error_from_response(response),
                      LeaseUseError)
    # Test unset status
    response.lease_use_result.status = response.lease_use_result.STATUS_OK
    assert isinstance(_power_command_error_from_response(response),
                      UnsetStatusError)
    # Test status error
    response.status = power_pb2.STATUS_SHORE_POWER_CONNECTED
    assert isinstance(_power_command_error_from_response(response),
                      ResponseError)
    # Test unknown status
    response.status = 1337
    assert isinstance(_power_command_error_from_response(response),
                      ResponseError)
    # Test status processing
    response.status = power_pb2.STATUS_IN_PROGRESS
    assert not _power_command_error_from_response(response)
    # Test status OK
    response.status = power_pb2.STATUS_SUCCESS
    assert not _power_command_error_from_response(response)
    # Test lease error even when response status is OK.
    response.lease_use_result.status = response.lease_use_result.STATUS_INVALID_LEASE
    assert isinstance(_power_command_error_from_response(response),
                      LeaseUseError)
    # Test license error even when response status is OK.
    response.license_status = license_pb2.LicenseInfo.STATUS_NO_LICENSE
    response.lease_use_result.status = response.lease_use_result.STATUS_OK
    response.status = power_pb2.STATUS_LICENSE_ERROR
    assert isinstance(_power_command_error_from_response(response),
                      LicenseError)

    # test backwards compatibility with old clients
    response.license_status = license_pb2.LicenseInfo.STATUS_NO_LICENSE
    response.status = power_pb2.STATUS_SUCCESS
    assert not _power_command_error_from_response(response)
示例#2
0
def test_power_command_error():
    # Test unset header error
    response = power_pb2.PowerCommandResponse()
    assert isinstance(_power_command_error_from_response(response),
                      UnsetStatusError)
    # Test header internal server error
    response.header.error.code = response.header.error.CODE_INTERNAL_SERVER_ERROR
    assert isinstance(_power_command_error_from_response(response),
                      InternalServerError)
    # Test header invalid request error
    response.header.error.code = response.header.error.CODE_INVALID_REQUEST
    assert isinstance(_power_command_error_from_response(response),
                      InvalidRequestError)
    # Test no lease error
    response.header.error.code = response.header.error.CODE_OK
    assert isinstance(_power_command_error_from_response(response),
                      LeaseUseError)
    # Test lease use error
    response.lease_use_result.status = response.lease_use_result.STATUS_INVALID_LEASE
    assert isinstance(_power_command_error_from_response(response),
                      LeaseUseError)
    # Test unset status
    response.lease_use_result.status = response.lease_use_result.STATUS_OK
    assert isinstance(_power_command_error_from_response(response),
                      UnsetStatusError)
    # Test status error
    response.status = power_pb2.STATUS_SHORE_POWER_CONNECTED
    assert isinstance(_power_command_error_from_response(response),
                      ResponseError)
    # Test unknown status
    response.status = 1337
    assert isinstance(_power_command_error_from_response(response),
                      ResponseError)
    # Test status processing
    response.status = power_pb2.STATUS_IN_PROGRESS
    assert not _power_command_error_from_response(response)
    # Test status OK
    response.status = power_pb2.STATUS_SUCCESS
    assert not _power_command_error_from_response(response)
示例#3
0
 def power_command(self, request, lease=None, **kwargs):
     self.request = request
     return power_pb2.PowerCommandResponse(power_command_id=1337)