コード例 #1
0
    def test_multiple_packages_added(self):
        """
        Tests that when multiple packages are added to the default repository,
        they are all correctly processed.
        """
        team_maintainer_packages = [
            self.package,
            create_source_package({
                'name': 'other-package',
                'version': '1.0.0',
                'maintainer': {
                    'name': 'Maintainer',
                    'email': self.maintainer_email,
                },
                'uploaders': self.uploaders,
            })
        ]
        unknown_maintainer = '*****@*****.**'
        unknown_maintainer_packages = [
            create_source_package({
                'name': 'last-package',
                'version': '1.0.0',
                'maintainer': {
                    'name': 'Maintainer',
                    'email': unknown_maintainer,
                },
                'uploaders': self.uploaders,
            })
        ]
        # Add them all to the default repository
        for source_package in \
                team_maintainer_packages + unknown_maintainer_packages:
            self.repository.add_source_package(source_package)
            self.add_mock_events('new-source-package-version-in-repository', {
                'name': source_package.name,
                'version': source_package.version,
                'repository': self.repository.name,
            })
        # Sanity check: the maintainer's team does not have any packages
        self.assertEqual(0, self.team.packages.count())

        self.run_task()

        # The team is not related to the packages with an unknown maintainer
        self.assertEqual(len(team_maintainer_packages),
                         self.team.packages.count())
        all_packages = [p.name for p in self.team.packages.all()]
        for source_package in team_maintainer_packages:
            self.assertIn(source_package.source_package_name.name, all_packages)
コード例 #2
0
 def setUp(self):
     self.repo1 = Repository.objects.create(
         name='repo1', shorthand='repo1')
     self.package = create_source_package({
         'name': 'dummy-package',
         'version': '1.0.0',
     })
     self.repo1.add_source_package(self.package)
     self.update = UpdateVersionInformation()
コード例 #3
0
 def setUp(self):
     self.srcpkg = create_source_package({
         'name': 'dummy-package',
         'version': '1.0.0',
         'maintainer': {
             'name': 'John Doe',
             'email': '*****@*****.**'
         },
         'architectures': ['i386', 'amd64'],
     })
     self.repo1 = Repository.objects.create(name='repo1', shorthand='repo1')
     SourcePackageRepositoryEntry.objects.create(
         source_package=self.srcpkg, repository=self.repo1)
コード例 #4
0
    def test_update_multiple_sources_files(self,
                                           mock_update_repositories,
                                           mock_all_sources):
        """
        Tests the update scenario where only one of the Sources files is
        updated. For example, only the main component of a repository is
        updated whereas contrib and non-free were not.
        """
        src_pkg = create_source_package({
            'name': 'dummy-package',
            'binary_packages': ['dummy-package-binary'],
            'version': '1.0.0',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
            'dsc_file_name': 'file.dsc'
        })
        self.repository.add_source_package(src_pkg)
        # Updated sources - only 1 file
        self.set_mock_sources(mock_update_repositories, 'Sources')
        # All sources - 2 files
        mock_all_sources.return_value = [
            self.get_path_to('Sources'),
            self.get_path_to('Sources-minimal')
        ]
        # Sanity check - only 1 source package exists
        self.assertEqual(SourcePackageName.objects.count(), 1)

        self.run_update()

        # The package from the file which was not updated is still there
        self.assert_package_by_name_in(
            'dummy-package',
            SourcePackageName.objects.all()
        )
        # It is still in the repository
        self.assertEqual(
            1,
            SourcePackageRepositoryEntry.objects.filter(
                repository=self.repository,
                source_package__source_package_name__name='dummy-package').count(),  # noqa
        )
        # The matching binary package is also there
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )
        # The new package from the updated file is there
        self.assertEqual(SourcePackageName.objects.count(), 2)
