

@pytest.mark.parametrize('webhooks,config_file', [(False, 'simple'), (True, 'webhooks')])
def test_basic(tmpdir, webhooks, config_file):
    tmpdir = str(tmpdir)
    config_file = os.path.join(test_path, config_file)
    with mock.patch('squadron.main.get_squadron_dir') as dirmock:
        dirmock.return_value = tmpdir
        with mock.patch('squadron.daemon.Repo') as gitmock:
            git = mock.MagicMock()
            git.checkout.return_value = 0
            git.pull.return_value = 0
            repo = mock.MagicMock()
            repo.git.return_value = git
            gitmock.return_value = repo
            with mock.patch('squadron.notify.server.get_server') as getservermock:
                threadmock = mock.MagicMock()
                servermock = mock.MagicMock()
                getservermock.return_value = (threadmock, servermock)
                with mock.patch('squadron.main.go') as mainmock:
                    node_name = 'test'
                    exit_loop = threading.Event()
                    timer = threading.Timer(2, (lambda : exit_loop.set()))
                    timer.start()
                    daemon.daemonize(tmpdir, config_file, 3, 'blank', node_name, exit_loop)
                    mainmock.assert_called_with(tmpdir, node_name=node_name, config_file=config_file, dry_run=False, dont_rollback=True)
                if webhooks:
                    assert getservermock.called
                    assert servermock.stop.called
                    assert threadmock.join.called
            assert git.checkout.called_with('master')
            assert git.pull.called_with('--rebase')
        assert dirmock.called

dataset/ETHPy150Open gosquadron/squadron/tests/test_daemon.py test_basic/original