def test_to_ensure_relevant_ads_appear_when_no_ads_available(self): urls = [ 'http://quotes.toscrape.com/page/2/', 'http://quotes.toscrape.com/page/1/' ] result = scrape('random', urls.copy()) self.assertEqual(result[1].get('zone_id'), 'zone755505698')
def test_to_ensure_relevant_ads_appear_when_ads_available(self): urls = [ 'http://quotes.toscrape.com/page/2/', 'http://quotes.toscrape.com/page/1/' ] result = scrape('football', urls.copy()) self.assertEqual(result[1].get('zone_id'), 'zone669165852')
def test_a_whole_word_is_not_needed_to_match(self): urls = [ 'http://quotes.toscrape.com/page/2/', 'http://quotes.toscrape.com/page/1/' ] result = scrape('indifference', urls.copy()) self.assertEqual(len(result[0]), 1) self.assertEqual(result[0][0].get('url'), 'http://quotes.toscrape.com/page/2/')
def test_every_word_searched_for_gets_accounted_for(self): urls = [ 'http://quotes.toscrape.com/page/2/', 'http://quotes.toscrape.com/page/1/' ] result = scrape('BOB albert', urls.copy()) self.assertEqual(len(result[0]), 2) for entry in result[0]: self.assertTrue(entry.get('url') in urls)
def upload_csv(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return Response("No File", 404) file = request.files['file'] if file.filename == '': return Response("No File", 404) if file and allowed_file(file.filename): res = insta.scrape(file) return send_file(res)\
def test_scrape(self): """ test case for crawl """ items = app.scrape(self.html) self.assertIsNotNone(items)
# Add parent directory import os, sys, inspect currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.insert(0, os.path.dirname(currentdir)) from app import scrape WEBSITE = 'http://www.bierbrierdevelopment.com/' if __name__ == '__main__': result = scrape(website=WEBSITE) print('{} Results Found'.format(len(result)))
def tests_all_urls(self): urls = Urls.urls.copy() result = scrape('a', Urls.urls) self.assertEqual(len(result[0]), len(urls)) for entry in result[0]: self.assertTrue(entry.get('url') in urls)
def test_search_string_return_correct_answer_uppercase(self): url = 'http://quotes.toscrape.com/page/2/' result = scrape('BOB', [url]) self.assertEqual(len(result[0]), 1) self.assertEqual(result[0][0].get('url'), url)