コード例 #5
0
    def test_update_multiple_versions_in_source_file(self,
                                                     mock_update_repositories,
                                                     mock_all_sources):
        """
        Tests the update scenario where a Sources file that was not updated
        contains multiple source versions of the same source package.
        """
        src_name = 'dummy-package'
        versions = ['1.0.0', '2.0.0']

        src_pkgs = [
            create_source_package({
                'name': src_name,
                'binary_packages': ['dummy-package-binary'],
                'version': version,
                'maintainer': {
                    'name': 'Maintainer',
                    'email': '*****@*****.**'
                },
                'architectures': ['amd64', 'all'],
                'dsc_file_name': 'file.dsc'
            })
            for version in versions
        ]
        for src_pkg in src_pkgs:
            self.repository.add_source_package(src_pkg)
        # Updated sources - only 1 file
        self.set_mock_sources(mock_update_repositories, 'Sources')
        # All sources - 2 files
        mock_all_sources.return_value = [
            self.get_path_to('Sources'),
            self.get_path_to('Sources-multiple-versions')
        ]
        # Sanity check: both versions exist
        self.assertEqual(2, SourcePackage.objects.count())

        self.run_update()

        # The package from the file which was not updated is still there
        self.assert_package_by_name_in(
            'dummy-package',
            SourcePackageName.objects.all()
        )
        # Both versions are still in the repository
        entries = SourcePackageRepositoryEntry.objects.filter(
            repository=self.repository,
            source_package__source_package_name__name='dummy-package')
        self.assertEqual(2, entries.count())
        for entry in entries:
            self.assertIn(entry.source_package.version, versions)
コード例 #6
0
    def test_update_removed_binary_package(self, mock_update):
        """
        Test the scenario when new data removes an existing binary package.
        """
        self.set_mock_sources(mock_update, 'Sources-minimal')
        src_pkg = create_source_package({
            'name': 'dummy-package',
            'binary_packages': ['some-package'],
            'version': '0.1',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
        })
        self.repository.add_source_package(src_pkg)
        # Sanity check -- the binary package exists.
        self.assert_package_by_name_in(
            'some-package',
            BinaryPackageName.objects.all()
        )

        self.run_update()

        # The binary package should no longer exist, replaced by a different one
        self.assertEqual(BinaryPackageName.objects.count(), 1)
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )
        # The new binary package is now mapped to the existing source package
        bin_pkg = BinaryPackageName.objects.get(name='dummy-package-binary')
        self.assertEqual(
            bin_pkg.main_source_package_name,
            src_pkg.source_package_name)
        # All events?
        self.assert_events_raised(
            ['new-source-package-version',
             'new-source-package-version-in-repository'] +
            ['new-binary-package'] +
            ['lost-version-of-source-package',
             'lost-source-package-version-in-repository'] +
            ['lost-binary-package']
        )
コード例 #7
0
    def setUp(self):
        self.maintainer_email = '*****@*****.**'
        self.uploaders = [
            '*****@*****.**',
            '*****@*****.**',
        ]
        self.package = create_source_package({
            'name': 'dummy-package',
            'version': '1.0.0',
            'maintainer': {
                'name': 'Maintainer',
                'email': self.maintainer_email,
            },
            'uploaders': self.uploaders,
        })
        self.repository = Repository.objects.create(
            name='repo', shorthand='repo', default=True)
        self.non_default_repository = Repository.objects.create(
            name='nondef', shorthand='nondef')

        self.password = '******'
        self.user = User.objects.create_user(
            main_email='*****@*****.**', password=self.password,
            first_name='', last_name='')
        self.team = Team.objects.create_with_slug(
            owner=self.user,
            name="Team",
            maintainer_email=self.maintainer_email)
        # Create a team for each of the uploaders and maintainers
        self.teams = [
            Team.objects.create_with_slug(owner=self.user, name="Team" + str(i))
            for i in range(5)
        ]

        self.job_state = mock.create_autospec(JobState)
        self.job_state.events_for_task.return_value = []
        self.job = mock.create_autospec(Job)
        self.job.job_state = self.job_state
        self.task = UpdateTeamPackagesTask()
        self.task.job = self.job
コード例 #8
0
    def test_binary_package_entry_removed(self, mock_update_repositories):
        """
        Tests that an existing
        :class:`BinaryPackageRepositoryEntry
        <distro_tracker.core.models.BinaryPackageRepositoryEntry>` is removed if
        the updated ``Packages`` file no longer contains it.
        """
        binary_name = 'dummy-package-binary'
        source_package = create_source_package({
            'name': 'dummy-package',
            'binary_packages': [binary_name],
            'version': '1.0.0',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
            'dsc_file_name': 'file.dsc'
        })
        # Add a binary package to the repository
        bin_name = BinaryPackageName.objects.all()[0]
        bin_pkg = BinaryPackage.objects.create(
            binary_package_name=bin_name,
            source_package=source_package,
            version='1.0.0')
        arch = Architecture.objects.all()[0]
        self.repository.add_binary_package(bin_pkg, architecture=arch)
        self.set_mock_sources(mock_update_repositories, 'Sources')
        # The existing binary package is no longer found in this Packages file
        self.set_mock_packages(mock_update_repositories, 'Packages-2')

        self.run_update()

        # The entry is removed from the repository
        bin_pkgs_in_repo = [
            entry.binary_package.name
            for entry in self.repository.binary_entries.all()
        ]
        self.assertNotIn(binary_name, bin_pkgs_in_repo)
