def test_pipeline_downloader_tarzip_curdler(): "Install#pipeline() should route all the tar/zip files to the curdler" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.curdler.queue = Mock(__name__=str('queue')) install.pipeline() # Handle the installer with the requirement install.finder.queue = Mock() install.handle('tests', requirement='curdling') # When I fire the download.finished() signal with proper data install.downloader.emit('finished', 'downloader', requirement='curdling', tarball='curdling-0.1.tar.gz') # Than I see that the curdler received a request install.curdler.queue.assert_called_once_with( 'downloader', requirement='curdling', tarball='curdling-0.1.tar.gz')
def test_pipeline_curdler_wheel_dependencer(): "Install#pipeline() should route all the wheel files from the curdler to the dependencer" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.dependencer.queue = Mock(__name__=str('queue')) install.pipeline() # Handle the installer with the requirement install.finder.queue = Mock() install.handle('tests', requirement='curdling') # When I fire the curdler.finished() signal with proper data install.curdler.emit('finished', 'curdler', requirement='curdling', wheel='curdling-0.1.0-py27-none-any.whl') # Than I see that the dependencer received a request install.dependencer.queue.assert_called_once_with( 'curdler', requirement='curdling', wheel='curdling-0.1.0-py27-none-any.whl')
def test_pipeline_finder_found_downloader(): "Install#pipeline() should route the finder output to the downloader" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the downloader service end-point install.finder.queue = Mock(__name__=str('queue')) install.downloader.queue = Mock(__name__=str('queue')) install.pipeline() # Handle the installer with the requirement install.finder.queue = Mock() install.handle('tests', requirement='package') install.handle('tests', requirement='package (0.0.1)') # When I fire the finder.finished() signal with proper data install.finder.emit('finished', 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', ) # And manually add the first package to the `processing_packages` set, # because we mock `queue`, the component that actually does that for us. install.downloader.processing_packages.add('package.tar.gz') # And When I fire another finished signal with a different requirement but # the same url install.finder.emit('finished', 'finder', requirement='package (0.0.1)', url='http://another.srv.com/package.tar.gz', locator_url='http://srv.com/simple', ) # Then I see that the downloader received a single request. The second one # was duplicated install.downloader.queue.assert_called_once_with( 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', )
def test_handle_filter_blacklisted_packages(): "Install#handle() Should skip blacklisted package names" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # When I handle the installer with the requirement install.handle('tests', requirement='setuptools') # Then I see it was just skipped install.finder.queue.called.should.be.false
def test_handle_requirement_finder(): "Install#handle() should route all queued requirements to the finder" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I mock some service end-points install.finder.queue = Mock() # When I request the installation of a new requirement install.handle('tests', requirement='curdling') # Then I see the finder received a request install.finder.queue.assert_called_once_with( 'tests', requirement='curdling')
def test_pipeline_update_mapping_errors(): "Install#pipeline() Should update Install#mapping#errors whenever an error occurs" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() install.finder.handle = Mock(side_effect=Exception('P0wned!')) # When I handle the installer with a requirement install.handle('tests', requirement='pkg (0.1)') install.finder.queue(None) install.finder._worker() install.mapping.errors.should.have.length_of(1) str(install.mapping.errors['pkg']['pkg (0.1)']['exception']).should.equal('P0wned!')
def test_pipeline_update_mapping_stats(): "Install#pipeline() Should update the Install#mapping#stats" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() install.finder.handle = Mock(return_value={ 'requirement': 'pkg', 'url': 'pkg.tar.gz', }) # When I handle the installer with a requirement install.handle('tests', requirement='pkg') install.finder.queue(None) install.finder._worker() install.mapping.count('finder').should.equal(1)
def test_handle_link_download(): "Install#handle() should route all queued links to the downloader" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I mock some service end-points install.downloader.queue = Mock() # When I request the installation of a new requirement install.handle('tests', requirement='http://srv/pkgs/curdling-0.1.tar.gz') # I see that the downloader received a request install.downloader.queue.assert_called_once_with( 'tests', requirement='http://srv/pkgs/curdling-0.1.tar.gz', url='http://srv/pkgs/curdling-0.1.tar.gz')
def test_handle_filter_dups(): "Install#handle() Should skip duplicated requirements" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # Handle the installer with the requirement install.handle('tests', requirement='package') install.finder.queue.assert_called_once_with('tests', requirement='package') install.mapping.requirements.should.equal(set(['package'])) # When I fire the finder.finished() signal with proper data install.handle('tests', requirement='package') # Then I see the handle function just skipped this repeated requirement install.finder.queue.assert_called_once_with('tests', requirement='package') install.mapping.requirements.should.equal(set(['package']))
def test_handle_filter_compatible_requirements(): "Install#handle() Should skip requirements that already have compatible matches in the mapping" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # When I handle the installer with a requirement *without dependencies* install.handle('tests', requirement='package (1.0)') # And I handle the installer with another requirement for the same # package above, requested by `something-else` install.handle('tests', requirement='package (3.0)', dependency_of='something-else') # Then I see that the requirement without any dependencies # (primary requirement) is the chosen one install.finder.queue.assert_called_once_with('tests', requirement='package (1.0)') install.mapping.requirements.should.equal(set(['package (1.0)']))