1. Armin Ronacher
  2. pip

Commits

Hugo Lopes Tavares  committed df237a0

using custom xmlrpclib.Transport (testability purposes)

  • Participants
  • Parent commits 332bf62
  • Branches default

Comments (0)

Files changed (4)

File pip/commands/search.py

View file
 import xmlrpclib
 import textwrap
 import pkg_resources
+import pip.download
 from pip.basecommand import Command
 from pip.util import get_terminal_size
 from pip.log import logger
         print_results(hits, terminal_width=terminal_width)
 
     def search(self, query, index_url):
-        pypi = xmlrpclib.ServerProxy(index_url)
+        pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport)
         hits = pypi.search({'name': query, 'summary': query}, 'or')
         return hits
 

File pip/download.py

View file
+import xmlrpclib
+
+xmlrpclib_transport = xmlrpclib.Transport()

File setup.py

View file
       packages=['pip', 'pip.commands', 'pip.vcs'],
       entry_points=dict(console_scripts=['pip=pip:main']),
       test_suite='nose.collector',
-      tests_require=['nose', 'virtualenv', 'scripttest', 'wsgi_intercept', 'wsgiproxy', 'WebOb==dev,>=0.9.8post1'],
+      tests_require=['nose', 'virtualenv', 'scripttest', 'wsgi_intercept', 'wsgiproxy', 'WebOb==dev,>=0.9.8post1', 'mock'],
       zip_safe=False)

File tests/test_search.py

View file
-
-import os
-import sys
-sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
-
-from pip.commands.search import compare_versions, highest_version, transform_hits
+import xmlrpclib
+import pip.download
+from pip.commands.search import (compare_versions,
+                                 highest_version,
+                                 transform_hits,
+                                 SearchCommand,)
+from mock import Mock
 from test_pip import run_pip, reset_env
 
 
     output = run_pip('search', 'pip', expect_error=True)
     assert 'pip installs packages' in output.stdout
 
+
+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)