Exemplo n.º 1
0
def test_fail_validate_setup_py_file(fx_copy_fn_main_mock_integration):
    """Test for failure when calling _validate_setup()"""

    mock_package_path = fx_copy_fn_main_mock_integration[1]

    mock_data = {
        "test2": {
            "fail_func": lambda x: True,
            "fail_msg": "failed",
            "severity": SDKValidateIssue.SEVERITY_LEVEL_WARN,
            "missing_msg": "missing",
            "solution": "solution",
            "parse_func":
            lambda _, attr_list: {attr: "mock_data"
                                  for attr in attr_list},
        },
        "test": {
            "fail_func": lambda x: True,
            "fail_msg": "failed",
            "severity": SDKValidateIssue.SEVERITY_LEVEL_CRITICAL,
            "missing_msg": "missing",
            "solution": "solution",
            "parse_func":
            lambda _, attr_list: {attr: "mock_data"
                                  for attr in attr_list},
        },
        "test3": {
            "fail_func": lambda x: True,
            "fail_msg": "failed",
            "severity": SDKValidateIssue.SEVERITY_LEVEL_INFO,
            "missing_msg": "missing",
            "solution": "solution",
            "parse_func":
            lambda _, attr_list: {attr: "mock_data"
                                  for attr in attr_list},
        }
    }

    with patch.dict(
            "resilient_sdk.cmds.validate.validation_configurations.setup_py_attributes",
            mock_data,
            clear=True):
        results = CmdValidate._validate_setup(mock_package_path)

        assert not results[0]
        assert len(results) == 2
        assert len(results[1]) == 3
        # note the returned values in results[1] are sorted so the levels should be in order of severity
        assert results[1][
            0].severity == SDKValidateIssue.SEVERITY_LEVEL_CRITICAL
        assert results[1][1].severity == SDKValidateIssue.SEVERITY_LEVEL_WARN
        assert results[1][2].severity == SDKValidateIssue.SEVERITY_LEVEL_INFO
Exemplo n.º 2
0
def test_pass_validate_setup_py_file(fx_copy_fn_main_mock_integration):
    """Test for success when calling _validate_setup()"""

    mock_package_path = fx_copy_fn_main_mock_integration[1]

    mock_data = {
        "test": {
            "fail_func": lambda x: False,
            "parse_func":
            lambda _, attr_list: {attr: "mock_data"
                                  for attr in attr_list},
        }
    }

    with patch.dict(
            "resilient_sdk.cmds.validate.validation_configurations.setup_py_attributes",
            mock_data,
            clear=True):
        results = CmdValidate._validate_setup(mock_package_path)

        assert results[0]
        assert len(results) == 2
        assert len(results[1]) == 1
        assert results[1][0].severity == SDKValidateIssue.SEVERITY_LEVEL_DEBUG