Ejemplo n.º 1
0
 def test_save_method(self):
     data = '<h1>Ленин жив</h1>'.encode('utf-8')
     with temp_file() as file_:
         res = Response(body=data, url=None)
         res.save(file_)
         with open(file_, 'rb') as inp:
             self.assertEqual(inp.read(), data)
Ejemplo n.º 2
0
    def test_lxml_tree_realdata(self):
        import lxml.etree

        with open('crawler/data/awesome_python.html', 'rb') as inp:
            data = inp.read()
        res = Response(body=data, url=None)
        self.assertTrue(isinstance(res._lxml_tree(), lxml.etree._ElementTree))
Ejemplo n.º 3
0
    def test_xpath(self):
        from selection import XpathSelector

        with open('crawler/data/awesome_python.html', 'rb') as inp:
            data = inp.read()
        res = Response(body=b'<title>foo</title>', url=None)

        self.assertEqual(res.xpath('//title').text(), 'foo')
Ejemplo n.º 4
0
 def test_absolute_url(self):
     res = Response(body='', url='http://example.com')
     self.assertEquals('http://example.com', res.absolute_url(''))
     self.assertEquals('http://example.com/', res.absolute_url('/'))
     self.assertEquals('http://example.com', res.absolute_url())
     self.assertEquals('http://example.com/foo', res.absolute_url('/foo'))
     self.assertEquals('http://example.com/foo?1=2',
                       res.absolute_url('/foo?1=2'))
     self.assertEquals('http://domain.com/foo',
                       res.absolute_url('http://domain.com/foo'))
Ejemplo n.º 5
0
 def test_lxml_tree_empty_body(self):
     res = Response(body=b'', url=None)
     res._lxml_tree()
Ejemplo n.º 6
0
 def test_lxml_tree_only_comment(self):
     res = Response(body=b'<-- foo -->', url=None)
     res._lxml_tree()
Ejemplo n.º 7
0
 def test_text_method(self):
     res = Response(body='<h1>Ленин жив</h1>'.encode('utf-8'), url=None)
     self.assertEqual('<h1>Ленин жив</h1>', res.text())
Ejemplo n.º 8
0
    def test_selector(self):
        from selection import XpathSelector

        res = Response(body=b'<h1>test</h1>', url=None)

        self.assertTrue(isinstance(res.selector('lxml_xpath'), XpathSelector))