Esempio n. 1
0
def validate_config():
    with open("/run_args.yaml", "r") as c:
        cfg = yaml.safe_load(c)
    validate_yaml(cfg)
Esempio n. 2
0
def test_validate_phase():
    empty = {}
    bad_folder = {"folder": 1, "config": {}}
    good_folder = {"folder": "legit", "config": {}}

    write(empty)
    with pytest.raises(
            InvalidYamlError,
            match="The folder attribute must exist and be a string"):
        validate()

    write(bad_folder)
    with pytest.raises(
            InvalidYamlError,
            match="The folder attribute must exist and be a string"):
        validate()

    bad_phase = {**good_folder, "phase": "not a phase"}
    good_phase_select = {**good_folder, "phase": "select"}
    good_phase_analyse = {**good_folder, "phase": "analyse"}
    write(bad_phase)
    with pytest.raises(InvalidYamlError,
                       match="specified a phase, you must specify a module"):
        validate()

    bad_select_module = {**good_phase_select, "module": "not a selector"}
    bad_analyse_module = {**good_phase_analyse, "module": "not an analyser"}
    good_select_module = {**good_phase_select, "module": "local"}
    write(bad_select_module)
    with pytest.raises(InvalidYamlError,
                       match="No select module named 'not a selector'"):
        validate()

    write(bad_analyse_module)
    with pytest.raises(InvalidYamlError,
                       match="No analyse module named 'not an analyser'"):
        validate()

    # the select module requires a 'source_folder' arg
    bad_local_config = {**good_select_module, "config": {}}
    bad_youtube_config = {
        **good_select_module,
        "module": "youtube",
        "config": {
            "uploaded_before": "212321"
        },
    }
    good_youtube_config = {
        **good_select_module,
        "module": "youtube",
        "config": {
            "search_term": "a search term",
            "uploaded_before": "212321",
            "uploaded_after": "212321",
        },
    }

    if os.path.exists("/mtriage/credentials/google.json"):
        write(good_select_module)
        with pytest.raises(
                InvalidYamlError,
                match=
                "config you specified does not contain all the required arguments",
        ):
            validate()

        write(bad_local_config)
        with pytest.raises(
                InvalidYamlError,
                match=
                "The config you specified does not contain all the required arguments for the 'local' selecter.",
        ):
            validate()

        write(bad_youtube_config)
        with pytest.raises(
                InvalidYamlError,
                match=
                "The config you specified does not contain all the required arguments for the 'youtube' selecter.",
        ):
            validate()

        write(good_youtube_config)
        validate()

        # should return True to indicate this is a single phase config, see 'validate_yaml' docstring for more info
        res = validate_yaml(good_youtube_config)
        assert res == True
Esempio n. 3
0
def test_config_types():
    res = validate_yaml(GOOD_ANALYSE_DICT)
    assert res == False

    res = validate_yaml(GOOD_SELECT_ANALYSE)
    assert res == False
Esempio n. 4
0
def validate():
    with open(ARGS, "r") as c:
        cfg = yaml.safe_load(c)
    validate_yaml(cfg)
Esempio n. 5
0
def test_config_types():
    validate_yaml(GOOD_ANALYSE_DICT)
    validate_yaml(GOOD_SELECT_ANALYSE)