def test_run_method_should_return_no_matches_found_when_does_not_find_pkgs(): """ Test SearchCommand.run for no matches """ command = SearchCommand() cmdline = "--index=https://pypi.python.org/pypi nonexistentpackage" options, args = command.parse_args(cmdline.split()) status = command.run(options, args) assert status == NO_MATCHES_FOUND
def test_run_method_should_return_success_when_find_packages(): """ Test SearchCommand.run for found package """ command = SearchCommand() cmdline = "--index=https://pypi.python.org/pypi pip" options, args = command.parse_args(cmdline.split()) status = command.run(options, args) assert status == SUCCESS
def test_run_method_should_return_no_matches_found_when_does_not_find_packages(): """ Test SearchCommand.run for no matches """ options_mock = Mock() options_mock.index = 'https://pypi.python.org/pypi' search_cmd = SearchCommand() status = search_cmd.run(options_mock, ('non-existant-package',)) assert status == NO_MATCHES_FOUND, status
def test_run_method_should_return_sucess_when_find_packages(): """ Test SearchCommand.run for found package """ options_mock = Mock() options_mock.index = 'http://pypi.python.org/pypi' search_cmd = SearchCommand() status = search_cmd.run(options_mock, ('pip',)) assert status == SUCCESS
def test_searching_through_Search_class(): """ Verify if ``pip.vcs.Search`` uses tests xmlrpclib.Transport class """ pip.download.xmlrpclib_transport = fake_transport = Mock() query = 'mylittlequerythatdoesnotexists' dumped_xmlrpc_request = b(xmlrpclib.dumps(({'name': query, 'summary': query}, 'or'), 'search')) expected = [{'_pypi_ordering': 100, 'name': 'foo', 'summary': 'foo summary', 'version': '1.0'}] fake_transport.request.return_value = (expected,) pypi_searcher = SearchCommand() result = pypi_searcher.search(query, 'http://pypi.python.org/pypi') assert expected == result, result fake_transport.request.assert_called_with('pypi.python.org', '/pypi', dumped_xmlrpc_request, verbose=VERBOSE_FALSE)
def search_packages(package_name): """ query pip package repository """ versions = [] search = SearchCommand() pypi = search.search(package_name, search.parse_args([package_name])[0]) for hit in transform_hits(pypi): if hit['name'] == package_name: versions = hit['versions'] break return versions
def test_searching_through_Search_class(): """ Verify if ``pip.vcs.Search`` uses tests xmlrpclib.Transport class """ pip.download.xmlrpclib_transport = fake_transport = Mock() query = 'mylittlequerythatdoesnotexists' dumped_xmlrpc_request = xmlrpclib.dumps(({ 'name': query, 'summary': query }, 'or'), 'search') expected = [{ '_pypi_ordering': 100, 'name': 'foo', 'summary': 'foo summary', 'version': '1.0' }] fake_transport.request.return_value = (expected, ) pypi_searcher = SearchCommand() result = pypi_searcher.search(query, 'http://pypi.python.org/pypi') assert expected == result, result fake_transport.request.assert_called_with('pypi.python.org', '/pypi', dumped_xmlrpc_request, verbose=0)
def search(terms): _ensure_search_logger() cmd = SearchCommand() args = terms options, query = cmd.parse_args(args) return cmd.search(query, options)