File size: 2,877 Bytes
079c32c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import pytest
from .test_base import _HTTPErrorGenerator
from ...exception.master import MasterErrorCode, \
get_master_exception_class_by_error_code, get_master_exception_by_error, MasterSuccess, \
MasterSystemShuttingDown, MasterTaskDataInvalid, MasterSlaveTokenNotGiven, MasterSlaveTokenInvalid, \
MasterSelfTokenNotGiven, MasterSelfTokenInvalid, MasterChannelInvalid, \
MasterChannelNotGiven, MasterMasterTokenInvalid, MasterMasterTokenNotGiven
@pytest.mark.unittest
class TestInteractionExceptionMaster(_HTTPErrorGenerator):
def test_error_code(self):
assert len(MasterErrorCode.__members__) == 11
assert MasterErrorCode.SUCCESS == 0
def test_exception_class(self):
assert get_master_exception_class_by_error_code(MasterErrorCode.SUCCESS) == MasterSuccess
assert get_master_exception_class_by_error_code(
MasterErrorCode.SYSTEM_SHUTTING_DOWN
) == MasterSystemShuttingDown
assert get_master_exception_class_by_error_code(MasterErrorCode.CHANNEL_NOT_GIVEN) == MasterChannelNotGiven
assert get_master_exception_class_by_error_code(MasterErrorCode.CHANNEL_INVALID) == MasterChannelInvalid
assert get_master_exception_class_by_error_code(
MasterErrorCode.MASTER_TOKEN_NOT_GIVEN
) == MasterMasterTokenNotGiven
assert get_master_exception_class_by_error_code(
MasterErrorCode.MASTER_TOKEN_INVALID
) == MasterMasterTokenInvalid
assert get_master_exception_class_by_error_code(MasterErrorCode.SELF_TOKEN_NOT_GIVEN) == MasterSelfTokenNotGiven
assert get_master_exception_class_by_error_code(MasterErrorCode.SELF_TOKEN_INVALID) == MasterSelfTokenInvalid
assert get_master_exception_class_by_error_code(
MasterErrorCode.SLAVE_TOKEN_NOT_GIVEN
) == MasterSlaveTokenNotGiven
assert get_master_exception_class_by_error_code(MasterErrorCode.SLAVE_TOKEN_INVALID) == MasterSlaveTokenInvalid
assert get_master_exception_class_by_error_code(MasterErrorCode.TASK_DATA_INVALID) == MasterTaskDataInvalid
def test_get_master_exception_by_error(self):
err = get_master_exception_by_error(self._generate_exception(101, 'This is system shutting down.'))
assert isinstance(err, MasterSystemShuttingDown)
assert not err.success
assert err.status_code == 400
assert err.code == 101
assert err.message == 'This is system shutting down.'
assert err.data == {}
err = get_master_exception_by_error(self._generate_exception(601, 'Task data invalid.', data={'value': 233}))
assert isinstance(err, MasterTaskDataInvalid)
assert not err.success
assert err.status_code == 400
assert err.code == 601
assert err.message == 'Task data invalid.'
assert err.data == {'value': 233}
|