Completed
Push — master ( 22211d...11aa1d )
by Roy
01:08
created

TestBaseHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 56
rs 10
c 1
b 1
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_task_join_crawl_config() 0 33 1
1
#!/usr/bin/env python
2
# -*- encoding: utf-8 -*-
3
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
4
# Author: Binux<[email protected]>
5
#         http://binux.me
6
# Created on 2017-02-26 10:35:23
7
8
import unittest2 as unittest
9
10
from pyspider.libs.base_handler import BaseHandler
11
12
13
class TestBaseHandler(unittest.TestCase):
14
    sample_task_http = {
15
        'taskid': 'taskid',
16
        'project': 'project',
17
        'url': '',
18
        'fetch': {
19
            'method': 'GET',
20
            'headers': {
21
                'Cookie': 'a=b',
22
                'a': 'b'
23
            },
24
            'cookies': {
25
                'c': 'd',
26
            },
27
            'timeout': 60,
28
            'save': 'abc',
29
        },
30
        'process': {
31
            'callback': 'callback',
32
            'save': [1, 2, 3],
33
        },
34
    }
35
36
    def test_task_join_crawl_config(self):
37
        task = dict(self.sample_task_http)
38
        crawl_config = {
39
            'taskid': 'xxxx',       # should not affect finial task
40
            'proxy': 'username:password@hostname:port',  # should add proxy
41
            'headers': {            # should merge headers
42
                'Cookie': 'abc',    # should not affect cookie
43
                'c': 'd',           # should add header c
44
            }
45
        }
46
        
47
        ret = BaseHandler.task_join_crawl_config(task, crawl_config)
48
        self.assertDictEqual(ret, {
49
            'taskid': 'taskid',
50
            'project': 'project',
51
            'url': '',
52
            'fetch': {
53
                'method': 'GET',
54
                'proxy': 'username:password@hostname:port',
55
                'headers': {
56
                    'Cookie': 'a=b',
57
                    'a': 'b',
58
                    'c': 'd'
59
                },
60
                'cookies': {
61
                    'c': 'd',
62
                },
63
                'timeout': 60,
64
                'save': 'abc',
65
            },
66
            'process': {
67
                'callback': 'callback',
68
                'save': [1, 2, 3],
69
            },
70
        });
71