예제 #1
0
def test_box_metadata_version(version_str, expected):
    if expected is not None:
        assert str(parse_version(version_str)) == expected

    else:
        with pytest.raises(BoxVersionException):
            parse_version(version_str)
예제 #2
0
def test_box_inventory_installed(mock_box_list):
    if mock_box_list is None:
        return

    inventory = BoxInventory()
    for box_name, box_lookup in mock_box_list.iteritems():
        for provider in ('aws', 'virtualbox', 'unknown'):
            print('check installed: missing-box {}'.format(provider))

            assert inventory.installed('missing-box', provider) is None

            print('check installed: {} {}'.format(box_name, provider))

            result = inventory.installed(box_name, provider)
            version_list = box_lookup.get(provider, [])
            assert result == (version_list[0] if version_list else None)

            for version in (Version('0.0.0'), Version('1.0.0'), 'test', 123):
                print('check installed: {} {} {}'.format(box_name, provider, version))

                try:
                    version_val = parse_version(version)

                except BoxVersionException:
                    with pytest.raises(BoxVersionException):
                        inventory.installed(box_name, provider, version)

                else:
                    result = version_val if version_val in version_list else None
                    assert inventory.installed(box_name, provider, version) == result
예제 #3
0
def test_box_metadata_add_version(version_list, version_order, provider, url, checksum, checksum_type):
    metadata = BoxMetadata(name = 'test')
    for version_val in [parse_version(val) for val in version_list]:
        metadata.add_version(version_val, provider, url, checksum, checksum_type)

    for index, version_info in enumerate(metadata.versions):
        assert version_order[index] == str(version_info['version'])
        provider_info = {
            'name': provider,
            'url': url,
        }
        if checksum and checksum_type:
            provider_info['checksum'] = checksum
            provider_info['checksum_type'] = checksum_type

        assert version_info['providers'] == [provider_info]
예제 #4
0
def test_box_metadata_get_add_index(version, version_list, insert_expected, match_expected):
    test_version = parse_version(version)
    test_version_list = [Version(val) for val in version_list]
    insert_at, match_at = get_version_index(test_version, test_version_list)
    assert insert_at == insert_expected
    assert match_at == match_expected