예제 #1
0
    def test_save_unit(self):
        """
        Test the save_unit() method.
        """
        conduit = mock.MagicMock()
        pp = models.Package('name', 'version', 'summary', 'home_page',
                            'author', 'author_email', 'license', 'description',
                            'platform', '_filename', '_checksum',
                            '_checksum_type', '_metadata_file')
        pp._unit = mock.MagicMock()

        pp.save_unit(conduit)

        conduit.save_unit.assert_called_once_with(pp._unit)
예제 #2
0
    def test_storage_path(self):
        """
        Test the storage_path property.
        """
        pp = models.Package('name', 'version', 'summary', 'home_page',
                            'author', 'author_email', 'license', 'description',
                            'platform', '_filename', '_checksum',
                            '_checksum_type')
        pp._unit = mock.MagicMock()
        path = '/some/path.tar.gz'
        pp._unit.storage_path.return_value = path

        sp = pp.storage_path()

        self.assertEqual(sp, path)
예제 #3
0
def make_package():
    return models.Package(
        name='foo',
        version='1.0.0',
        author='Mr Foo',
        author_email='*****@*****.**',
        description='Foo for you.',
        home_page='http://foo.pulpproject.org',
        license='GPL2',
        platform='all',
        summary='Foo!',
        _checksum='abc123',
        _checksum_type='md5',
        _filename='foo-1.0.0.tar.gz',
        _metadata_file='somefile',
    )
예제 #4
0
    def test_init_unit(self):
        """
        Test the init_unit() method.
        """
        pulp_unit = mock.MagicMock()
        conduit = mock.MagicMock()
        conduit.init_unit.return_value = pulp_unit
        name = 'nectar'
        version = '1.3.1'
        summary = 'a summary'
        home_page = 'http://github.com/pulp/nectar'
        author = 'The Pulp Team'
        author_email = '*****@*****.**'
        license = 'GPLv2'
        description = 'a description'
        platform = 'Linux'
        _filename = 'nectar-1.3.1.tar.gz'
        _checksum = 'some_sum'
        _checksum_type = 'some-type'
        _metadata_file = 'nectar-1.3.1/PKG-INFO'
        pp = models.Package(name, version, summary, home_page, author,
                            author_email, license, description, platform,
                            _filename, _checksum, _checksum_type,
                            _metadata_file)

        pp.init_unit(conduit)

        conduit.init_unit.assert_called_once_with(
            models.Package.TYPE, {
                'name': name,
                'version': version
            }, {
                'summary': summary,
                'home_page': home_page,
                'author': author,
                'author_email': author_email,
                'license': license,
                'description': description,
                'platform': platform,
                '_filename': _filename,
                '_checksum': _checksum,
                '_checksum_type': _checksum_type,
                '_metadata_file': _metadata_file
            }, _filename)
        self.assertEqual(pp._unit, pulp_unit)
예제 #5
0
    def test_upload_unit(self, move, save_unit, init_unit, from_archive):
        """
        Assert correct operation of upload_unit().
        """
        package = models.Package('name', 'version', 'summary', 'home_page',
                                 'author', 'author_email', 'license',
                                 'description', 'platform', '_filename',
                                 '_checksum', '_checksum_type',
                                 '_metadata_file')
        from_archive.return_value = package
        storage_path = '/some/path/name-version.tar.bz2'

        def init_unit_side_effect(self, conduit):
            class Unit(object):
                def __init__(self, *args, **kwargs):
                    self.storage_path = storage_path

            self._unit = Unit()

        init_unit.side_effect = init_unit_side_effect

        python_importer = importer.PythonImporter()
        repo = mock.MagicMock()
        type_id = constants.PACKAGE_TYPE_ID
        unit_key = {}
        metadata = {}
        file_path = '/some/path/1234'
        conduit = mock.MagicMock()
        config = {}

        report = python_importer.upload_unit(repo, type_id, unit_key, metadata,
                                             file_path, conduit, config)

        self.assertEqual(report, {
            'success_flag': True,
            'summary': {},
            'details': {}
        })
        from_archive.assert_called_once_with(file_path)
        init_unit.assert_called_once_with(package, conduit)
        save_unit.assert_called_once_with(package, conduit)
        move.assert_called_once_with(file_path, storage_path)
예제 #6
0
    def test___repr__(self):
        """
        Assert correct behavior with the __repr__() method.
        """
        name = 'nectar'
        version = '1.3.1'
        summary = 'a summary'
        home_page = 'http://github.com/pulp/nectar'
        author = 'The Pulp Team'
        author_email = '*****@*****.**'
        license = 'GPLv2'
        description = 'a description'
        platform = 'Linux'
        _filename = 'nectar-1.3.1.tar.gz'
        _checksum = 'abcde'
        _checksum_type = 'some_type'

        pp = models.Package(name, version, summary, home_page, author, author_email, license,
                            description, platform, _filename, _checksum, _checksum_type)

        self.assertEqual(repr(pp), 'Python Package: nectar-1.3.1')
