Verified Commit db4c0c3f authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

Merge branch 'branch-coverage' of salsa.debian.org:lyknode/debexpo into live

MR: !187


Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parents 857b453f 6453d37e
Pipeline #335265 passed with stage
in 10 minutes and 57 seconds
...@@ -78,3 +78,9 @@ class TestPluginRFSTemplate(TestImporterController): ...@@ -78,3 +78,9 @@ class TestPluginRFSTemplate(TestImporterController):
'[NMU] [QA] [Team] -- Test package for debexpo') '[NMU] [QA] [Team] -- Test package for debexpo')
self.assert_rfs_content('does-not-exist', self.assert_rfs_content('does-not-exist',
'Severity: wishlist') 'Severity: wishlist')
def test_no_vcs_browser(self):
self.import_source_package('hello-no-vcs-browser')
self.assert_importer_succeeded()
self.assert_rfs_content('hello',
'Vcs : [fill in')
...@@ -130,13 +130,17 @@ BQJb8YGqAhsMAAoJEMQ0eBzocfPf8IcA/RyHF6zgRu2Ds3wH8GgxjCZRW+YxWahX ...@@ -130,13 +130,17 @@ BQJb8YGqAhsMAAoJEMQ0eBzocfPf8IcA/RyHF6zgRu2Ds3wH8GgxjCZRW+YxWahX
self._run_command(command, args, self.source_dir, self._run_command(command, args, self.source_dir,
self._get_env_with_gpg()) self._get_env_with_gpg())
def _build_package(self): def _build_package(self, sign):
args = ['--build=source', args = ['--build=source',
'--no-check-builddeps', '--no-check-builddeps',
'--sign-key=559306EEE1C8C1B2DD1C73B1C434781CE871F3DF', '--sign-key=559306EEE1C8C1B2DD1C73B1C434781CE871F3DF']
'--force-sign']
command = 'dpkg-buildpackage' command = 'dpkg-buildpackage'
if sign:
args.append('--force-sign')
else:
args.append('--no-sign')
log.debug('Build source package {}-{}'.format(self.package, log.debug('Build source package {}-{}'.format(self.package,
self.version)) self.version))
self._run_command(command, args, join(self.workdir, 'sources'), self._run_command(command, args, join(self.workdir, 'sources'),
...@@ -180,14 +184,14 @@ BQJb8YGqAhsMAAoJEMQ0eBzocfPf8IcA/RyHF6zgRu2Ds3wH8GgxjCZRW+YxWahX ...@@ -180,14 +184,14 @@ BQJb8YGqAhsMAAoJEMQ0eBzocfPf8IcA/RyHF6zgRu2Ds3wH8GgxjCZRW+YxWahX
def get_package_dir(self): def get_package_dir(self):
return self.workdir return self.workdir
def build(self): def build(self, sign=True):
# Copy sources files into workdir # Copy sources files into workdir
copytree(self.source_dir, copytree(self.source_dir,
join(self.workdir, 'sources')) join(self.workdir, 'sources'))
# Gen orig, build and sign # Gen orig, build and sign
self._gen_orig() self._gen_orig()
self._build_package() self._build_package(sign)
# Remove temporary source dir # Remove temporary source dir
if isdir(join(self.workdir, 'sources')): if isdir(join(self.workdir, 'sources')):
......
../../hello/debian/changelog
\ No newline at end of file
../../hello/debian/compat
\ No newline at end of file
Source: hello
Section: utils
Priority: optional
Maintainer: Vincent TIME <vtime@example.org>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: https://example.org
Vcs-Git: https://salsa.debian.org/debian/hello.git
Package: hello
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Test package for debexpo
Unfortunatly, a too short description
../../hello/debian/rules
\ No newline at end of file
../../hello/debian/source
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# This file is part of debexpo # This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo # https://salsa.debian.org/mentors.debian.net-team/debexpo
# #
# Copyright © 2018-2020 Baptiste Beauplat <lyknode@cilg.org> # Copyright © 2018-2021 Baptiste Beauplat <lyknode@debian.org>
# #
# Permission is hereby granted, free of charge, to any person # Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation # obtaining a copy of this software and associated documentation
...@@ -34,6 +34,7 @@ UploadController test cases. ...@@ -34,6 +34,7 @@ UploadController test cases.
from os.path import join from os.path import join
from os import utime, unlink from os import utime, unlink
from time import time from time import time
from glob import glob
from django.conf import settings from django.conf import settings
from django.core import mail from django.core import mail
...@@ -42,6 +43,7 @@ from django.test import override_settings ...@@ -42,6 +43,7 @@ from django.test import override_settings
from tests.functional.importer import TestImporterController from tests.functional.importer import TestImporterController
from debexpo.importer.models import Importer, ExceptionImporterRejected from debexpo.importer.models import Importer, ExceptionImporterRejected
from debexpo.tools.debian.changes import Changes
class TestImporter(TestImporterController): class TestImporter(TestImporterController):
...@@ -202,6 +204,20 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw== ...@@ -202,6 +204,20 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw==
self.assert_package_count('hello', '1.0-1', 0) self.assert_package_count('hello', '1.0-1', 0)
self.assert_package_not_in_repo('hello', '1.0-1') self.assert_package_not_in_repo('hello', '1.0-1')
def test_import_package_not_signed_ok(self):
self._setup_example_user(email='vtime@example.org')
self.import_source_package('hello', skip_gpg=True)
self.assert_importer_succeeded()
self.assert_package_count('hello', '1.0-1', 1)
self.assert_package_in_repo('hello', '1.0-1')
def test_import_package_not_signed_ok_no_user(self):
self.import_source_package('hello', skip_gpg=True)
self.assert_importer_failed()
self.assert_email_with('No user found for')
self.assert_package_count('hello', '1.0-1', 0)
self.assert_package_not_in_repo('hello', '1.0-1')
def test_import_package_not_signed(self): def test_import_package_not_signed(self):
self.import_package('not-signed') self.import_package('not-signed')
self.assert_importer_failed() self.assert_importer_failed()
...@@ -460,17 +476,17 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw== ...@@ -460,17 +476,17 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw==
self.assertIn('No space left', mail.outbox[0].body) self.assertIn('No space left', mail.outbox[0].body)
self.assertIn(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].to) self.assertIn(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].to)
def test_importer_fail_no_changed_by(self): def test_importer_fail_no_changed_by_no_spool(self):
self._upload_package(join(self.data_dir, 'changes-no-changed-by')) filename = glob(join(self.data_dir, 'changes-no-changed-by',
'*.changes'))[0]
importer = Importer(str(self.spool)) importer = Importer()
changes = self.spool.changes_to_process()[0] changes = Changes(filename)
importer._fail(ExceptionImporterRejected( importer._fail(ExceptionImporterRejected(
changes, 'Importer failed', changes, 'Importer failed',
IOError('No space left on device')) IOError('No space left on device'))
) )
changes.remove()
self.assertEquals(len(mail.outbox), 1) self.assertEquals(len(mail.outbox), 1)
self.assertEquals(changes.uploader, changes.maintainer) self.assertEquals(changes.uploader, changes.maintainer)
...@@ -491,6 +507,7 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw== ...@@ -491,6 +507,7 @@ r1JREXlgQRuRdd5ZWSvIxKaKGVbYCw==
self.assertEquals(len(mail.outbox), 1) self.assertEquals(len(mail.outbox), 1)
self.assertEquals(changes.uploader, changes._data.get('Changed-By')) self.assertEquals(changes.uploader, changes._data.get('Changed-By'))
self.assertEquals(changes.changes, changes._data.get('Changes'))
self.assertNotEquals(changes.uploader, changes.maintainer) self.assertNotEquals(changes.uploader, changes.maintainer)
self.assertIn('No space left', mail.outbox[0].body) self.assertIn('No space left', mail.outbox[0].body)
self.assertIn(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].to) self.assertIn(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].to)
......
...@@ -213,6 +213,14 @@ C7NQGzfRMFLSPxIHVzhHvJUo6vNZ+AA= ...@@ -213,6 +213,14 @@ C7NQGzfRMFLSPxIHVzhHvJUo6vNZ+AA=
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
# Next upload allowed
response = self.client.put(reverse(
'upload',
args=['vitetris_0.58.0-2.dsc']),
data='contents')
self.assertEqual(response.status_code, 200)
for filename in (os.path.join(settings.UPLOAD_SPOOL, for filename in (os.path.join(settings.UPLOAD_SPOOL,
'incoming', 'vitetris_0.58.0-1.dsc'), 'incoming', 'vitetris_0.58.0-1.dsc'),
os.path.join(settings.UPLOAD_SPOOL, os.path.join(settings.UPLOAD_SPOOL,
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
from django.core import mail from django.core import mail
from django.urls import reverse from django.urls import reverse
from django.test import override_settings
from django.conf import settings
from tests import TestController from tests import TestController
from debexpo.accounts.models import User from debexpo.accounts.models import User
...@@ -199,7 +201,16 @@ class TestPackageController(TestController): ...@@ -199,7 +201,16 @@ class TestPackageController(TestController):
self.assertRaises(Package.DoesNotExist, Package.objects.get, self.assertRaises(Package.DoesNotExist, Package.objects.get,
name='testpackage') name='testpackage')
def test_delete_upload_successful(self): @override_settings()
def test_delete_successful_no_gitstorage(self):
del settings.GIT_STORAGE
self.test_delete_successful()
@override_settings()
def test_delete_upload_successful_no_gitstorage(self):
del settings.GIT_STORAGE
self.client.post(reverse('login'), self._AUTHDATA) self.client.post(reverse('login'), self._AUTHDATA)
response = self.client.post(reverse( response = self.client.post(reverse(
...@@ -227,6 +238,22 @@ class TestPackageController(TestController): ...@@ -227,6 +238,22 @@ class TestPackageController(TestController):
def test_comment_bad_method(self): def test_comment_bad_method(self):
self._test_bad_method('comment_package') self._test_bad_method('comment_package')
def test_comment_bad_form(self):
self.client.post(reverse('login'), self._AUTHDATA)
upload = PackageUpload.objects.filter(package__name='testpackage') \
.earliest('uploaded')
response = self.client.post(reverse('comment_package',
args=['testpackage']), {
'upload_id': upload.id,
'text': 'This is a test comment',
'outcome': 42,
'commit': 'submit_comment'
})
self.assertEquals(response.status_code, 200)
self.assertIn('errorlist', str(response.content))
def test_comment(self): def test_comment(self):
self.client.post(reverse('login'), self._AUTHDATA) self.client.post(reverse('login'), self._AUTHDATA)
......
...@@ -30,6 +30,9 @@ import logging ...@@ -30,6 +30,9 @@ import logging
from email import message_from_string from email import message_from_string
from http.server import BaseHTTPRequestHandler from http.server import BaseHTTPRequestHandler
from django.conf import settings
from django.test import override_settings
# from debexpo.lib.email import Email # from debexpo.lib.email import Email
from debexpo.accounts.models import User from debexpo.accounts.models import User
from debexpo.packages.models import Package, PackageUpload, Distribution, \ from debexpo.packages.models import Package, PackageUpload, Distribution, \
...@@ -61,6 +64,7 @@ class TestCronjobRemoveOldUploads(TestController): ...@@ -61,6 +64,7 @@ class TestCronjobRemoveOldUploads(TestController):
('htop', '1.0.0', 'unstable', False), ('htop', '1.0.0', 'unstable', False),
('htop', '0.9.0', 'unstable', False), ('htop', '0.9.0', 'unstable', False),
('htop', '0.8.0', 'buster-backports', False), ('htop', '0.8.0', 'buster-backports', False),
('tmux', '1.1.0', 'unstable', False),
('tmux', '1.0.0', 'unstable', False), ('tmux', '1.0.0', 'unstable', False),
('tmux', '1.0.0', 'UNRELEASED', False), ('tmux', '1.0.0', 'UNRELEASED', False),
('zsh', '1.0.0', 'unstable', False), ('zsh', '1.0.0', 'unstable', False),
...@@ -194,7 +198,10 @@ class TestCronjobRemoveOldUploads(TestController): ...@@ -194,7 +198,10 @@ class TestCronjobRemoveOldUploads(TestController):
remove_old_uploads() remove_old_uploads()
self._assert_cronjob_success() self._assert_cronjob_success()
def test_remove_uploads_expired(self): @override_settings()
def test_remove_uploads_expired_no_gistorage(self):
del settings.GIT_STORAGE
self._setup_packages(include_expired=True) self._setup_packages(include_expired=True)
remove_old_uploads() remove_old_uploads()
self._assert_cronjob_success() self._assert_cronjob_success()
......
...@@ -62,3 +62,17 @@ class TestUser(TestCase): ...@@ -62,3 +62,17 @@ class TestUser(TestCase):
'password') 'password')
self.assertTrue(user.is_staff) self.assertTrue(user.is_staff)
self.assertTrue(user.is_superuser) self.assertTrue(user.is_superuser)
def test_lookup_user(self):
for unknown_email in (None, '', 'unknown@example.org',):
self.assertEquals(
None,
User.objects.lookup_user_from_address(unknown_email)
)
user = User.objects.create_user('email@example.com', 'test user',
'password')
self.assertEquals(
User.objects.lookup_user_from_address('User <email@example.com>'),
user
)
# test_bugs.py - Test debexpo Bug model
#
# This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo
#
# Copyright © 2022 Baptiste Beauplat <lyknode@debian.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from tests import TestController
from debexpo.bugs.models import Bug
class TestBugs(TestController):
def test_guess_packages(self):
# Normal bug
packages = Bug.objects._guess_packages(
'package1',
'FTBFS: with foo from experimental'
)
self.assertEquals(len(packages), 1)
self.assertEquals(packages[0].name, 'package1')
# Bug linked to multiple packages
packages = Bug.objects._guess_packages(
'package1,package2',
'FTBFS: with foo from experimental'
)
self.assertEquals(len(packages), 2)
self.assertEquals(packages[0].name, 'package1')
self.assertEquals(packages[1].name, 'package2')
# WNPP/sponsorship-requests
packages = Bug.objects._guess_packages(
'wnpp',
'ITP: foo -- A stable and useful software'
)
self.assertEquals(len(packages), 1)
self.assertEquals(packages[0].name, 'foo')
# WNPP/sponsorship-requests, wrong subject
packages = Bug.objects._guess_packages(
'wnpp',
'wait, there is a format for the subject?'
)
self.assertEquals(len(packages), 0)
...@@ -27,9 +27,11 @@ ...@@ -27,9 +27,11 @@
# OTHER DEALINGS IN THE SOFTWARE. # OTHER DEALINGS IN THE SOFTWARE.
from tests import TestController from tests import TestController
from types import SimpleNamespace
from debexpo.plugins.models import PluginManager, BasePlugin, PluginSeverity, \ from debexpo.plugins.models import PluginManager, BasePlugin, PluginSeverity, \
PluginResults PluginResults, ExceptionPlugin
from debexpo.plugins.maintaineremail import PluginMaintainerEmail
class PluginBad(BasePlugin): class PluginBad(BasePlugin):
...@@ -103,3 +105,15 @@ class TestPluginResults(TestController): ...@@ -103,3 +105,15 @@ class TestPluginResults(TestController):
result = PluginResults() result = PluginResults()
self.assertEquals(result.data, {}) self.assertEquals(result.data, {})
class TestPluginMaintainerEmail(TestController):
def test_maintainer_email_emtpy(self):
changes = SimpleNamespace()
changes.maintainer = ''
plugin = PluginMaintainerEmail()
with self.assertRaises(ExceptionPlugin) as e:
plugin.run(changes, None)
self.assertIn('No maintainer address found', str(e.exception))
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from tests import TestController from tests import TestController
from debexpo.packages.models import Package, Priority, Project, Distribution, \ from debexpo.packages.models import Package, Priority, Project, Distribution, \
Section, Component, BinaryPackage Section, Component, BinaryPackage, PackageUpload
class TestPackagesController(TestController): class TestPackagesController(TestController):
...@@ -62,3 +62,10 @@ class TestPackagesController(TestController): ...@@ -62,3 +62,10 @@ class TestPackagesController(TestController):
binary.delete() binary.delete()
self.assertEquals('', package.get_description()) self.assertEquals('', package.get_description())
def test_get_dsc_no_files(self):
package = Package.objects.get(name='testpackage')
upload = PackageUpload.objects.get(package=package)
self.assertEquals(None, upload.get_dsc_url())
self.assertEquals(None, upload.get_dsc_name())
# test_changes.py - unit testing for Changes
#
# This file is part of debexpo
# https://salsa.debian.org/mentors.debian.net-team/debexpo
#
# Copyright © 2019-2021 Baptiste Beauplat <lyknode@debian.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from tests import TestController
from os.path import join, dirname
from debexpo.tools.debian.changes import Changes
CHANGES_FILE_OK = join(dirname(__file__), '..', '..', '..', 'functional',
'importer', 'data', 'ok', 'hello_1.0-1_amd64.changes')
class TestChanges(TestController):
def test_dsc_from_changes(self):
changes = Changes(CHANGES_FILE_OK)
changes.validate()
changes.parse_dsc()
source = changes.get_source()
try:
source.extract()
source.parse_control_files()
finally:
source.remove()
self.assertEquals(source, changes.get_source())
...@@ -53,12 +53,19 @@ class TestMail(TestCase): ...@@ -53,12 +53,19 @@ class TestMail(TestCase):
self.email.send('My subject', []) self.email.send('My subject', [])
self.assertFalse(hasattr(self.email, 'email')) self.assertFalse(hasattr(self.email, 'email'))
def _assert_mail_content(self, content): def _assert_mail_content(self, content, bounce='bounce@example.org'):
self._assert_base_content(content.body) self._assert_base_content(content.body)
self.assertIn('user@example.org', content.to) self.assertIn('user@example.org', content.to)
self.assertIn('bounce@example.org', content.from_email) self.assertIn(bounce, content.from_email)
self.assertIn('From: debexpo <support@example.org>', self.assertIn('From: debexpo <support@example.org>',
str(content.message())) str(content.message()))
def _assert_base_content(self, content): def _assert_base_content(self, content):
self.assertIn('This is a test email, user@example.org', content) self.assertIn('This is a test email, user@example.org', content)
def test_bounce(self):
bounce = 'another@example.org'
self.email.send('My subject', ['user@example.org'],
bounce_to=bounce)
self._assert_mail_content(mail.outbox[0], bounce=bounce)
...@@ -18,7 +18,7 @@ setenv = ...@@ -18,7 +18,7 @@ setenv =
commands = commands =
coverage erase coverage erase
coverage run manage.py test -v 2 --exclude-tag nntp {posargs} coverage run --branch manage.py test -v 2 --exclude-tag nntp {posargs}
coverage report --include='debexpo*' --omit '*/nntp.py' coverage report --include='debexpo*' --omit '*/nntp.py'
coverage html --include='debexpo*' --omit '*/nntp.py' coverage html --include='debexpo*' --omit '*/nntp.py'
......
Supports Markdown
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