Exemple #1
0
def test_yaml_schema_error():
    """[System config reader] Yaml schema error"""

    config = """
    random_key:
      and_again: 2
    """

    with pytest.raises(exceptions.InvalidSystemConfigFile):
        systemconfigreader.read(config)
Exemple #2
0
def test_yaml_parser_error():

    config = """
    random_key:
    <HTML TAG>
        Ramon ind
      and_again: 2
    """

    with pytest.raises(exceptions.InvalidSystemConfigFile):
        systemconfigreader.read(config)
Exemple #3
0
def test_missing_settings():

    config = f"""
    {systemconfigreader.NAME}: "{SYSTEM_NAME}"

    {systemconfigreader.REQUIREMENTS}:
      {systemconfigreader.SETTINGS}:
        -setting_name

    {systemconfigreader.FEEDS}:
      {FEED_ID}:
        http:
          url: "{{setting_name}}"
        parser:
          built_in: GTFS_STATIC
    """

    with pytest.raises(exceptions.InvalidSystemConfigFile):
        systemconfigreader.read(config)
Exemple #4
0
def _install_system_configuration(system_update_pk):
    system_update = systemqueries.get_update_by_pk(system_update_pk)
    extra_settings = json.loads(system_update.config_parameters)
    system_update.config = systemconfigreader.render_template(
        system_update.config_template, extra_settings
    )
    system_config = systemconfigreader.read(system_update.config, extra_settings)
    system = system_update.system
    system.name = system_config[systemconfigreader.NAME]

    # Service maps must come first in case calculations are triggered
    # by install_required feed updates
    _save_service_map_configuration(
        system, system_config[systemconfigreader.SERVICE_MAPS]
    )
    return _save_feed_configuration(system, system_config[systemconfigreader.FEEDS])
Exemple #5
0
def test_base_case():
    """[System config reader] Base case"""

    config = f"""
    {systemconfigreader.NAME}: "{SYSTEM_NAME}"

    {systemconfigreader.FEEDS}:
      {FEED_ID}:
        http:
          url: {URL}
        parser:
          built_in: GTFS_STATIC
    """

    expected = {
        systemconfigreader.NAME: SYSTEM_NAME,
        "required_settings": [],
        "requirements": {
            "packages": [],
            "settings": []
        },
        "feeds": {
            FEED_ID: {
                "http": {
                    "url": URL,
                    "headers": {}
                },
                "parser": {
                    "built_in": models.Feed.BuiltInParser.GTFS_STATIC
                },
                "auto_update": {
                    "enabled": False,
                    "period": -1
                },
                "required_for_install": False,
            }
        },
    }

    actual = systemconfigreader.read(config)
    del actual["service_maps"]

    # assert expected["feeds"][FEED_ID] == actual["feeds"][FEED_ID]
    assert expected == actual
Exemple #6
0
def test_substitute_settings():

    config = f"""
    {systemconfigreader.NAME}: "{SYSTEM_NAME}"

    {systemconfigreader.REQUIREMENTS}:
      {systemconfigreader.SETTINGS}:
        - setting_name

    {systemconfigreader.FEEDS}:
      {FEED_ID}:
        http:
          url: "{{{{setting_name}}}}"
        parser:
          built_in: GTFS_STATIC
    """

    assert SETTING_VALUE == (systemconfigreader.read(
        systemconfigreader.render_template(config,
                                           {"setting_name": SETTING_VALUE}),
        {"setting_name": SETTING_VALUE},
    )[systemconfigreader.FEEDS][FEED_ID][systemconfigreader.HTTP][
        systemconfigreader.URL])