def test_create_dom_snapshot_loop_raises_if_run_returns_error():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.ERROR,
                                                error="OOPS")

    with pytest.raises(DomSnapshotScriptError, match="OOPS"):
        create_dom_snapshot_loop(script, 1, 2, 3)
def test_create_dom_snapshot_loop_timeout():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.WIP)
    script.poll_result.return_value = ProcessPageResult(ProcessPageStatus.WIP)

    with pytest.raises(DomSnapshotTimeout):
        create_dom_snapshot_loop(script, 5, 2, 3)
def test_create_dom_snapshot_loop_calls_poll_result_with_chunk_byte_length():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.WIP)
    script.poll_result.return_value = ProcessPageResult(
        ProcessPageStatus.SUCCESS, value={})

    create_dom_snapshot_loop(script, time() + 1, 2, 3)

    calls = script.poll_result.call_args_list
    assert calls == [mock.call(3)]
Example #4
0
def test_create_dom_snapshot_loop_calls_run_with_args():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.WIP)
    script.poll_result.return_value = ProcessPageResult(
        ProcessPageStatus.SUCCESS, value={}
    )

    create_dom_snapshot_loop(
        script, time() + 1, 2, 3, dont_fetch_resources=True, skip_resources=[]
    )

    calls = script.run.call_args_list
    assert calls == [mock.call(dont_fetch_resources=True, skip_resources=[])]
def test_create_dom_snapshot_loop_success():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.WIP)
    script.poll_result.return_value = ProcessPageResult(
        ProcessPageStatus.SUCCESS, value={"a": "b"})

    res = create_dom_snapshot_loop(script, time() + 1, 2, 3)

    assert res == {"a": "b"}
Example #6
0
def test_create_dom_snapshot_loop_chunks():
    script = mock.MagicMock()
    script.run.return_value = ProcessPageResult(ProcessPageStatus.WIP)
    script.poll_result.side_effect = [
        ProcessPageResult(ProcessPageStatus.SUCCESS_CHUNKED, done=False, value='{"a"'),
        ProcessPageResult(ProcessPageStatus.SUCCESS_CHUNKED, done=True, value=':"b"}'),
    ]

    res = create_dom_snapshot_loop(script, time() + 1, 1, 3)

    assert res == {"a": "b"}
Example #7
0
 def failing_once_loop(*args, **kwargs):
     failing_once_loop.call_count += 1
     if failing_once_loop.call_count == 2:
         raise Exception
     else:
         return create_dom_snapshot_loop(*args, **kwargs)