コード例 #1
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_file_non_exists_from_remote(mocked_get_branches, mocked_pre_load,
                                          mocked_session, branches,
                                          files_branch_map):
    mocked_get_branches.return_value = branches
    mocked_pre_load.return_value = files_branch_map

    with pytest.raises(ValueError):
        ubi.get_loader().load("non-exists.yaml")
コード例 #2
0
def test_get_empty_branches(mocked_session):
    mocked_session.return_value.get.return_value.json.return_value = {}
    exception = RuntimeError(
        ('Please check https://contentdelivery.com/ubi/data '
         'is in right format'))
    try:
        ubi.get_loader()
        raise AssertionError('test should fail!')
    except RuntimeError as actual_exception:
        assert actual_exception.args == exception.args
コード例 #3
0
def test_default_or_local_repo_not_set():
    try:
        ubi.DEFAULT_UBI_REPO = ''

        expected_error = (
            'Please either set a source or define DEFAULT_UBI_REPO '
            'in your environment')

        with pytest.raises(ubi.LoaderError) as exc:
            ubi.get_loader()

        assert str(exc.value) == expected_error

    finally:
        ubi.DEFAULT_UBI_REPO = 'https://contentdelivery.com/ubi/data'
コード例 #4
0
def test_get_branches(mocked_session):
    branches = [{
        'name': 'dnf7',
        'commit': {
            'id': 'c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f'
        }
    }, {
        'name': 'ubi7',
        'commit': {
            'id': '2189cbc2e447f796fe354f8d784d76b0a2620248'
        }
    }]
    headers = {
        'Content-Length': '629',
        'X-Total-Pages': '1',
        'X-Per-Page': '20'
    }
    mocked_session.return_value.get.return_value.headers = headers
    mocked_session.return_value.get.return_value.json.return_value = branches
    loader = ubi.get_loader()
    actual_branches = loader._get_branches()
    assert actual_branches == [
        'c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f',
        '2189cbc2e447f796fe354f8d784d76b0a2620248'
    ]
コード例 #5
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_get_branches(mocked_session, branches):
    remote_branches = [
        {
            "name": "ubi7",
            "commit": {
                "id": "c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f"
            }
        },
        {
            "name": "ubi7.1",
            "commit": {
                "id": "2189cbc2e447f796fe354f8d784d76b0a2620248"
            },
        },
        {
            "name": "ubi8",
            "commit": {
                "id": "26d24af7859df3c4d361bd33cd57984d03abe206"
            }
        },
    ]
    headers = {
        "Content-Length": "629",
        "X-Total-Pages": "1",
        "X-Per-Page": "20"
    }
    mocked_session.return_value.get.return_value.headers = headers
    mocked_session.return_value.get.return_value.json.return_value = remote_branches
    loader = ubi.get_loader()
    actual_branches_sha1 = loader._get_branches()
    assert actual_branches_sha1 == branches
コード例 #6
0
def test_pre_load(mocked_get_branches, mocked_session, files_branch_map):
    branches = [
        'c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f',
        '2189cbc2e447f796fe354f8d784d76b0a2620248'
    ]
    mocked_get_branches.return_value = branches
    headers = {
        'Content-Length': '629',
        'X-Total-Pages': '1',
        'X-Per-Page': '20'
    }
    mocked_session.return_value.get.return_value.headers = headers
    file_list = [[{
        'name': 'rhel-atomic-host.yaml',
        'path': 'rhel-atomic-host.yaml'
    }, {
        'name': 'README.md',
        'path': 'README.md'
    }],
                 [{
                     'name': 'rhel-7-for-power-le.yaml',
                     'path': 'rhel-7-for-power-le.yaml'
                 }]]
    mocked_session.return_value.get.return_value.json.side_effect = file_list
    loader = ubi.get_loader()
    expected_map = files_branch_map
    actual_files_branch_map = loader._files_branch_map
    assert expected_map == actual_files_branch_map
コード例 #7
0
def test_syntax_error_from_config_file():
    loader = ubi.get_loader(TEST_DATA_DIR)
    try:
        loader.load('bad_configs/syntax_error.yaml')
        raise AssertionError('load should fail!')
    except yaml.YAMLError as e:
        assert e.problem == "expected <block end>, but found '?'"
コード例 #8
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_all_from_local():
    repo = os.path.join(TEST_DATA_DIR, "configs/ubi7.1")
    loader = ubi.get_loader(repo)
    configs = loader.load_all()
    assert len(configs) == 2
    assert configs[0].version == "7.1"
    assert isinstance(configs[0], UbiConfig)
