diff --git a/pipenv/environments.py b/pipenv/environments.py index eaf0be55..a8745a9a 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -13,6 +13,9 @@ PIPENV_SHELL_FANCY = bool(os.environ.get('PIPENV_SHELL_FANCY')) # Create the virtualenv in the project, instead of with pew. PIPENV_VENV_IN_PROJECT = bool(os.environ.get('PIPENV_VENV_IN_PROJECT')) or os.path.isdir('.venv') +# Overwrite all index funcitonality. +PIPENV_TEST_INDEX = os.environ.get('PIPENV_TEST_INDEX') + # No color mode, for unfun people. PIPENV_COLORBLIND = bool(os.environ.get('PIPENV_COLORBLIND')) diff --git a/pipenv/project.py b/pipenv/project.py index a1f0c790..5634b762 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -23,7 +23,8 @@ from .environments import ( PIPENV_PIPFILE, PIPENV_VENV_IN_PROJECT, PIPENV_VIRTUALENV, - PIPENV_NO_INHERIT + PIPENV_NO_INHERIT, + PIPENV_TEST_INDEX ) if PIPENV_PIPFILE: @@ -410,17 +411,20 @@ class Project(object): install = dict(config_parser.get_config_section('install')) indexes = install.get('extra-index-url', '').lstrip('\n').split('\n') - # Default source. - pypi_source = {u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, u'name': 'pypi'} - sources = [pypi_source] + if PIPENV_TEST_INDEX: + sources = [{u'url': PIPENV_TEST_INDEX, u'verify_ssl': True, u'name': u'custom'}] + else: + # Default source. + pypi_source = {u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, u'name': 'pypi'} + sources = [pypi_source] - for i, index in enumerate(indexes): - if not index: - continue - source_name = 'pip_index_{}'.format(i) - verify_ssl = index.startswith('https') + for i, index in enumerate(indexes): + if not index: + continue + source_name = 'pip_index_{}'.format(i) + verify_ssl = index.startswith('https') - sources.append({u'url': index, u'verify_ssl': verify_ssl, u'name': source_name}) + sources.append({u'url': index, u'verify_ssl': verify_ssl, u'name': source_name}) data = { u'source': sources, diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index e4ccb070..1870f8c0 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -25,6 +25,15 @@ except: os.environ['PIPENV_DONT_USE_PYENV'] = '1' os.environ['PIPENV_IGNORE_VIRTUALENVS'] = '1' +os.environ['PYPI_VENDOR_DIR'] = os.path.sep.join([os.path.dirname(__file__), 'pypi']) + +from flask import Flask + +class PYPI(object): + """docstring for PYPI""" + def __init__(self, packages=None): + super(PYPI, self).__init__() + self.packages = packages or [] @pytest.fixture(scope='module') @@ -41,7 +50,8 @@ def pip_src_dir(request): class PipenvInstance(): """An instance of a Pipenv Project...""" - def __init__(self, pipfile=True, chdir=False): + def __init__(self, pypi=None, pipfile=True, chdir=False): + self.pypi = pypi self.original_umask = os.umask(0o007) self.original_dir = os.path.abspath(os.curdir) self._path = TemporaryDirectory(suffix='project', prefix='pipenv') @@ -50,6 +60,9 @@ class PipenvInstance(): self.pipfile_path = None self.chdir = chdir + if self.pypi: + os.environ['PIPENV_TEST_INDEX'] = '{0}/simple'.format(self.pypi.url) + if pipfile: p_path = os.sep.join([self.path, 'Pipfile']) with open(p_path, 'a'): @@ -111,8 +124,8 @@ class TestPipenv: """The ultimate testing class.""" @pytest.mark.cli - def test_pipenv_where(self): - with PipenvInstance() as p: + def test_pipenv_where(self, pypi_secure): + with PipenvInstance(pypi=pypi_secure) as p: assert normalize_drive(p.path) in p.pipenv('--where').out @pytest.mark.cli @@ -137,15 +150,15 @@ class TestPipenv: assert not os.path.isdir(venv_path) @pytest.mark.cli - def test_pipenv_graph(self): - with PipenvInstance() as p: + def test_pipenv_graph(self, pypi): + with PipenvInstance(pypi=pypi) as p: p.pipenv('install requests') assert 'requests' in p.pipenv('graph').out assert 'requests' in p.pipenv('graph --json').out @pytest.mark.cli - def test_pipenv_graph_reverse(self): - with PipenvInstance() as p: + def test_pipenv_graph_reverse(self, pypi): + with PipenvInstance(pypi=pypi) as p: p.pipenv('install requests==2.18.4') output = p.pipenv('graph --reverse').out @@ -168,8 +181,8 @@ class TestPipenv: assert 'Warning: Using both --reverse and --json together is not supported.' in c.err @pytest.mark.cli - def test_pipenv_check(self): - with PipenvInstance() as p: + def test_pipenv_check(self, pypi): + with PipenvInstance(pypi=pypi) as p: p.pipenv('install requests==1.0.0') assert 'requests' in p.pipenv('check').out