Commit d3b5e786 authored by Raphaël Hertzog's avatar Raphaël Hertzog

Get rid of the old create_source_package() helper function

Convert all users of the function to use the new TestCase.create_source_package() method.
parent e0642ba9
Pipeline #16391 passed with stage
in 111 minutes 42 seconds
......@@ -55,7 +55,6 @@ from distro_tracker.core.models import (
from distro_tracker.core.utils import message_from_bytes
from distro_tracker.core.utils.email_messages import get_decoded_message_payload
from distro_tracker.test import TestCase
from distro_tracker.test.utils import create_source_package
class SubscriptionManagerTest(TestCase):
......@@ -1012,17 +1011,17 @@ class SourcePackageTests(TestCase):
Tests retrieving the URL of the package's directory from the entry.
"""
architectures = ['amd64', 'all']
src_pkg = create_source_package({
'name': 'package-with-directory',
'binary_packages': ['binary-package'],
'version': '0.1',
'maintainer': {
src_pkg = self.create_source_package(
name='package-with-directory',
binary_packages=['binary-package'],
version='0.1',
maintainer={
'name': 'Maintainer',
'email': 'maintainer@domain.com'
},
'architectures': architectures,
'directory': 'pool/path/to/dir',
})
architectures=architectures,
directory='pool/path/to/dir',
)
entry = self.repository.add_source_package(src_pkg)
self.assertEqual(
......@@ -1044,18 +1043,18 @@ class SourcePackageTests(TestCase):
Tests retrieving the URL of the package's .dsc file given in the entry.
"""
architectures = ['amd64', 'all']
src_pkg = create_source_package({
'name': 'package-with-dsc-file',
'binary_packages': ['binary-package'],
'version': '0.1',
'maintainer': {
src_pkg = self.create_source_package(
name='package-with-dsc-file',
binary_packages=['binary-package'],
version='0.1',
maintainer={
'name': 'Maintainer',
'email': 'maintainer@domain.com'
},
'architectures': architectures,
'directory': 'pool/path/to/dir',
'dsc_file_name': 'file.dsc',
})
architectures=architectures,
directory='pool/path/to/dir',
dsc_file_name='file.dsc',
)
entry = self.repository.add_source_package(src_pkg)
self.assertEqual(
......
......@@ -5,25 +5,16 @@
# at https://deb.li/DTAuthors
#
# This file is part of Distro Tracker. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
import contextlib
import shutil
import tempfile
# in the LICENSE file found in the top-level directory of this
# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
from distro_tracker.accounts.models import UserEmail
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
from distro_tracker.core.models import (
Architecture,
BinaryPackageName,
ContributorName,
SourcePackage,
SourcePackageName
)
@contextlib.contextmanager
def make_temp_directory(suffix=''):
......@@ -38,55 +29,6 @@ def make_temp_directory(suffix=''):
shutil.rmtree(temp_dir_name)
def create_source_package(arguments):
"""
Creates and returns a new
:class:`SourcePackage <distro_tracker.core.models.SourcePackage>`
instance based on the parameters given in the arguments.
It takes care to automatically create any missing maintainers, package
names, etc.
"""
kwargs = {}
if 'maintainer' in arguments:
maintainer = arguments['maintainer']
maintainer_email = UserEmail.objects.get_or_create(
email=maintainer['email'])[0]
kwargs['maintainer'] = ContributorName.objects.get_or_create(
contributor_email=maintainer_email,
name=maintainer.get('name', ''))[0]
if 'name' in arguments:
name = arguments['name']
kwargs['source_package_name'] = (
SourcePackageName.objects.get_or_create(name=name)[0])
for arg in ('version', 'directory', 'dsc_file_name'):
if arg in arguments:
kwargs[arg] = arguments[arg]
src_pkg = SourcePackage.objects.create(**kwargs)
# Now add m2m fields
if 'architectures' in arguments:
architectures = arguments['architectures']
src_pkg.architectures.set(
Architecture.objects.filter(name__in=architectures))
if 'binary_packages' in arguments:
binaries = []
for binary in arguments['binary_packages']:
binaries.append(
BinaryPackageName.objects.get_or_create(name=binary)[0])
src_pkg.binary_packages.set(binaries)
if 'uploaders' in arguments:
for uploader in arguments['uploaders']:
contributor = ContributorName.objects.get_or_create(
contributor_email=UserEmail.objects.get_or_create(
email=uploader)[0])[0]
src_pkg.uploaders.add(contributor)
src_pkg.save()
return src_pkg
def set_mock_response(mock_requests, text="", headers=None, status_code=200):
"""
Helper method which sets a mock response to the given mock requests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment