summaryrefslogtreecommitdiff
path: root/tests/test_search.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_search.py')
-rw-r--r--tests/test_search.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/test_search.py b/tests/test_search.py
index 7dc884872..44c9fe970 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -2,7 +2,8 @@ import pip.download
from pip.commands.search import (compare_versions,
highest_version,
transform_hits,
- SearchCommand,)
+ SearchCommand)
+from pip.status_codes import NO_MATCHES_FOUND, SUCCESS
from pip.backwardcompat import xmlrpclib, b
from mock import Mock
from tests.test_pip import run_pip, reset_env, pyversion
@@ -66,6 +67,7 @@ def test_searching_through_Search_class():
"""
Verify if ``pip.vcs.Search`` uses tests xmlrpclib.Transport class
"""
+ original_xmlrpclib_transport = pip.download.xmlrpclib_transport
pip.download.xmlrpclib_transport = fake_transport = Mock()
query = 'mylittlequerythatdoesnotexists'
dumped_xmlrpc_request = b(xmlrpclib.dumps(({'name': query, 'summary': query}, 'or'), 'search'))
@@ -73,8 +75,11 @@ def test_searching_through_Search_class():
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)
+ try:
+ assert expected == result, result
+ fake_transport.request.assert_called_with('pypi.python.org', '/pypi', dumped_xmlrpc_request, verbose=VERBOSE_FALSE)
+ finally:
+ pip.download.xmlrpclib_transport = original_xmlrpclib_transport
def test_search_missing_argument():
@@ -84,3 +89,39 @@ def test_search_missing_argument():
env = reset_env(use_distribute=True)
result = run_pip('search', expect_error=True)
assert 'ERROR: Missing required argument (search query).' in result.stdout
+
+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_run_method_should_return_no_matches_found_when_does_not_find_packages():
+ """
+ Test SearchCommand.run for no matches
+ """
+ options_mock = Mock()
+ options_mock.index = 'http://pypi.python.org/pypi'
+ search_cmd = SearchCommand()
+ status = search_cmd.run(options_mock, ('non-existant-package',))
+ assert status == NO_MATCHES_FOUND, status
+
+def test_search_should_exit_status_code_zero_when_find_packages():
+ """
+ Test search exit status code for package found
+ """
+ env = reset_env(use_distribute=True)
+ result = run_pip('search', 'pip')
+ assert result.returncode == SUCCESS
+
+def test_search_exit_status_code_when_finds_no_package():
+ """
+ Test search exit status code for no matches
+ """
+ env = reset_env(use_distribute=True)
+ result = run_pip('search', 'non-existant-package', expect_error=True)
+ assert result.returncode == NO_MATCHES_FOUND