示例#1
0
def test_build_batou_fresh_install(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir), 'hg-pull')
    remote_core.cmd.reset_mock()
    remote_core.build_batou('.', 'asdf')
    calls = iter([x[1][0] for x in remote_core.cmd.mock_calls])
    assert remote_core.cmd.call_count == 1
    assert next(calls) == './batou --help'
示例#2
0
def test_hg_bundle_shipping(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir) + "/foo", "hg-bundle")
    remote_core.cmd.side_effect = [
        ("41fea38ce5d3", None),
        (
            """\
changeset: 371:revision-a
summary:fdsa

changeset: 372:revision-b
""",
            None,
        ),
        ("", ""),
        ("", ""),
        ("", ""),
    ]
    heads = remote_core.hg_current_heads()
    assert heads == ["revision-a", "revision-b"]
    remote_core.hg_unbundle_code()
    remote_core.hg_update_working_copy("default")

    assert remote_core.cmd.call_count == 6
    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls) == "hg init {}".format(remote_core.target_directory)
    assert next(calls) == "hg id -i"
    assert next(calls) == "hg heads"
    assert next(calls) == "hg -y unbundle batou-bundle.hg"
    assert next(calls) == "hg up -C default"
    assert next(calls) == "hg id -i"
示例#3
0
def test_build_batou_virtualenv_exists(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir), 'hg-pull')
    os.mkdir(remote_core.target_directory + '/bin')
    open(remote_core.target_directory + '/bin/python3', 'w')
    remote_core.build_batou('.', 'asdf')
    calls = iter([x[1][0] for x in remote_core.cmd.mock_calls])
    assert remote_core.cmd.call_count == 2
    next(calls)  # skip ensure_repository
    assert next(calls) == './batou --help'
示例#4
0
def test_update_code_new_target(mock_remote_core, tmpdir):
    remote_core.cmd.side_effect = [('', ''), ('', ''), ('', ''), ('', '')]
    remote_core.ensure_repository(str(tmpdir) + '/foo', 'hg-bundle')
    remote_core.hg_pull_code('http://bitbucket.org/flyingcircus/batou')
    remote_core.hg_update_working_copy('default')

    assert remote_core.cmd.call_count == 4
    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls) == 'hg init {}'.format(remote_core.target_directory)
    assert next(calls) == 'hg pull http://bitbucket.org/flyingcircus/batou'
    assert next(calls) == 'hg up -C default'
    assert next(calls) == 'hg id -i'
示例#5
0
def test_update_code_new_target(mock_remote_core, tmpdir):
    remote_core.cmd.side_effect = [("", ""), ("", ""), ("", ""), ("", "")]
    remote_core.ensure_repository(str(tmpdir) + "/foo", "hg-bundle")
    remote_core.hg_pull_code("http://bitbucket.org/flyingcircus/batou")
    remote_core.hg_update_working_copy("default")

    assert remote_core.cmd.call_count == 4
    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls) == "hg init {}".format(remote_core.target_directory)
    assert next(calls) == "hg pull http://bitbucket.org/flyingcircus/batou"
    assert next(calls) == "hg up -C default"
    assert next(calls) == "hg id -i"
示例#6
0
def test_build_batou_virtualenv_exists(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir), "hg-pull")
    remote_core.ensure_base("asdf")
    os.mkdir(remote_core.target_directory + "/bin")
    with open(remote_core.target_directory + "/bin/python3", "w") as f:
        # Break python
        pass
    remote_core.build_batou()
    calls = iter([x[1][0] for x in remote_core.cmd.mock_calls])
    assert remote_core.cmd.call_count == 2
    next(calls)  # skip ensure_repository
    assert next(calls) == "./batou --help"
示例#7
0
def test_update_code_existing_target(mock_remote_core, tmpdir):
    remote_core.cmd.side_effect = [('', ''), ('', ''), ('', ''), ('', '')]

    remote_core.ensure_repository(str(tmpdir), 'hg-pull')
    remote_core.hg_pull_code('http://bitbucket.org/flyingcircus/batou')
    remote_core.hg_update_working_copy('default')

    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls).startswith('hg init /')
    assert next(calls) == 'hg pull http://bitbucket.org/flyingcircus/batou'
    assert next(calls) == 'hg up -C default'
    assert next(calls) == 'hg id -i'
    assert remote_core.cmd.call_count == 4
