def test_parsing_fails_raise(self): # If request succeeds but parsing the html data fails show error for it # Use url format context for request to force load dummy file url = (DUMMY_FILE_DIR / 'badhtml.html').as_uri() errormsg = 'Error parsing search response for url "%s"' % url with self.assertRaisesRegex(Exception, errormsg): with url_context(url): search(VALIDPKG, '1.0')
def test_request_fails_raise(self): # If request to DistroWatch fails show error message indicating that # Use url format context for requests to force failure url = (SCRIPTDIR / 'foobar.txt').as_uri() errormsg = 'Error sending search request with url "%s"' % url with self.assertRaisesRegex(Exception, errormsg): with url_context(url): search(VALIDPKG, '1.0')
def test_one_result_return_list_of_one(self): url = (DUMMY_FILE_DIR / 'oneresult.html').as_uri() xp = "./body/div[@id='search-results']/ul/li" with url_context(url), xpath_context(xp): result = search(VALIDPKG, '1.0') self.assertEqual(['The Only One'], result)
def test_three_results_return_list_of_three(self): url = (DUMMY_FILE_DIR / 'threeresults.html').as_uri() xp = "./body/div[@id='search-results']/ul/li" expected = ['The First', 'The 2nd: Number Two', 'Third Result'] with url_context(url), xpath_context(xp): result = search(VALIDPKG, '1.0') self.assertEqual(expected, result)
package_list = [] with open(LFSPKG_FILE) as pf: for pkg in pf: package_list.append(pkg.strip().split()) print('List of packages to search for:') print('\n'.join([pkg[0] + ' ' + pkg[2] for pkg in package_list])) # Do the search for all packages and add the list of results to the map print('\nPerforming package searches...\n') for (name, mode, version) in package_list: print('Searching for distros with "%s %s"...' % (name, version)) key = '%s (%s %s)' % (name, mode, version) package_map[key] = distrosearch.search(name, version, mode) print('\nPackages (and number of qualifying distros):\n') for pkg in sorted(package_map.keys()): print('{: <20}: {}'.format(pkg, len(package_map[pkg]))) # Get set of distros which comply with all host requirements good_distros = set() bad_distros = set() distro_sets = list(filter(None, package_map.values())) # Check each distro in each list and ensure it's in all the other lists for distro_set in distro_sets: for distro in distro_set: if distro in good_distros or distro in bad_distros:
def test_no_search_results_return_empty_list(self): url = (DUMMY_FILE_DIR / 'noresults.html').as_uri() with url_context(url), xpath_context(''): result = search(VALIDPKG, '1.0') self.assertEqual([], result)
def test_version_invalid_raise(self): # Ensure it's a non-empty string with self.assertRaisesRegex(ValueError, 'Version cannot be empty'): search(VALIDPKG, '') with self.assertRaisesRegex(ValueError, 'Version cannot be empty'): search(VALIDPKG, '\t ')
def test_package_invalid_raise(self): # Ensure package is a valid value with self.assertRaisesRegex(ValueError, 'Unknown package: "foobarfoo"'): search('foobarfoo', '1.0')
def test_mode_invalid_raise(self): # Ensure mode is a valid value with self.assertRaisesRegex(ValueError, 'Invalid mode: "badmode"'): search(VALIDPKG, '1.0', 'badmode')