Beispiel #1
0
def test_clone_multiple(fx_get_sub_parser, fx_cmd_line_args_clone_prefix):
    """
    Test when calling 'clone'  with multiple objects and specifying a prefix
    the resultant export object contains the appropiate number of cloned objects
    """
    cmd_clone = CmdClone(fx_get_sub_parser)

    args = cmd_clone.parser.parse_known_args()[0]

    # When running tox tox args are picked up by the parser
    # -s tests from the tox command passes `tests/` as a script name
    # If we have script args and tests is present, remove it.
    if args.script and 'tests/' in args.script:
        args.script.remove('tests/')

    # Assert the prefix arg was passed as expected
    assert args.prefix == "v2"
    # Copy the export data so we don't modify the existing object
    new_export_data = TEST_EXPORT.copy()

    # Sanitize the export dict to remove everything non essential before clone
    for dict_key in new_export_data:
        if dict_key not in MANDATORY_KEYS and isinstance(new_export_data[dict_key], list):
            # clear the new export data, the stuff we clear isn't necessary for cloning
            new_export_data[dict_key] = []
    # Perform the cloning
    cmd_clone._clone_multiple_action_objects(
        args, new_export_data, TEST_EXPORT)

    # Assert in the new export dict that there is the same number of objects
    # as there is in the args
    assert len(new_export_data['functions']) == len(args.function)
    assert len(new_export_data['workflows']) == len(args.workflow)
    assert len(new_export_data['actions']) == len(args.rule)
def test_clone_prefix(fx_get_sub_parser, fx_cmd_line_args_clone_prefix):
    """
    Test when calling 'clone' and specifying a prefix
    the prefix is found on all the cloned objects
    """

    cmd_clone = CmdClone(fx_get_sub_parser)

    args = cmd_clone.parser.parse_known_args()[0]

    # When running tox tox args are picked up by the parser
    # -s tests from the tox command passes `tests/` as a script name
    # If we have script args and tests is present, remove it.
    if args.script and 'tests/' in args.script:
        args.script.remove('tests/')
    # Assert the prefix arg was passed as expected
    assert args.prefix == "v2"

    # Copy the export data so we don't modify the existing object
    new_export_data = TEST_EXPORT.copy()

    # Sanitize the export dict to remove everything non essential before clone
    for dict_key in new_export_data:
        if dict_key not in MANDATORY_KEYS and isinstance(
                new_export_data[dict_key], list):
            # clear the new export data, the stuff we clear isn't necessary for cloning
            new_export_data[dict_key] = []

    # Perform the cloning
    cmd_clone._clone_multiple_action_objects(args, new_export_data,
                                             TEST_EXPORT)

    # A mapping table of the org_export items and their unique identifiers
    # for each tested type, get the type name in the export and its identifier
    for obj_type, identifier in EXPORT_TYPE_MAP.items():
        # for each action onject of type obj_type
        for obj in new_export_data[obj_type]:
            # Ensure the provided prefix is found on the objects unique identifier
            assert "v2" in obj[
                identifier], "Expected the object's identifer to contain the prefix"