コード例 #9
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_from_local():
    path = os.path.join(TEST_DATA_DIR, "configs/ubi7.1")
    loader = ubi.get_loader(path)
    # loads relative to given path
    config = loader.load("rhel-atomic-host.yaml")
    assert isinstance(config, UbiConfig)
    assert config.version == "7.1"
コード例 #10
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_all_with_error_config(
    mocked_get_branches,
    mocked_pre_load,
    mocked_session,
    branches,
    ubi7_1_config_file1,
    ubi7_1_config_file2,
    ubi7_config_file,
    ubi8_config_file,
    invalid_config_file,
    syntax_error_file,
    response,
    files_branch_map_with_error_config_file,
):
    mocked_get_branches.return_value = branches
    mocked_pre_load.return_value = files_branch_map_with_error_config_file
    mocked_session.return_value.get.side_effect = [
        response(ubi7_1_config_file1),
        response(ubi8_config_file),
        response(ubi7_1_config_file2),
        response(ubi7_config_file),
        response(invalid_config_file),
        response(syntax_error_file),
    ]

    loader = ubi.get_loader()
    configs = loader.load_all()
    assert mocked_session.return_value.get.call_count == 6
    assert len(configs) == 4
コード例 #11
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_all_from_default_repo(
    mocked_get_branches,
    mocked_pre_load,
    mocked_session,
    branches,
    files_branch_map,
    ubi7_1_config_file1,
    ubi7_1_config_file2,
    ubi7_config_file,
    ubi8_config_file,
    response,
):
    mocked_get_branches.return_value = branches
    mocked_pre_load.return_value = files_branch_map
    mocked_session.return_value.get.side_effect = [
        response(ubi7_1_config_file1),
        response(ubi8_config_file),
        response(ubi7_1_config_file2),
        response(ubi7_config_file),
    ]
    loader = ubi.get_loader()
    configs = loader.load_all()
    configs = sorted(configs, key=repr)
    assert len(configs) == 4
    assert isinstance(configs[0], UbiConfig)
    assert str(configs[1]) == "rhel-7-server.yaml"
    assert configs[1].version == "7"
コード例 #12
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_from_nonyaml(tmpdir):
    somefile = tmpdir.mkdir("ubi7").join("some-file.txt")
    somefile.write("[oops, this is not valid yaml")

    loader = ubi.get_loader(str(tmpdir))

    with pytest.raises(yaml.YAMLError):
        loader.load("ubi7/some-file.txt")
コード例 #13
0
def test_load_from_nonyaml(tmpdir):
    somefile = tmpdir.join('some-file.txt')
    somefile.write('[oops, this is not valid yaml')

    loader = ubi.get_loader(str(tmpdir))

    with pytest.raises(yaml.YAMLError):
        loader.load('some-file.txt')
コード例 #14
0
def test_load_from_nonyaml(tmpdir):
    somefile = tmpdir.join('some-file.txt')
    somefile.write('[oops, this is not valid yaml')

    loader = ubi.get_loader(str(tmpdir))

    # The exception from failing to load this file should be propagated
    with pytest.raises(yaml.YAMLError):
        loader.load('some-file.txt')
コード例 #15
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_all_from_local_recursive():
    repo = os.path.join(TEST_DATA_DIR, "configs")
    loader = ubi.get_loader(repo)
    configs = loader.load_all()
    assert len(configs) == 4
    assert isinstance(configs[0], UbiConfig)
    for conf in configs:
        # version should be populated
        assert hasattr(conf, "version")
        if conf.file_name == "rhel-8-for-power-le.yaml":
            # it's under ubi8 directory, version should be 8
            assert conf.version == "8"
コード例 #16
0
def test_load_all_from_default_repo(mocked_pre_load, mocked_session,
                                    files_branch_map, dnf7_config_file,
                                    ubi7_config_file, response):
    mocked_pre_load.return_value = files_branch_map
    mocked_session.return_value.get.side_effect = [
        response(dnf7_config_file),
        response(ubi7_config_file)
    ]
    loader = ubi.get_loader()
    configs = loader.load_all()
    configs = sorted(configs, key=repr)
    assert len(configs) == 2
    assert isinstance(configs[0], UbiConfig)
    assert str(configs[1]) == 'rhel-atomic-host.yaml'
コード例 #17
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_file_without_providing_version(
    mocked_get_branches,
    mocked_pre_load,
    mocked_session,
    branches,
    files_branch_map,
    ubi7_config_file,
    response,
):

    mocked_get_branches.return_value = branches
    mocked_pre_load.return_value = files_branch_map
    mocked_session.return_value.get.side_effect = [response(ubi7_config_file)]

    loader = ubi.get_loader()
    config = loader.load("rhel-7-server.yaml")

    assert config.version == "7"
