File: test_command_fetch.py

package info (click to toggle)
python-scrapy 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,664 kB
  • sloc: python: 52,028; xml: 199; makefile: 25; sh: 7
file content (35 lines) | stat: -rw-r--r-- 1,218 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
32
33
34
35
from twisted.internet import defer
from twisted.trial import unittest

from tests.utils.testproc import ProcessTest
from tests.utils.testsite import SiteTest


class TestFetchCommand(ProcessTest, SiteTest, unittest.TestCase):
    command = "fetch"

    @defer.inlineCallbacks
    def test_output(self):
        _, out, _ = yield self.execute([self.url("/text")])
        assert out.strip() == b"Works"

    @defer.inlineCallbacks
    def test_redirect_default(self):
        _, out, _ = yield self.execute([self.url("/redirect")])
        assert out.strip() == b"Redirected here"

    @defer.inlineCallbacks
    def test_redirect_disabled(self):
        _, out, err = yield self.execute(
            ["--no-redirect", self.url("/redirect-no-meta-refresh")]
        )
        err = err.strip()
        assert b"downloader/response_status_count/302" in err, err
        assert b"downloader/response_status_count/200" not in err, err

    @defer.inlineCallbacks
    def test_headers(self):
        _, out, _ = yield self.execute([self.url("/text"), "--headers"])
        out = out.replace(b"\r", b"")  # required on win32
        assert b"Server: TwistedWeb" in out, out
        assert b"Content-Type: text/plain" in out