def test_push_gerrit_direct( monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed ): assert local_log() != remote_log() monkeypatch.chdir(str(local_repo_patch)) push_to_scm('master', gerrit_push_map, direct=True) assert local_log() == remote_log() push_to_scm('not_master', gerrit_push_map, direct=True) assert local_log() == remote_log('not_master')
def test_push_gerrit_if_not_exists(patch_exists, if_not_exists, should_check, should_push, monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed): monkeypatch.chdir(str(local_repo_patch)) assert local_log() != remote_log('refs/for/master') mock_check_pushed.set_return(patch_exists) push_to_scm('master', gerrit_push_map, if_not_exists=if_not_exists) assert mock_check_pushed.call_count <= 1 assert mock_check_pushed.called == should_check assert (local_log() == remote_log('refs/for/master')) == should_push
def test_push_gerrit(monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed): remote_log_pre = remote_log() assert local_log() != remote_log_pre monkeypatch.chdir(str(local_repo_patch)) push_to_scm('master', gerrit_push_map) assert remote_log() == remote_log_pre assert local_log() == remote_log('refs/for/master') push_to_scm('not_master', gerrit_push_map) assert remote_log() == remote_log_pre assert local_log() == remote_log('refs/for/not_master')
def test_push_gerrit_if_not_exists( patch_exists, if_not_exists, should_check, should_push, monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed ): monkeypatch.chdir(str(local_repo_patch)) assert local_log() != remote_log('refs/for/master') mock_check_pushed.set_return(patch_exists) push_to_scm('master', gerrit_push_map, if_not_exists=if_not_exists) assert mock_check_pushed.call_count <= 1 assert mock_check_pushed.called == should_check assert (local_log() == remote_log('refs/for/master')) == should_push
def test_push_gerrit( monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed ): remote_log_pre = remote_log() assert local_log() != remote_log_pre monkeypatch.chdir(str(local_repo_patch)) push_to_scm('master', gerrit_push_map) assert remote_log() == remote_log_pre assert local_log() == remote_log('refs/for/master') push_to_scm('not_master', gerrit_push_map) assert remote_log() == remote_log_pre assert local_log() == remote_log('refs/for/not_master')
def test_push_gerrit_unless_hash( monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed ): monkeypatch.chdir(str(local_repo_patch)) assert remote_log('master') == remote_log('refs/for/master') head_hash, older_hash = local_log()[0:2] push_to_scm( 'master', gerrit_push_map, unless_hash=head_hash, if_not_exists=True ) assert remote_log('master') == remote_log('refs/for/master') assert not mock_check_pushed.called push_to_scm( 'master', gerrit_push_map, unless_hash='HEAD', if_not_exists=True ) assert remote_log('master') == remote_log('refs/for/master') assert not mock_check_pushed.called push_to_scm( 'master', gerrit_push_map, unless_hash='master', if_not_exists=True ) assert remote_log('master') == remote_log('refs/for/master') assert not mock_check_pushed.called push_to_scm( 'master', gerrit_push_map, unless_hash=older_hash, if_not_exists=True ) assert local_log('master') == remote_log('refs/for/master') assert mock_check_pushed.called
def test_push_gerrit_set_ssh_key(monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed): mock_add_pkey = MagicMock() monkeypatch.setattr('scripts.pusher.add_key_to_known_hosts', mock_add_pkey) monkeypatch.chdir(str(local_repo_patch)) push_to_scm('master', gerrit_push_map) assert not mock_add_pkey.called py.path.local(gerrit_push_map).write( dedent(""" --- - ^(/.*): push_url: \\1 host_key: some_host_key """).lstrip().format()) push_to_scm('master', gerrit_push_map) assert mock_add_pkey.called assert mock_add_pkey.call_count == 1 assert mock_add_pkey.call_args == call('some_host_key')
def test_push_gerrit_set_ssh_key( monkeypatch, gerrit_push_map, local_log, remote_log, local_repo_patch, mock_check_pushed ): mock_add_pkey = MagicMock() monkeypatch.setattr( 'scripts.pusher.add_key_to_known_hosts', mock_add_pkey ) monkeypatch.chdir(str(local_repo_patch)) push_to_scm('master', gerrit_push_map) assert not mock_add_pkey.called py.path.local(gerrit_push_map).write(dedent( """ --- - ^(/.*): push_url: \\1 host_key: some_host_key """ ).lstrip().format()) push_to_scm('master', gerrit_push_map) assert mock_add_pkey.called assert mock_add_pkey.call_count == 1 assert mock_add_pkey.call_args == call('some_host_key')