MCPcopy
hub / github.com/scrapinghub/splash / test_abort_request

Method test_abort_request

splash/tests/test_execute_callbacks.py:39–61  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

37 self.assertEqual(requests[0]['url'], urls[0])
38
39 def test_abort_request(self):
40 resp = self.request_lua("""
41 function main(splash)
42 splash:on_request(function(request)
43 if string.find(request.url, "gif") ~= nil then
44 request:abort()
45 end
46 end)
47 splash:go(splash.args.url)
48 return {har=splash:har(), png=splash:png()}
49 end
50 """, {'url': self.mockurl("show-image")})
51 self.assertStatusCode(resp, 200)
52 data = resp.json()
53
54 # the rendered image is not black (gif is not rendered)
55 img = Image.open(BytesIO(base64.b64decode(data['png'])))
56 self.assertEqual((255, 255, 255, 255), img.getpixel((10, 10)))
57
58 # gif file is not in HAR log
59 urls = [e['request']['url'] for e in data['har']['log']['entries']]
60 self.assertTrue(any('show-image' in url for url in urls), urls)
61 self.assertFalse(any('.gif' in url for url in urls), urls)
62
63 def test_set_url(self):
64 url = self.mockurl("http-redirect?code=302")

Callers

nothing calls this directly

Calls 3

mockurlMethod · 0.80
assertStatusCodeMethod · 0.80
request_luaMethod · 0.45

Tested by

no test coverage detected