def fake_scraper_pages(client): """ Several tests use these fake responses """ client.adapter.register_uri('GET', 'https://errata.devel.redhat.com/products/new', text=load_html('products_new.html')) client.adapter.register_uri( 'GET', 'https://errata.devel.redhat.com/workflow_rules', text=load_html('workflow_rules.html'))
def enum(self, client): client.adapter.register_uri( 'GET', 'https://errata.devel.redhat.com/workflow_rules', text=load_html('workflow_rules.html')) scraper = WorkflowRulesScraper(client) return scraper.enum
def show_index(start_response): """ 处理首页 :param start_response: :return: """ file_name = PAGE_ROOT + '/index.html' return load_html(file_name, start_response)
def show_test(start_response): """ 处理test页面 :param start_response: :return: """ file_name = PAGE_ROOT + '/test.html' return load_html(file_name, start_response)
def test_found_explanations(self, client): """ Verify that we can scrape the error explanations. """ client.adapter.register_uri( 'POST', 'https://errata.devel.redhat.com/products', text=load_html('products_create_form_errors.html')) response = client.post('products') result = scrape_error_explanations(response) assert result == ["Name can't be blank", "Short name can't be blank"]
def test_200_response(self, client): client.adapter.register_uri( 'POST', 'https://errata.devel.redhat.com/products', text=load_html('products_create_form_errors.html')) response = client.post('products') with pytest.raises(RuntimeError) as e: handle_form_errors(response) assert e.value.args == ("Name can't be blank", "Short name can't be blank")
def test_found_message(self, client): """ Verify that we can scrape an error message. """ client.adapter.register_uri( 'POST', 'https://errata.devel.redhat.com/products', status_code=500, text=load_html('products_create_500_error.html')) response = client.post('products') result = scrape_error_message(response) assert result == ('ERROR: Mysql2::Error: Cannot add or update a child ' 'row: a foreign key constraint fails (... longer ' 'error message here ...)')
def test_500_response(self, client): client.adapter.register_uri( 'POST', 'https://errata.devel.redhat.com/products', status_code=500, text=load_html('products_create_500_error.html')) response = client.post('products') with pytest.raises(RuntimeError) as e: handle_form_errors(response) result = str(e.value) assert result == ('ERROR: Mysql2::Error: Cannot add or update a child ' 'row: a foreign key constraint fails (... longer ' 'error message here ...)')
def test_state_machine_rule_set(self, client): """ Ensure that we send the ID number, not the name. CLOUDWF-298 """ client.adapter.register_uri('GET', PROD + '/workflow_rules', text=load_html('workflow_rules.html')) client.adapter.register_uri('PUT', PROD + '/api/v1/releases/1017') differences = [('state_machine_rule_set', None, 'Unrestricted')] edit_release(client, 1017, differences) history = client.adapter.request_history expected = { 'release': { 'state_machine_rule_set_id': 2, } } assert history[-1].json() == expected
def show_index(start_response): file_name = PAGE_ROOT + '/index.html' return load_html(file_name, start_response)
def show_test(start_response): file_name = PAGE_ROOT + '/test.html' return load_html(file_name, start_response)
def fake_response(self, client): client.adapter.register_uri( 'GET', 'https://errata.devel.redhat.com/products/new', text=load_html('products_new.html'))
if pattern: results.append(pattern) return results def performance_test(crawler): results = crawler.extract() assert len(results) == 4 return results if __name__ == '__main__': # https://avxhm.se/music/Monty_Python_Soundtracks_Collection.html some_page = utils.load_html('page.html').lower() regex_crawler = DummyRegexCrawler(some_page) soup = bs4.BeautifulSoup(some_page, 'lxml') bs4_crawler = DummyBs4Crawler(soup) tree = fromstring(some_page) lxml_crawler = DummyLxmlCrawler(tree) scrapy_parser = Selector(text=some_page) scrapy_crawler = DummyScrapyCrawler(scrapy_parser) print( timeit.timeit('performance_test(regex_crawler)', number=100, globals=globals()))
def request_parser(url, asin=None, page_count=None): html_page = load_html(url, asin, page_count) parser = html.fromstring(html_page) return parser