Exemplo n.º 1
0
def test_cancelling_running_job():
    mock_client = MagicMock()
    mock_client.post.return_value = {
        'prevstate': 'running',
    }
    api = ScrapydAPI(HOST_URL, client=mock_client)
    rtn = api.cancel(PROJECT, JOB)
    assert rtn is 'running'
    mock_client.post.assert_called_with('http://localhost/cancel.json',
                                        data={
                                            'project': PROJECT,
                                            'job': JOB
                                        })
Exemplo n.º 2
0
def test_cancelling_pending_job():
    mock_client = MagicMock()
    mock_client.post.return_value = {
        'prevstate': 'pending',
    }
    api = ScrapydAPI(HOST_URL, client=mock_client)
    rtn = api.cancel(PROJECT, JOB)
    assert rtn is 'pending'
    mock_client.post.assert_called_with(
        'http://localhost/cancel.json',
        data={
            'project': PROJECT,
            'job': JOB
        }
    )
Exemplo n.º 3
0
def test_cancelling_with_specific_signal():
    mock_client = MagicMock()
    mock_client.post.return_value = {
        'prevstate': 'running',
    }
    api = ScrapydAPI(HOST_URL, client=mock_client)
    rtn = api.cancel(PROJECT, JOB, signal='TERM')
    assert rtn is 'running'
    mock_client.post.assert_called_with(
        'http://localhost/cancel.json',
        data={
            'project': PROJECT,
            'job': JOB,
            'signal': 'TERM'
        }
    )
Exemplo n.º 4
0
def test_cancelling_with_specific_signal():
    mock_client = MagicMock()
    mock_client.post.return_value = {
        'prevstate': 'running',
    }
    api = ScrapydAPI(HOST_URL, client=mock_client)
    rtn = api.cancel(PROJECT, JOB, signal='TERM')
    assert rtn is 'running'
    mock_client.post.assert_called_with(
        'http://localhost/cancel.json',
        data={
            'project': PROJECT,
            'job': JOB,
            'signal': 'TERM'
        },
        timeout=None
    )
Exemplo n.º 5
0
def test_cancel():
    """
    Test the method which handles cancelling a spider job.
    """
    mock_client = MagicMock()
    mock_client.post.return_value = {
        'prevstate': 'running',
    }
    api = ScrapydAPI(HOST_URL, client=mock_client)
    rtn = api.cancel(PROJECT, JOB)
    assert rtn is True
    mock_client.post.assert_called_with(
        'http://localhost/cancel.json',
        data={
            'project': PROJECT,
            'job': JOB
        }
    )