예제 #1
0
def test_box_metadata_download_url(url, expected):
    if expected:
        BoxMetadata(url)

    else:
        with pytest.raises(BoxMetadataException):
            BoxMetadata(url)
예제 #2
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]
예제 #3
0
def test_box_metadata_file_read_error(tmpdir):
    json_text = "{"
    temp_file = tmpdir.join("metadata.json")
    temp_file.write(json_text)

    file_url = 'file://{}'.format(str(temp_file))
    with pytest.raises(BoxMetadataException):
        BoxMetadata(file_url)
예제 #4
0
def test_box_metadata_file_read_write(vagrant_box_metadata):
    file_name, expected = vagrant_box_metadata
    input_file_url = 'file://{}'.format(file_name)
    if expected:
        input_metadata = BoxMetadata(input_file_url)
        assert input_metadata.name
        assert isinstance(input_metadata.versions, list)

        file_path = os.path.dirname(file_name)
        output_file_name = os.path.join(file_path, 'output.json')
        input_metadata.write(output_file_name)

        with open(file_name, 'r') as input_file_object:
            input_data = json.load(input_file_object)

        with open(output_file_name, 'r') as output_file_object:
            output_data = json.load(output_file_object)

        assert input_data == output_data

    else:
        with pytest.raises(BoxMetadataException):
            BoxMetadata(input_file_url)
예제 #5
0
def test_box_metadata_get_provider(provider_name, provider_list, expected_info, expected_list):
    provider_new = BoxMetadata._get_provider(provider_name, provider_list)
    assert provider_new == expected_info
    assert provider_list == expected_list
예제 #6
0
def test_box_metadata_create():
    BoxMetadata(name = 'test')
예제 #7
0
def test_box_metadata_url_error(url):
    with pytest.raises(BoxMetadataException):
        BoxMetadata(url)
예제 #8
0
def test_box_metadata_file_write_error():
    metadata = BoxMetadata(name = 'test')
    with pytest.raises(BoxMetadataException):
        metadata.write('/path/does/not/exist/metadata.json')