def test_delete_old_few(ftp_root, ftp_server, work_dir):
    """Test if to few files are not deleted."""

    # create file to upload
    work_dir.join('filename-0.0.4.tgz').write(CONTENT)
    make_files(ftp_root, ['filename-0.0.3.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {
        'keep_versions': 3
    }

    result = cmd('out', source, [str(work_dir)], params=params)

    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join('filename-0.0.3.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.4.tgz').read() == CONTENT

    assert result == {
        "version": {"version": "0.0.4"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.4.tgz"},
        ]
    }
def test_delete_old_few(ftp_root, ftp_server, work_dir):
    """Test if to few files are not deleted."""

    # create file to upload
    work_dir.join('filename-0.0.4.tgz').write(CONTENT)
    make_files(ftp_root, ['filename-0.0.3.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {'keep_versions': 3}

    result = cmd('out', source, [str(work_dir)], params=params)

    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.3.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.4.tgz').read() == CONTENT

    assert result == {
        "version": {
            "version": "0.0.4"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.4.tgz"
            },
        ]
    }
Example #3
0
def test_check_no_new_version(ftp_root, ftp_server):
    """When passing a version an no newer files return nothing."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert result == []
Example #4
0
def test_check_multiple_files(ftp_root, ftp_server):
    """Test if multiple uploaded file return more versions."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.1"}], 'should only return most recent version'
Example #5
0
def test_check_one_file(ftp_root, ftp_server):
    """Test if one uploaded file returns one version."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.0"}]
Example #6
0
def test_semver(ftp_root, ftp_server):
    """Test if semver versions don't break."""

    make_files(ftp_root, ['filename-1.0.0-rc.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "1.0.0-rc.1"}]
def test_check_no_new_version(ftp_root, ftp_server):
    """When passing a version an no newer files return nothing."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert result == []
def test_check_one_file(ftp_root, ftp_server):
    """Test if one uploaded file returns one version."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.0"}]
def test_check_multiple_files(ftp_root, ftp_server):
    """Test if multiple uploaded file return more versions."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.1"}], 'should only return most recent version'
def test_delete_old_sorting(ftp_root, ftp_server, work_dir):
    """Test if natural sorting is used when deleting."""

    # create file to upload
    work_dir.join('filename-0.0.14.tgz').write(CONTENT)
    make_files(ftp_root, [
        'filename-0.0.0.tgz',
        'filename-0.0.1.tgz',
        'filename-0.0.2.tgz',
        'filename-0.0.3.tgz',
        'filename-0.0.10.tgz',
        'filename-0.0.11.tgz',
        'filename-0.0.12.tgz',
        'filename-0.0.13.tgz',
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {'keep_versions': 3}

    result = cmd('out', source, [str(work_dir)], params=params)

    # old files should be deleted
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.0.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.1.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.2.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.3.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.10.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.11.tgz').exists()
    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.12.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.13.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.14.tgz').read() == CONTENT

    assert result == {
        "version": {
            "version": "0.0.14"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.14.tgz"
            },
        ]
    }
def test_delete_old_sorting(ftp_root, ftp_server, work_dir):
    """Test if natural sorting is used when deleting."""

    # create file to upload
    work_dir.join('filename-0.0.14.tgz').write(CONTENT)
    make_files(ftp_root, [
        'filename-0.0.0.tgz',
        'filename-0.0.1.tgz',
        'filename-0.0.2.tgz',
        'filename-0.0.3.tgz',
        'filename-0.0.10.tgz',
        'filename-0.0.11.tgz',
        'filename-0.0.12.tgz',
        'filename-0.0.13.tgz',
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {
        'keep_versions': 3
    }

    result = cmd('out', source, [str(work_dir)], params=params)

    # old files should be deleted
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.0.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.1.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.2.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.3.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.10.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.11.tgz').exists()
    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join('filename-0.0.12.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.13.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.14.tgz').read() == CONTENT

    assert result == {
        "version": {"version": "0.0.14"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.14.tgz"},
        ]
    }
Example #12
0
def test_check_passing_version(ftp_root, ftp_server):
    """Test when a version is passed only new versions are returned."""

    make_files(ftp_root, [
        'filename-0.0.0.tgz', 'filename-0.0.1.tgz', 'filename-0.0.2.tgz', 'filename-0.0.3.tgz'
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert {"version": "0.0.2"} in result, 'new version should be in result'
    assert {"version": "0.0.3"} in result, 'new version should be in result'
    assert {"version": "0.0.0"} not in result, 'older version should not be in result'
    assert {"version": "0.0.1"} not in result, 'current version should not be in result'
def test_check_passing_version(ftp_root, ftp_server):
    """Test when a version is passed only new versions are returned."""

    make_files(ftp_root, [
        'filename-0.0.0.tgz', 'filename-0.0.1.tgz', 'filename-0.0.2.tgz', 'filename-0.0.3.tgz'
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert {"version": "0.0.2"} in result, 'new version should be in result'
    assert {"version": "0.0.3"} in result, 'new version should be in result'
    assert {"version": "0.0.0"} not in result, 'older version should not be in result'
    assert {"version": "0.0.1"} not in result, 'current version should not be in result'
def test_get_a_file(ftp_root, ftp_server, work_dir):
    """Test if a file can be retrieved."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('in', source, [str(work_dir)], version={"version": "0.0.0"})

    assert work_dir.join('filename-0.0.0.tgz').read() == '123'
    assert result == {
        "version": {"version": "0.0.0"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.0.tgz"},
        ]
    }
Example #15
0
def test_get_a_file(ftp_root, ftp_server, work_dir):
    """Test if a file can be retrieved."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('in', source, [str(work_dir)], version={"version": "0.0.0"})

    assert work_dir.join('filename-0.0.0.tgz').read() == '123'
    assert result == {
        "version": {
            "version": "0.0.0"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.0.tgz"
            },
        ]
    }