def test_max_timeout(self): with SplashServer(extra_args=['--max-timeout=0.1']) as splash: r1 = requests.get( url=splash.url("render.html"), params={ 'url': self.mockurl("delay?n=1"), 'timeout': '0.2', }, ) self.assertStatusCode(r1, 400) r2 = requests.get( url=splash.url("render.html"), params={ 'url': self.mockurl("delay?n=1"), 'timeout': '0.1', }, ) self.assertStatusCode(r2, 504) r3 = requests.get( url=splash.url("render.html"), params={'url': self.mockurl("delay?n=1")}, ) self.assertStatusCode(r3, 504) r4 = requests.get( url=splash.url("render.html"), params={'url': self.mockurl("")}, ) self.assertStatusCode(r4, 200)
def run_with_extra_args(self, extra_args): with SplashServer(extra_args=extra_args) as splash: test_url = self.mockurl('subresources-with-caching') render_url = splash.url('render.har') # 1st page fetch r = requests.get(render_url, params={ 'url': test_url, 'response_body': 1 }) self.assertStatusCode(r, 200) entry11 = self.findHAREntry(r.json(), r"^.*subresources-with-caching$") entry12 = self.findHAREntry( r.json(), r"^.*subresources-with-caching/img.gif$") # 2nd page fetch r = requests.get(render_url, params={ 'url': test_url, 'response_body': 1 }) self.assertStatusCode(r, 200) entry21 = self.findHAREntry(r.json(), r"^.*subresources-with-caching$") entry22 = self.findHAREntry( r.json(), r"^.*subresources-with-caching/img.gif$") return [[entry11, entry12], [entry21, entry22]]
def test_verbosity4_works(self): with SplashServer(extra_args=['-v4']) as splash: resp = requests.get( url=splash.url("render.html"), params={'url': self.mockurl("jsrender")}, timeout=3, ) self.assertStatusCode(resp, 200)
def test_file_scheme_can_be_enabled(self): assert os.path.isfile(self.FILE_PATH) with SplashServer(extra_args=['--allowed-schemes=http,file']) as splash: url = splash.url('render.html') r = requests.get(url, params={'url': self.FILE_URL}) self.assertStatusCode(r, 200) self.assertIn('script.js', r.text)
def test_browser_engines_all_enabled(self): with SplashServer( extra_args=['--browser-engines', 'chromium,webkit']) as splash: url = self.mockurl('getrequest') + '?code=200' resp = self._request_html(splash, {'url': url, 'engine': 'webkit'}) self.assertStatusCode(resp, 200) resp = self._request_html(splash, { 'url': url, 'engine': 'chromium' }) self.assertStatusCode(resp, 200)
def test_js_external_iframe_cross_domain_enabled(self): # cross-domain access should work if we enable it with SplashServer(extra_args=['--js-cross-domain-access']) as splash: query = {'url': ts.mockserver.url("externaliframe"), 'script': 1} headers = {'content-type': 'application/javascript'} response = requests.post( splash.url("render.json"), params=query, headers=headers, data=self.CROSS_DOMAIN_JS, ) self.assertEqual(response.json()['script'], u'EXTERNAL\n\n')
def test_browser_engines_invalid(self): with pytest.raises(RuntimeError) as e: with SplashServer( extra_args=['--browser-engines', 'foo']) as splash: pass