コード例 #9
0
    def test_update_changed_binary_mapping_2(self, mock_update):
        """
        Tests the scenario when new data changes the source package to which
        a particular binary package belongs and the old source package is
        removed from the repository.
        """
        self.set_mock_sources(mock_update, 'Sources-minimal')

        src_pkg = create_source_package({
            'name': 'dummy-package',
            'version': '0.1',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
        })
        self.repository.add_source_package(src_pkg)

        src_pkg2 = create_source_package({
            'name': 'src-pkg',
            'binary_packages': ['dummy-package-binary'],
            'version': '2.1',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
        })
        self.repository.add_source_package(src_pkg2)
        # Sanity check: the binary package now exists
        self.assertEqual(BinaryPackageName.objects.count(), 1)
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )

        self.run_update()

        # There is only one source package left
        self.assertEqual(SourcePackageName.objects.count(), 1)
        # And only one repository entry
        self.assertEqual(SourcePackageRepositoryEntry.objects.count(), 1)
        self.assert_package_by_name_in(
            'dummy-package',
            SourcePackageName.objects.all()
        )
        src_pkg = SourcePackageName.objects.get(name='dummy-package')
        # The binary package still exists
        self.assertEqual(BinaryPackageName.objects.count(), 1)
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )
        # The binary package is now linked with a different source package
        bin_pkg = BinaryPackageName.objects.get(name='dummy-package-binary')
        self.assertEqual(bin_pkg.main_source_package_name, src_pkg)

        self.assert_events_raised(
            ['new-source-package-version'] +
            ['new-source-package-version-in-repository'] +
            ['lost-version-of-source-package'] * 2 +
            ['lost-source-package-version-in-repository'] * 2 +
            ['lost-source-package']
        )
コード例 #10
0
    def test_update_changed_binary_mapping_1(self, mock_update):
        """
        Tests the scenario when new data changes the source package to which
        a particular binary package belongs.
        """
        self.set_mock_sources(mock_update, 'Sources-minimal-1')

        src_pkg = create_source_package({
            'name': 'dummy-package',
            'version': '0.1',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
        })
        self.repository.add_source_package(src_pkg)

        src_pkg2 = create_source_package({
            'name': 'src-pkg',
            'binary_packages': ['dummy-package-binary', 'other-package'],
            'version': '2.1',
            'maintainer': {
                'name': 'Maintainer',
                'email': '*****@*****.**'
            },
            'architectures': ['amd64', 'all'],
        })
        self.repository.add_source_package(src_pkg2)
        # Sanity check: the binary package now exists
        self.assertEqual(BinaryPackageName.objects.count(), 2)
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )

        self.run_update()

        # Both source package names are still here
        self.assertEqual(SourcePackageName.objects.count(), 2)
        # Still only two source packages since the original ones were merely
        # updated.
        self.assertEqual(SourcePackage.objects.count(), 2)
        self.assertEqual(SourcePackageRepositoryEntry.objects.count(), 2)
        # The package names are unchanged
        self.assert_package_by_name_in(
            'dummy-package',
            SourcePackageName.objects.all()
        )
        self.assert_package_by_name_in(
            'src-pkg',
            SourcePackageName.objects.all()
        )
        src_pkg = SourcePackageName.objects.get(name='dummy-package')
        # Both binary packages are still here
        self.assertEqual(BinaryPackageName.objects.count(), 2)
        self.assert_package_by_name_in(
            'dummy-package-binary',
            BinaryPackageName.objects.all()
        )
        # This binary package is now linked with a different source package
        bin_pkg = BinaryPackageName.objects.get(name='dummy-package-binary')
        self.assertEqual(
            bin_pkg.main_source_package_name,
            src_pkg
        )

        self.assert_events_raised(
            ['new-source-package-version'] * 2 +
            ['new-source-package-version-in-repository'] * 2 +
            ['lost-source-package-version-in-repository'] * 2 +
            ['lost-version-of-source-package'] * 2
        )