Skip to content

Commit 7ef1e06

Browse files
committed
[tests] add integration test for errback
simple test when target server returns 503, spider errback is executed, we check if errback is actually executed.
1 parent e7defeb commit 7ef1e06

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

tests/test_resource_crawl.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import json
3+
import os
34

45
import pytest
56
import re
@@ -386,8 +387,16 @@ def test_passing_errback(self, server, method):
386387
url = server.url("crawl.json")
387388
res = method(url,
388389
{"spider_name": "test"},
389-
{"url": server.target_site.url("page1.html"),
390-
'errback': 'some_errback',
391-
'callback': 'raise_some_error'})
390+
{"url": server.target_site.url("err/503"),
391+
'errback': 'some_errback'})
392392

393393
res_json = res.json()
394+
assert res_json.get('stats').get('log_count/ERROR') == 1
395+
assert res_json['status'] == 'ok'
396+
logs_path = os.path.join(server.cwd, 'logs', 'test')
397+
logs_files = os.listdir(logs_path)
398+
with open(os.path.join(logs_path, logs_files[0])) as f:
399+
log_file = f.read()
400+
401+
msg = 'ERROR: Logging some error'
402+
assert re.search(msg, log_file)

tests/testsite/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask
1+
from flask import Flask, abort
22

33

44
app = Flask(__name__)
@@ -32,3 +32,8 @@ def page2():
3232
@app.route('/page3.html')
3333
def page3():
3434
return read_file('page3.html')
35+
36+
37+
@app.route('/err/<int:code>')
38+
def return_code(code):
39+
abort(code)

0 commit comments

Comments
 (0)