예제 #7
0
    def test_download_succeeded_not_unique(self, super_download_succeeded, mock_objects,
                                           from_archive, checksum, mock_associate):
        """
        Test the download_succeeded() method when the checksum of the downloaded package is correct.
        """
        report = mock.MagicMock()
        report.data = models.Package(name='foo', version='1.0.0', _checksum='good checksum',
                                     _checksum_type='md5')
        step = sync.DownloadPackagesStep('sync_step_download_packages', conduit=mock.MagicMock())
        step.parent = mock.MagicMock()
        checksum.return_value = 'good checksum'
        package = from_archive.return_value
        package.name = 'foo'
        package.version = '1.0.0'
        package.save_and_import_content.side_effect = mongoengine.NotUniqueError

        step.download_succeeded(report)

        package.save_and_import_content.assert_called()
        self.assertEqual(package.import_content.call_count, 0)
        mock_associate.assert_called_once_with(step.parent.get_repo.return_value.repo_obj,
                                               mock_objects.get.return_value)
        mock_objects.get.assert_called_once_with(name='foo', version='1.0.0')
예제 #8
0
    def test___init__(self):
        """
        Assert correct behavior with the __init__() method.
        """
        name = 'nectar'
        version = '1.3.1'
        summary = 'a summary'
        home_page = 'http://github.com/pulp/nectar'
        author = 'The Pulp Team'
        author_email = '*****@*****.**'
        license = 'GPLv2'
        description = 'a description'
        platform = 'Linux'
        _filename = 'nectar-1.3.1.tar.gz'
        _checksum = 'abcde'
        _checksum_type = 'some_type'
        _metadata_file = 'nectar-1.3.1/PKG-INFO'

        pp = models.Package(name, version, summary, home_page, author,
                            author_email, license, description, platform,
                            _filename, _checksum, _checksum_type,
                            _metadata_file)

        self.assertEqual(pp.name, name)
        self.assertEqual(pp.version, version)
        self.assertEqual(pp.summary, summary)
        self.assertEqual(pp.home_page, home_page)
        self.assertEqual(pp.author, author)
        self.assertEqual(pp.author_email, author_email)
        self.assertEqual(pp.license, license)
        self.assertEqual(pp.description, description)
        self.assertEqual(pp.platform, platform)
        self.assertEqual(pp._filename, _filename)
        self.assertEqual(pp._checksum, _checksum)
        self.assertEqual(pp._checksum_type, _checksum_type)
        self.assertEqual(pp._metadata_file, _metadata_file)
        self.assertEqual(pp._unit, None)
예제 #9
0
    def test_download_succeeded_checksum_good(self, super_download_succeeded, download_failed,
                                              from_archive, checksum, mock_associate):
        """
        Test the download_succeeded() method when the checksum of the downloaded package is correct.
        """
        report = mock.MagicMock()
        report.data = models.Package(name='foo', version='1.0.0', _checksum='good checksum',
                                     _checksum_type='md5')
        step = sync.DownloadPackagesStep('sync_step_download_packages', conduit=mock.MagicMock())
        step.parent = mock.MagicMock()
        checksum.return_value = 'good checksum'

        step.download_succeeded(report)

        # Download failed should not have been called
        self.assertEqual(download_failed.call_count, 0)
        # Make sure the checksum was calculated with the correct data
        checksum.assert_called_once_with(report.destination, 'md5')
        # The from_archive method should have been given the destination
        from_archive.assert_called_once_with(report.destination)
        from_archive.return_value.save_and_import_content\
            .assert_called_once_with(report.destination)
        mock_associate.assert_called_once_with(step.parent.get_repo.return_value.repo_obj,
                                               from_archive.return_value)
예제 #10
0
"""
from gettext import gettext as _
import os
import unittest
from xml.etree import cElementTree as ElementTree

import mock

from pulp_python.common import constants
from pulp_python.plugins import models
from pulp_python.plugins.distributors import steps

_PACKAGES = [
    models.Package(name='nectar',
                   version='1.2.0',
                   _filename='nectar-1.2.0.tar.gz',
                   _checksum='abcde',
                   _checksum_type='made_up',
                   _storage_path='/path/to/nectar-1.2.0.tar.gz'),
    models.Package(name='nectar',
                   version='1.3.1',
                   _filename='nectar-1.3.1.tar.gz',
                   _checksum='fghij',
                   _checksum_type='made_up',
                   _storage_path='/path/to/nectar-1.3.1.tar.gz'),
    models.Package(name='pulp_python_plugins',
                   version='0.0.0',
                   _filename='pulp_python_plugins-0.0.0.tar.gz',
                   _checksum='klmno',
                   _checksum_type='made_up',
                   _storage_path='/path/to/pulp_python_plugins-0.0.0.tar.gz'),
]
예제 #11
0
import unittest

import mock

from pulp_python.plugins import models, querysets

from .importers.test_sync import NUMPY_MANIFEST

_PACKAGES = [
    models.Package(name='nectar',
                   packagetype='sdist',
                   version='1.2.0',
                   author='me',
                   summary='does stuff',
                   md5_digest='abcde',
                   filename='nectar-1.2.0.tar.gz',
                   _checksum='abcde',
                   _checksum_type='made_up',
                   path='some/url',
                   _storage_path='/path/to/nectar-1.2.0.tar.gz'),
    models.Package(name='nectar',
                   packagetype='sdist',
                   version='1.3.1',
                   summary='does stuff',
                   author='me',
                   filename='nectar-1.3.1.tar.gz',
                   md5_digest='fghij',
                   _checksum='fghij',
                   _checksum_type='made_up',
                   path='some/url',
                   _storage_path='/path/to/nectar-1.3.1.tar.gz'),