示例#8
0
def test_update_code_existing_target(mock_remote_core, tmpdir):
    remote_core.cmd.side_effect = [("", ""), ("", ""), ("", ""), ("", "")]

    remote_core.ensure_repository(str(tmpdir), "hg-pull")
    remote_core.hg_pull_code("http://bitbucket.org/flyingcircus/batou")
    remote_core.hg_update_working_copy("default")

    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls).startswith("hg init /")
    assert next(calls) == "hg pull http://bitbucket.org/flyingcircus/batou"
    assert next(calls) == "hg up -C default"
    assert next(calls) == "hg id -i"
    assert remote_core.cmd.call_count == 4
示例#9
0
def test_git_remote_init_pull(tmpdir):
    source = tmpdir.mkdir('source')
    dest = tmpdir.mkdir('dest')
    with source.as_cwd():
        remote_core.cmd('git init')
        source.join('foo.txt').write('bar')
        remote_core.cmd('git add foo.txt')
        remote_core.cmd('git commit -m bar')

        remote_core.ensure_repository(str(dest), 'git-bundle')
        remote_core.git_pull_code(str(source), 'master')
        remote_core.git_update_working_copy('master')

    assert 'bar' == dest.join('foo.txt').read()
示例#10
0
def test_git_remote_init_pull(tmpdir):
    source = tmpdir.mkdir("source")
    dest = tmpdir.mkdir("dest")
    with source.as_cwd():
        remote_core.cmd("git init")
        source.join("foo.txt").write("bar")
        remote_core.cmd("git add foo.txt")
        remote_core.cmd("git commit -m bar")

        remote_core.ensure_repository(str(dest), "git-bundle")
        remote_core.git_pull_code(str(source), "master")
        remote_core.git_update_working_copy("master")

    assert "bar" == dest.join("foo.txt").read()
示例#11
0
def test_hg_bundle_shipping(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir) + '/foo', 'hg-bundle')
    remote_core.cmd.side_effect = [("41fea38ce5d3", None),
                                   ("""\
changeset: 371:revision-a
summary:fdsa

changeset: 372:revision-b
""", None), ('', ''), ('', ''), ('', '')]
    heads = remote_core.hg_current_heads()
    assert heads == ['revision-a', 'revision-b']
    remote_core.hg_unbundle_code()
    remote_core.hg_update_working_copy('default')

    assert remote_core.cmd.call_count == 6
    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls) == 'hg init {}'.format(remote_core.target_directory)
    assert next(calls) == 'hg id -i'
    assert next(calls) == 'hg heads'
    assert next(calls) == 'hg -y unbundle batou-bundle.hg'
    assert next(calls) == 'hg up -C default'
    assert next(calls) == 'hg id -i'
示例#12
0
def test_hg_bundle_shipping(mock_remote_core, tmpdir):
    remote_core.ensure_repository(str(tmpdir) + "/foo", "hg-bundle")
    remote_core.cmd.side_effect = [
        (b'[{"id": "41fea38ce5d3"}]', None),
        (b'[{"node": "revision-a"},{"node": "revision-b"}]', None),
        (b"", b""),
        (b"", b""),
        (b'[{"id": "revision-b"}]', b""),
    ]
    heads = remote_core.hg_current_heads()
    assert heads == ["revision-a", "revision-b"]
    remote_core.hg_unbundle_code()
    assert remote_core.hg_update_working_copy("default") == "revision-b"

    assert remote_core.cmd.call_count == 6
    calls = iter(x[1][0] for x in remote_core.cmd.mock_calls)
    assert next(calls) == "hg init {}".format(remote_core.target_directory)
    assert next(calls) == "hg id -Tjson"
    assert next(calls) == "hg heads -Tjson"
    assert next(calls) == "hg -y unbundle batou-bundle.hg"
    assert next(calls) == "hg up -C default"
    assert next(calls) == "hg id -Tjson"
示例#13
0
def test_expand_deployment_base(tmpdir):
    with mock.patch('os.path.expanduser') as expanduser:
        expanduser.return_value = str(tmpdir)
        remote_core.ensure_repository('~/deployment', 'rsync')
    assert (remote_core.target_directory == str(tmpdir))
示例#14
0
def test_expand_deployment_base(tmpdir):
    with mock.patch("os.path.expanduser") as expanduser:
        expanduser.return_value = str(tmpdir)
        remote_core.ensure_repository("~/deployment", "rsync")
    assert remote_core.target_directory == str(tmpdir)