コード例 #18
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_file_with_non_exists_version(
    mocked_get_branches,
    mocked_pre_load,
    mocked_session,
    branches,
    files_branch_map,
    ubi8_config_file,
    response,
):

    mocked_get_branches.return_value = branches
    mocked_pre_load.return_value = files_branch_map
    mocked_session.return_value.get.side_effect = [response(ubi8_config_file)]

    loader = ubi.get_loader()
    config = loader.load("rhel-8-for-power-le.yaml", "ubi8.20")

    assert config.version == "8"
コード例 #19
0
def test_get_branches(mocked_session):
    branches = [{
        'name': 'dnf7',
        'commit': {
            'id': 'c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f'
        }
    }, {
        'name': 'ubi7',
        'commit': {
            'id': '2189cbc2e447f796fe354f8d784d76b0a2620248'
        }
    }]
    mocked_session.return_value.get.return_value.json.return_value = branches
    loader = ubi.get_loader()
    actual_branches = loader._get_branches()
    assert actual_branches == [
        'c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f',
        '2189cbc2e447f796fe354f8d784d76b0a2620248'
    ]
コード例 #20
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_pre_load(mocked_get_branches, mocked_session, files_branch_map):
    branch_sha1 = OrderedDict([
        ("ubi7.1", "2189cbc2e447f796fe354f8d784d76b0a2620248"),
        ("ubi7", "c99cb8d7dae2e78e8cc7e720d3f950d1c5a0b51f"),
        ("ubi8", "26d24af7859df3c4d361bd33cd57984d03abe206"),
    ])
    mocked_get_branches.return_value = branch_sha1
    headers = {
        "Content-Length": "629",
        "X-Total-Pages": "1",
        "X-Per-Page": "20"
    }
    mocked_session.return_value.get.return_value.headers = headers
    file_list = [
        [
            {
                "name": "rhel-7-server.yaml",
                "path": "rhel-7-server.yaml"
            },
            {
                "name": "rhel-atomic-host.yaml",
                "path": "rhel-atomic-host.yaml"
            },
            {
                "name": "README.md",
                "path": "README.md"
            },
        ],
        [{
            "name": "rhel-7-server.yaml",
            "path": "rhel-7-server.yaml"
        }],
        [{
            "name": "rhel-8-for-power-le.yaml",
            "path": "rhel-8-for-power-le.yaml"
        }],
    ]
    mocked_session.return_value.get.return_value.json.side_effect = file_list
    loader = ubi.get_loader()
    expected_map = files_branch_map
    actual_files_branch_map = loader._files_branch_map
    assert expected_map == actual_files_branch_map
コード例 #21
0
def test_load_from_local():
    loader = ubi.get_loader(TEST_DATA_DIR)
    # loads relative to given path
    config = loader.load('configs/dnf7/rhel-atomic-host.yaml')
    assert isinstance(config, UbiConfig)
コード例 #22
0
ファイル: test_ubi.py プロジェクト: JayZ12138/ubi-config
def test_load_from_directory_not_named_after_ubi():
    with patch("os.path.isdir"):
        loader = ubi.get_loader("./ubi7.1a")
        with pytest.raises(ValueError):
            config = loader.load("file")
コード例 #23
0
def test_get_loader_notexist(tmpdir):
    with pytest.raises(ubi.LoaderError) as exc:
        ubi.get_loader(str(tmpdir.join("not-exist-dir")))

    assert 'not an existing directory' in str(exc.value)
コード例 #24
0
def test_load_all_from_local_with_error_configs():
    loader = ubi.get_loader(TEST_DATA_DIR)
    configs = loader.load_all(recursive=True)

    assert len(configs) == 2
コード例 #25
0
def test_load_from_local_decimal_integrity():
    loader = ubi.get_loader(TEST_DATA_DIR)
    config = loader.load('configs/dnf7/rhel-atomic-host.yaml')
    assert config.modules.whitelist[2].stream == '1.10'
コード例 #26
0
def test_load_all_from_local():
    repo = os.path.join(TEST_DATA_DIR, 'configs/dnf7')
    loader = ubi.get_loader(repo)
    configs = loader.load_all()
    assert len(configs) == 1
    assert isinstance(configs[0], UbiConfig)
コード例 #27
0
def test_load_all_from_local_recursive():
    repo = os.path.join(TEST_DATA_DIR, 'configs')
    loader = ubi.get_loader(repo)
    configs = loader.load_all(recursive=True)
    assert len(configs) == 2
    assert isinstance(configs[0], UbiConfig)
コード例 #28
0
def test_load_local_failed_validation():
    loader = ubi.get_loader(TEST_DATA_DIR)

    with pytest.raises(ValidationError):
        loader.load('bad_configs/invalid_config.yaml')