File: test_spidermiddleware_urllength.py

package info (click to toggle)
python-scrapy 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,904 kB
  • ctags: 2,981
  • sloc: python: 15,349; xml: 199; makefile: 68; sql: 64; sh: 34
file content (31 lines) | stat: -rw-r--r-- 946 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from unittest import TestCase

from scrapy.conf import settings
from scrapy.contrib.spidermiddleware.urllength import UrlLengthMiddleware
from scrapy.http import Response, Request
from scrapy.spider import BaseSpider


class TestUrlLengthMiddleware(TestCase):

    def setUp(self):
        settings.disabled = False
        settings.overrides['URLLENGTH_LIMIT'] = 25

        self.spider = BaseSpider()
        self.mw = UrlLengthMiddleware()

    def test_process_spider_output(self):
        res = Response('http://scrapytest.org')

        short_url_req = Request('http://scrapytest.org/')
        long_url_req = Request('http://scrapytest.org/this_is_a_long_url')
        reqs = [short_url_req, long_url_req] 

        out = list(self.mw.process_spider_output(res, reqs, self.spider))
        self.assertEquals(out, [short_url_req])

    def tearDown(self):
        del settings.overrides['URLLENGTH_LIMIT']
        settings.disabled = True