From 6c58093eefec13044c836a97a2dacdee162836db Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 20 Jun 2018 22:09:31 +0200 Subject: browser: Add a few more tests Increase coverage. --- crocoite/test_browser.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'crocoite') diff --git a/crocoite/test_browser.py b/crocoite/test_browser.py index cf7be39..92d9676 100644 --- a/crocoite/test_browser.py +++ b/crocoite/test_browser.py @@ -21,8 +21,9 @@ import pytest from operator import itemgetter from http.server import BaseHTTPRequestHandler +from pychrome.exceptions import TimeoutException -from .browser import Item, SiteLoader, ChromeService +from .browser import Item, SiteLoader, ChromeService, NullService, BrowserCrashed class TItem (Item): """ This should be as close to Item as possible """ @@ -104,8 +105,9 @@ def http (): @pytest.fixture def loader (http): def f (path): - assert path.startswith ('/') - return SiteLoader (browser, 'http://localhost:8000{}'.format (path)) + if path.startswith ('/'): + path = 'http://localhost:8000{}'.format (path) + return SiteLoader (browser, path) print ('loader setup') with ChromeService () as browser: yield f @@ -127,6 +129,7 @@ def itemsLoaded (l, items): assert False, 'url {} not supposed to be fetched'.format (item.url) assert item.body[0] == golden.body[0] assert item.response['status'] == golden.response['status'] + assert item.statusText == BaseHTTPRequestHandler.responses.get (item.response['status'])[0] for k, v in golden.responseHeaders: actual = list (map (itemgetter (1), filter (lambda x: x[0] == k, item.responseHeaders))) assert v in actual @@ -175,3 +178,28 @@ def test_html (loader): # make sure alerts are dismissed correctly (image won’t load otherwise) literalItem (loader, testItemMap['/html/alert'], [testItemMap['/image']]) +def test_crash (loader): + with loader ('/html') as l: + l.start () + try: + l.tab.Page.crash (_timeout=1) + except TimeoutException: + pass + q = l.queue + assert isinstance (q.popleft (), BrowserCrashed) + +def test_invalidurl (loader): + url = 'http://nonexistent.example/' + with loader (url) as l: + l.start () + q = l.queue + it = q.popleft () + assert it.failed + +def test_nullservice (): + """ Null service returns the url as is """ + + url = 'http://localhost:12345' + with NullService (url) as u: + assert u == url + -- cgit v1.2.3