def test_receivers(app, db, sample_record_string):
    with requests_mock.Mocker() as requests_mocker:
        job_id = uuid.uuid4().hex

        requests_mocker.register_uri('POST',
                                     'http://localhost:6800/schedule.json',
                                     json={
                                         'jobid': job_id,
                                         'status': 'ok'
                                     })

        mock_record = MagicMock()
        prop_mock = PropertyMock(return_value=sample_record_string)
        type(mock_record).raw = prop_mock

        with app.app_context():
            assert receive_oaiharvest_job(
                request=None, records=[mock_record], name="") is None

            receive_oaiharvest_job(request=None,
                                   records=[mock_record],
                                   name='',
                                   spider='Test',
                                   workflow='test')
            job = CrawlerJob.get_by_job(job_id)

            assert job
Exemple #2
0
def test_receivers(app, db, sample_record):
    """Test receivers."""
    job_id = uuid.uuid4().hex
    responses.add(
        responses.POST, "http://localhost:6800/schedule.json",
        body=json.dumps({"jobid": job_id, "status": "ok"}),
        status=200
    )

    mock_record = MagicMock()
    prop_mock = PropertyMock(return_value=sample_record)
    type(mock_record).raw = prop_mock
    with app.app_context():
        assert receive_oaiharvest_job(
            request=None, records=[mock_record], name=""
        ) is None

        receive_oaiharvest_job(
            request=None,
            records=[mock_record],
            name="",
            spider="Test",
            workflow="test"
        )
        job = CrawlerJob.get_by_job(job_id)

        assert job
def test_receivers_exception(app, db, sample_record_string):
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri('POST',
                                     'http://localhost:6800/schedule.json',
                                     json={
                                         'jobid': None,
                                         'status': 'ok'
                                     })

        mock_record = MagicMock()
        prop_mock = PropertyMock(return_value=sample_record_string)
        type(mock_record).raw = prop_mock

        with app.app_context():
            with pytest.raises(CrawlerScheduleError):
                receive_oaiharvest_job(request=None,
                                       records=[mock_record],
                                       name='',
                                       spider='Test',
                                       workflow='test')
Exemple #4
0
def test_receivers_exception(app, db, sample_record):
    """Test receivers."""
    responses.add(
        responses.POST, "http://localhost:6800/schedule.json",
        body=json.dumps({"jobid": None, "status": "ok"}),
        status=200
    )

    mock_record = MagicMock()
    prop_mock = PropertyMock(return_value=sample_record)
    type(mock_record).raw = prop_mock

    with app.app_context():
        with pytest.raises(CrawlerScheduleError):
            receive_oaiharvest_job(
                request=None,
                records=[mock_record],
                name="",
                spider="Test",
                workflow="test"
            )