From 3900df9b3fa15b312e609342180d1ae49e8a9895 Mon Sep 17 00:00:00 2001 From: Mattia Rizzolo Date: Tue, 2 Oct 2018 20:47:08 +0200 Subject: [PATCH 01/19] setup.py: add an entry point that pylons 1.0 dropped https://github.com/Pylons/pylons/issues/13 Signed-off-by: Mattia Rizzolo --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index bab43e72..6a4d05bb 100644 --- a/setup.py +++ b/setup.py @@ -38,5 +38,8 @@ setup( debexpo-importer = debexpo.bin.debexpo_importer:main debexpo-worker = debexpo.bin.debexpo_worker debexpo-user-importer = debexpo.bin.user_importer:main + + [nose.plugins] + pylons = pylons.test:PylonsPlugin """, ) -- GitLab From a9583029cbf502ee0809f723f0eda688069cc1d7 Mon Sep 17 00:00:00 2001 From: Mattia Rizzolo Date: Tue, 2 Oct 2018 20:37:07 +0200 Subject: [PATCH 02/19] Add a .gitlab-ci.yml Signed-off-by: Mattia Rizzolo --- .gitlab-ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..1dfdf4cc --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +before_script: + - apt-get -q update + - env DEBIAN_FRONTEND=noninteractive apt-get -q -y install --no-install-recommends aspcud apt-cudf + - env DEBIAN_FRONTEND=noninteractive apt-get -q -y --solver aspcud -o APT::Solver::Strict-Pinning=0 -o Debug::pkgProblemResolver=yes install --no-install-recommends + python-sqlalchemy python-pylons python-debian python-babel iso-codes + +.test_template: &test + script: + - python2.7 setup.py test + +unstable: + <<: *test + image: debian:unstable + +#testing: +# <<: *test +# image: debian:testing + +stable-bpo: + <<: *test + image: debian:stable-backports -- GitLab From d8330c2bfe66a75850012a379c43ceeec863e4bb Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 7 Oct 2018 23:16:08 +0200 Subject: [PATCH 03/19] Add dependencies for CI --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1dfdf4cc..aaaf4750 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ before_script: - apt-get -q update - env DEBIAN_FRONTEND=noninteractive apt-get -q -y install --no-install-recommends aspcud apt-cudf - env DEBIAN_FRONTEND=noninteractive apt-get -q -y --solver aspcud -o APT::Solver::Strict-Pinning=0 -o Debug::pkgProblemResolver=yes install --no-install-recommends - python-sqlalchemy python-pylons python-debian python-babel iso-codes + python-sqlalchemy python-pylons python-debian python-babel iso-codes gnupg python-apt python-lxml .test_template: &test script: -- GitLab From f8e6b47092016cb168753809d42bf24692d02c34 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 7 Oct 2018 23:32:54 +0200 Subject: [PATCH 04/19] Add missing config keys to test.ini --- development.ini | 2 ++ test.ini | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/development.ini b/development.ini index 1c9b69de..a43360dc 100644 --- a/development.ini +++ b/development.ini @@ -109,6 +109,8 @@ debexpo.cronjob_delay = 60 # NNTP server to connect to fetch mailing list comments/changes debexpo.nntp_server = news.gmane.org +debexpo.enable_experimental_code = false + # Logging configuration [loggers] keys = root, debexpo diff --git a/test.ini b/test.ini index 2a9a438e..8170a9af 100644 --- a/test.ini +++ b/test.ini @@ -62,6 +62,12 @@ debexpo.gpg_path = /usr/bin/gpg # Server debexpo is being run on including http:// and excluding trailing slash debexpo.server = http://localhost:5000 +debexpo.sitetitle = Testing + +debexpo.gpg_keyring = /tmp/keyring + +debexpo.enable_experimental_code = False + [loggers] keys = root, debexpo -- GitLab From 1fd6ad9057be7cbbe8a27e77dec30d87a9ef122a Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Wed, 10 Oct 2018 22:10:30 +0200 Subject: [PATCH 05/19] Add compile assets --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aaaf4750..d8ea0888 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ before_script: .test_template: &test script: + - python2.7 setup.py compile_catalog - python2.7 setup.py test unstable: -- GitLab From 772e418262e0d5702a533e27f93833ad0a709e1b Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 14 Oct 2018 00:33:10 +0200 Subject: [PATCH 06/19] Create upload directory for CI --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d8ea0888..7583b23b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ before_script: .test_template: &test script: + - mkdir -p /tmp/debexpo/pub - python2.7 setup.py compile_catalog - python2.7 setup.py test -- GitLab From 5b53d3c06081c3ff90fd2ec14e6768bfaf53d49f Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Thu, 11 Oct 2018 19:39:54 +0200 Subject: [PATCH 07/19] Fix gpg tests with setup/cleanup gpg env --- debexpo/tests/functional/test_my.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/debexpo/tests/functional/test_my.py b/debexpo/tests/functional/test_my.py index 9e1f1453..336eea96 100644 --- a/debexpo/tests/functional/test_my.py +++ b/debexpo/tests/functional/test_my.py @@ -4,6 +4,9 @@ from debexpo.model import meta from debexpo.model.users import User from debexpo.model.user_countries import UserCountry import md5 +import tempfile +import os +import shutil class TestMyController(TestController): _GPGKEY = """-----BEGIN PGP PUBLIC KEY BLOCK----- @@ -39,7 +42,15 @@ ABRL0EeYuGCJYJRQsw8e8JuRSaVGwfotqkIHtQ== """ _GPG_ID = '2048R/6758261E' + def _setup_gpg_env(self): + self.homedir = tempfile.mkdtemp() + os.environ['GNUPGHOME'] = self.homedir + + def _cleanup_gpg_env(self): + shutil.rmtree(self.homedir) + def setUp(self): + self._setup_gpg_env() self._setup_models() self._setup_example_user() self._setup_example_countries() @@ -47,6 +58,7 @@ ABRL0EeYuGCJYJRQsw8e8JuRSaVGwfotqkIHtQ== def tearDown(self): self._remove_example_user() self._remove_example_countries() + self._cleanup_gpg_env() def test_index(self): response = self.app.get(url(controller='my', action='index')) -- GitLab From eba1ac5e7ec7abb95519f1704b29aca08d08b1ac Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Thu, 11 Oct 2018 20:19:01 +0200 Subject: [PATCH 08/19] Add missing user setup for TestPackagesController --- debexpo/tests/functional/test_packages.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debexpo/tests/functional/test_packages.py b/debexpo/tests/functional/test_packages.py index e3f094db..0c8d1ccf 100644 --- a/debexpo/tests/functional/test_packages.py +++ b/debexpo/tests/functional/test_packages.py @@ -2,6 +2,13 @@ from debexpo.tests import * class TestPackagesController(TestController): + def setUp(self): + self._setup_models() + self._setup_example_user() + + def tearDown(self): + self._remove_example_user() + def test_index(self): response = self.app.get(url(controller='packages', action='index')) self.assertEquals(200, response.status_int) -- GitLab From 66d2c9a5ba52f43808840c6bfe3f87b9fe6f673c Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Thu, 11 Oct 2018 20:31:42 +0200 Subject: [PATCH 09/19] Remove ppa controller test (ppa controller removed by e2cfc0cf91cb67608e00cbae365e18101c863f03) --- debexpo/tests/functional/test_ppa.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 debexpo/tests/functional/test_ppa.py diff --git a/debexpo/tests/functional/test_ppa.py b/debexpo/tests/functional/test_ppa.py deleted file mode 100644 index fc4a3121..00000000 --- a/debexpo/tests/functional/test_ppa.py +++ /dev/null @@ -1,7 +0,0 @@ -from debexpo.tests import * - -class TestPpaController(TestController): - - def test_index(self): - response = self.app.get(url(controller='ppa', action='index')) - # Test response... -- GitLab From 2aeff0f7a012fcecac77c9d88787c39f6cc3600c Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Thu, 11 Oct 2018 22:35:06 +0200 Subject: [PATCH 10/19] Remove unused route /register/index (includes controller, template and routing) --- debexpo/config/routing.py | 1 - debexpo/controllers/register.py | 12 ------------ debexpo/templates/register/index.mako | 27 --------------------------- 3 files changed, 40 deletions(-) delete mode 100644 debexpo/templates/register/index.mako diff --git a/debexpo/config/routing.py b/debexpo/config/routing.py index 09237d60..1c379f6c 100644 --- a/debexpo/config/routing.py +++ b/debexpo/config/routing.py @@ -89,7 +89,6 @@ def make_map(config): #map.connect('packages_filter_feed', '/packages/{filter}/{id}/feed', controller='packages', action='feed') #map.connect('packages_feed', '/packages/feed', controller='packages', action='feed') map.connect('qa', '/qa', controller='index', action='qa') - #map.connect('register', '/register/{action}/{id}', controller='register', action='index', id=None) # LEGACY ROUTE. CAN BE REMOVED LATER map.connect('/upload/{email}/{password}/{filename}', controller='upload', diff --git a/debexpo/controllers/register.py b/debexpo/controllers/register.py index e545306d..e6ffcc62 100644 --- a/debexpo/controllers/register.py +++ b/debexpo/controllers/register.py @@ -60,18 +60,6 @@ class RegisterController(BaseController): """ c.config = config - def index(self): - """ - Entry point to controller. Displays the index page. - """ - log.debug('Main register form requested') - - if config['debexpo.debian_specific'] != 'true': - log.error('debexpo.debian_specific is !true; redirecting to maintainer form') - redirect(url(action='maintainer')) - - return render('/register/index.mako') - def _send_activate_email(self, key, recipient): """ Sends an activation email to the potential new user. diff --git a/debexpo/templates/register/index.mako b/debexpo/templates/register/index.mako deleted file mode 100644 index ba74a954..00000000 --- a/debexpo/templates/register/index.mako +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- - -<%inherit file="../base.mako"/> - -

${ _('Sign up for your own account at %s') % c.config['debexpo.sitename'] }

- -

- ${ _('What type of account would you like to apply for?') } -

- -

${ _('Package Maintainer') }

- -

- ${ _('''A package maintainer is a person who takes care of Debian packages. - If you create Debian packages from certain pieces of (so called - "upstream") software then you are a maintainer. You do not need to be - an official Debian Developer (DD) or Debian Maintainer (DM).''') } -

- -

${ _('Sponsor') }

- -

- ${ _('''Uploading new packages into Debian is only possible if you - are a Debian Developer (DD) or Debian Maintainer (DM). If you want - to help package maintainers to get their packages into Debian you - can be a sponsor and check and upload packages on their behalf.''')} -

-- GitLab From 50825d9a6cf59a6380beabf193c62c925114a723 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Thu, 11 Oct 2018 22:41:41 +0200 Subject: [PATCH 11/19] Fix test register controller: adding 'sponsor' to submit form --- debexpo/tests/functional/test_register.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/debexpo/tests/functional/test_register.py b/debexpo/tests/functional/test_register.py index 0a2359e0..d8debf70 100644 --- a/debexpo/tests/functional/test_register.py +++ b/debexpo/tests/functional/test_register.py @@ -4,16 +4,20 @@ from debexpo.model.users import User class TestRegisterController(TestController): + def setUp(self): + self._setup_models() + def test_maintainer_signup(self, actually_delete_it=True): count = meta.session.query(User).filter(User.email=='mr_me@example.com').count() self.assertEquals(count, 0) - self.app.post(url(controller='register', action='maintainer'), + self.app.post(url(controller='register', action='register'), {'name': 'Mr. Me', 'password': 'password', 'password_confirm': 'password', 'commit': 'yes', - 'email': 'mr_me@example.com'}) + 'email': 'mr_me@example.com', + 'sponsor': '0'}) count = meta.session.query(User).filter(User.email=='mr_me@example.com').count() self.assertEquals(count, 1) @@ -28,12 +32,13 @@ class TestRegisterController(TestController): def test_maintainer_signup_with_duplicate_name(self): self.test_maintainer_signup(actually_delete_it=False) - self.app.post(url(controller='register', action='maintainer'), + self.app.post(url(controller='register', action='register'), {'name': 'Mr. Me', 'password': 'password', 'password_confirm': 'password', 'commit': 'yes', - 'email': 'mr_me_again@example.com'}) + 'email': 'mr_me_again@example.com', + 'sponsor': '0'}) count = meta.session.query(User).filter(User.email=='mr_me_again@example.com').count() self.assertEquals(count, 0) -- GitLab From 59aa0313f9cd3c44903e6ecc49a88cb2433b614b Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sat, 13 Oct 2018 20:02:36 +0200 Subject: [PATCH 12/19] Fix test controller for package upload * Add test to cover duplicate upload * Delete all tests/references to authentication --- debexpo/tests/functional/test_upload.py | 83 ++++++++++--------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/debexpo/tests/functional/test_upload.py b/debexpo/tests/functional/test_upload.py index e1c8cc8e..52b29d29 100644 --- a/debexpo/tests/functional/test_upload.py +++ b/debexpo/tests/functional/test_upload.py @@ -50,10 +50,6 @@ class TestUploadController(TestController): """ TestController.__init__(self, *args, **kwargs) - # Keep this so tests don't have to constantly create it. - self.user_upload_key = 'upload_key' - self.email = 'email@example.com' - def setUp(self): self._setup_models() self._setup_example_user() @@ -66,56 +62,16 @@ class TestUploadController(TestController): Tests whether requests where method != PUT are rejected with error code 405. """ response = self.app.get(url(controller='upload', action='index', - email=self.email, password=self.user_upload_key, filename='testname.dsc'), expect_errors=True) self.assertEqual(response.status_int, 405) - def testNoAuthorization(self): - """ - Tests whether requests where the "Authorization" header is missing are rejected with - error code 401 and whether the "WWW-Authenticate" header is sent in the response with - the correct "realm" syntax. - """ - response = self.app.put( - url(controller='upload', action='index', - filename='testname.dsc', email='email', password='pass'), expect_errors=True) - - self.assertEqual(response.status_int, 403) - - def testFalseAuthentication(self): - """ - Tests whether false authentication details returns a 403 error code. - """ - response = self.app.put(url(controller='upload', action='index', - filename='testname.dsc', email=self.email, - password='wrong'), - expect_errors=True) - - self.assertEqual(response.status_int, 403) - - def testTrueAuthentication(self): - """ - Tests whether true authentication details returns a nicer error code. - """ - response = self.app.put(url(controller='upload', action='index', - filename='testname.dsc', email=self.email, - password=self.user_upload_key), - expect_errors=False) - - self.assertNotEqual(response.status_int, 403) - app_config = pylons.test.pylonsapp.config - - if os.path.isfile(os.path.join(app_config['debexpo.upload.incoming'], 'testfile1.dsc')): - os.remove(os.path.join(app_config['debexpo.upload.incoming'], 'testfile1.dsc')) - def testExtensionNotAllowed(self): """ Tests whether uploads of an unknown file extensions are rejected with error code 403. """ response = self.app.put(url(controller='upload', action='index', - filename='testname.unknown', email=self.email, - password=self.user_upload_key), + filename='testname.unknown'), expect_errors=True) self.assertEqual(response.status_int, 403) @@ -126,19 +82,46 @@ class TestUploadController(TestController): """ response = self.app.put(url( controller='upload', action='index', - filename='testfile2.dsc', - email=self.email, - password=self.user_upload_key), + filename='testfile2.dsc'), params='contents', expect_errors=False) self.assertEqual(response.status_int, 200) app_config = pylons.test.pylonsapp.config self.assertTrue(os.path.isfile(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile2.dsc'))) self.assertEqual(file(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile2.dsc')).read(), 'contents') - if os.path.isfile(os.path.join(app_config['debexpo.upload.incoming'], 'testfile2.dsc')): - os.remove(os.path.join(app_config['debexpo.upload.incoming'], 'testfile2.dsc')) + if os.path.isfile(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile2.dsc')): + os.remove(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile2.dsc')) + + def testDuplicatedUpload(self): + """ + Tests whether a re-uploads of the same file failed with error code 403. + """ + response = self.app.put(url( + controller='upload', action='index', + filename='testfile.dsc'), + params='contents', expect_errors=False) + + self.assertEqual(response.status_int, 200) + + response = self.app.put(url( + controller='upload', action='index', + filename='testfile.dsc'), + params='contents', expect_errors=True) + + self.assertEqual(response.status_int, 403) + + app_config = pylons.test.pylonsapp.config + + if os.path.isfile(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile.dsc')): + os.remove(os.path.join(app_config['debexpo.upload.incoming'], + 'pub', 'testfile.dsc')) -- GitLab From 0ca78dcd8d74e4bef481397acdfb4ba846a510f6 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sat, 13 Oct 2018 20:12:36 +0200 Subject: [PATCH 13/19] Fix Changes class. basename is only called on a file --- debexpo/lib/changes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/debexpo/lib/changes.py b/debexpo/lib/changes.py index 85714989..5999fe5b 100644 --- a/debexpo/lib/changes.py +++ b/debexpo/lib/changes.py @@ -69,12 +69,13 @@ class Changes(object): if filename: self._data = deb822.Changes(file(filename)) + self.basename = os.path.basename(filename) + if len(self._data) == 0: + raise Exception('Changes file {} could not be parsed'.format(self.basename)) else: self._data = deb822.Changes(string) - - if len(self._data) == 0: - raise Exception('Changes file could not be parsed.') - self.basename = os.path.basename(filename) + if len(self._data) == 0: + raise Exception('Changes file could not be parsed.') def get_filename(self): """ -- GitLab From 86638012fee23a7335e2891e8c4afc6d10f32001 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sat, 13 Oct 2018 20:35:15 +0200 Subject: [PATCH 14/19] Fix test controller for utils * Use CheckFiles() for allowed_upload * Use an existing component for testing * Return parse_section result as an array --- debexpo/lib/utils.py | 4 ++-- debexpo/tests/test_utils.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/debexpo/lib/utils.py b/debexpo/lib/utils.py index a630fa94..162b1345 100644 --- a/debexpo/lib/utils.py +++ b/debexpo/lib/utils.py @@ -59,9 +59,9 @@ def parse_section(section): component, thesection = section.split('/', 1) if component not in ("main", "contrib", "non-free"): log.warning("Parsing weird component %s, assuming main" % component) - return main, section.replace('/', '_') + return ['main', section.replace('/', '_')] else: - return component, thesection + return [component, thesection] else: return ['main', section] diff --git a/debexpo/tests/test_utils.py b/debexpo/tests/test_utils.py index 71d08b5f..8e37067a 100644 --- a/debexpo/tests/test_utils.py +++ b/debexpo/tests/test_utils.py @@ -39,6 +39,7 @@ from unittest import TestCase from debexpo.lib.utils import * from debexpo.lib.changes import Changes +from debexpo.lib.filesystem import CheckFiles class TestUtilsController(TestCase): @@ -46,7 +47,7 @@ class TestUtilsController(TestCase): """ Tests debexpo.lib.utils.allowed_upload. """ - t = allowed_upload + t = CheckFiles().allowed_upload self.assertTrue(t('foo_version.orig.tar.gz')) self.assertTrue(t('foo_version.tar.gz')) @@ -64,7 +65,7 @@ class TestUtilsController(TestCase): t = parse_section self.assertEqual(t('section'), ['main', 'section']) - self.assertEqual(t('component/section'), ['component', 'section']) + self.assertEqual(t('contrib/section'), ['contrib', 'section']) def testGetPackageDir(self): """ -- GitLab From 09e896389e24a76341d4c2f217efd793411212b7 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sat, 13 Oct 2018 21:01:46 +0200 Subject: [PATCH 15/19] Fix test controller index --- debexpo/tests/functional/test_index.py | 34 +++++--------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/debexpo/tests/functional/test_index.py b/debexpo/tests/functional/test_index.py index 6f3f45fc..6b4a7a58 100644 --- a/debexpo/tests/functional/test_index.py +++ b/debexpo/tests/functional/test_index.py @@ -24,19 +24,12 @@ class TestIndexController(TestController): def test_index(self): # test a normal index page testurl = url(controller='index', action='index') + pylons.test.pylonsapp.config['debexpo.sitename'] = 'test index' response = self.app.get(testurl) - self.assertEquals(response.status_int, 200) - - testtext = '

A test front page

' - pylons.test.pylonsapp.config['debexpo.html.frontpage'] = \ - self._generate_temppage('front.html', testtext) - - response = self.app.get(testurl) + testtext = '

Welcome to test index

' self.assertEquals(response.status_int, 200) self.assertTrue(testtext in response) - del pylons.test.pylonsapp.config['debexpo.html.frontpage'] - def test_contact(self): response = self.app.get(url(controller='index', action='contact')) self.assertEquals(response.status_int, 200) @@ -44,29 +37,14 @@ class TestIndexController(TestController): def test_intro_maintainers(self): testurl = url('intro-maintainers') response = self.app.get(testurl) - self.assertEquals(response.status_int, 200) - - testtext = '

A maintainer intro page

' - pylons.test.pylonsapp.config['debexpo.html.maintainer_intro'] = \ - self._generate_temppage('maintainer_intro.html', testtext) - - response = self.app.get(testurl) + testtext = "{}".format('

Introduction for maintainers: How will my', + ' package get into Debian

') self.assertEquals(response.status_int, 200) self.assertTrue(testtext in response) - del pylons.test.pylonsapp.config['debexpo.html.maintainer_intro'] - def test_intro_sponsors(self): - testurl = url('intro-sponsors') - response = self.app.get(testurl) - self.assertEquals(response.status_int, 200) - - testtext = '

A sponsor intro page

' - pylons.test.pylonsapp.config['debexpo.html.sponsors_intro'] = \ - self._generate_temppage('sponsor_intro.html', testtext) - + testurl = url('sponsors') response = self.app.get(testurl) + testtext = '

The sponsoring process

' self.assertEquals(response.status_int, 200) self.assertTrue(testtext in response) - - del pylons.test.pylonsapp.config['debexpo.html.sponsors_intro'] -- GitLab From d0e2f88d2d7633ea79aa46bfb5b4fcfd0cf013d1 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sat, 13 Oct 2018 23:19:14 +0200 Subject: [PATCH 16/19] Fix test controller for package * Add test to avoid deleting inexistant files on package deletion * Remove rfs test as it's not part of package anymore * Update routes on package tests --- debexpo/lib/filesystem.py | 2 + debexpo/tests/functional/test_package.py | 47 +++++++++++------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/debexpo/lib/filesystem.py b/debexpo/lib/filesystem.py index bc5d556a..8b5425f2 100644 --- a/debexpo/lib/filesystem.py +++ b/debexpo/lib/filesystem.py @@ -208,6 +208,8 @@ class CheckFiles(object): ```package``` package object whose files are supposed to be removed """ files = self.find_files_for_package(package, absolute_path=True) + if not files: + return path = os.path.dirname(files[0]) for file in files: if os.path.exists(file): diff --git a/debexpo/tests/functional/test_package.py b/debexpo/tests/functional/test_package.py index 18d7648b..615f5f96 100644 --- a/debexpo/tests/functional/test_package.py +++ b/debexpo/tests/functional/test_package.py @@ -47,6 +47,8 @@ class TestPackageController(TestController): self._remove_example_user() def test_index(self): + user = meta.session.query(User).filter( + User.email=='email@example.com').one() response = self.app.get(url(controller='package', action='index')) self.assertEquals(response.status_int, 302) self.assertTrue(response.location.endswith( @@ -60,8 +62,8 @@ class TestPackageController(TestController): packagename='testpackage')) self.assertEquals(response.status_int, 200) self.assertEquals(len(response.lxml.xpath( - '//a[@href="%s"]' % url( - 'packages-uploader', + '//a[@href="%s"]' % url(controller='packages', + action='uploader', id='email@example.com'))), 1) response = self.app.post(url('login'), self._AUTHDATA) response = self.app.get(url(controller='package', action='index', @@ -70,22 +72,13 @@ class TestPackageController(TestController): self.assertEquals(len(response.lxml.xpath( '//a[@href="%s"]' % url( controller='package', action='delete', - packagename='testpackage'))), 1) + packagename='testpackage', + key=user.get_upload_key()))), 1) self.assertEquals(len(response.lxml.xpath( '//form[@action="%s"]' % url( controller='package', action='comment', packagename='testpackage'))), 1) - def test_rfs(self): - response = self.app.get(url(controller='package', action='rfs')) - self.assertEquals(response.status_int, 302) - self.assertTrue(response.location.endswith( - url(controller='packages', action='index', packagename=None))) - response = self.app.get(url(controller='package', action='rfs', - packagename='testpackage')) - self.assertEquals(response.status_int, 200) - self.assertTrue('Subject: RFS: testpackage' in response) - def test_subscribe(self): response = self.app.get(url(controller='package', action='subscribe', packagename='testpackage')) @@ -157,31 +150,35 @@ class TestPackageController(TestController): self.assertEquals(subs, None) def test_delete(self): - response = self.app.get(url(controller='package', action='delete', - packagename='testpackage')) + user = meta.session.query(User).filter( + User.email=='email@example.com').one() + response = self.app.get(url( + controller='package', action='delete', packagename='testpackage', + key=user.get_upload_key())) self.assertEquals(response.status_int, 302) self.assertTrue(response.location.endswith(url('login'))) self.app.post(url('login'), self._AUTHDATA) - response = self.app.get(url(controller='package', action='delete', - packagename='testpackage')) + response = self.app.get(url( + controller='package', action='delete', packagename='testpackage', + key=user.get_upload_key())) self.assertEquals(response.status_int, 302) self.assertTrue(response.location.endswith( - url(controller='packages', action='index', filter='my'))) + url(controller='packages', action='my'))) package = meta.session.query(Package).filter( Package.name=='testpackage').first() self.assertEquals(package, None) def test_comment(self): - response = self.app.get(url(controller='package', action='comment', - packagename='testpackage')) + response = self.app.post( + url(controller='package', action='comment', + packagename='testpackage'), + {'package_version': 1, + 'text': 'This is a test comment', + 'outcome': constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED, + 'commit': 'submit'}) self.assertEquals(response.status_int, 302) self.assertTrue(response.location.endswith(url('login'))) self.app.post(url('login'), self._AUTHDATA) - response = self.app.get(url(controller='package', action='comment', - packagename='testpackage')) - self.assertEquals(response.status_int, 200) - self.assertEquals(4, len(response.lxml.xpath( - '//span[@class="error-message"]'))) response = self.app.post( url(controller='package', action='comment', packagename='testpackage'), -- GitLab From 872692504272764e24f7e6c522978c2a5b3ab856 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 14 Oct 2018 00:20:10 +0200 Subject: [PATCH 17/19] Mail can be saved as file in case of testing --- debexpo/lib/email.py | 11 +++++++++++ debexpo/tests/functional/test_package.py | 2 ++ debexpo/tests/functional/test_register.py | 2 ++ 3 files changed, 15 insertions(+) diff --git a/debexpo/lib/email.py b/debexpo/lib/email.py index 543a7388..224fecd1 100644 --- a/debexpo/lib/email.py +++ b/debexpo/lib/email.py @@ -146,6 +146,17 @@ class Email(object): pylons.url._pop_object() + if 'debexpo.testsmtp' in pylons.config: + self._save_as_file(recipients, message) + else: + self._send_as_mail(recipients, message) + + def _save_as_file(self, recipients, message): + log.debug('Save email as file to %s' % self.server) + with open(pylons.config['debexpo.testsmtp'], 'a') as email: + email.write(message) + + def _send_as_mail(self, recipients, message): log.debug('Starting SMTP session to %s' % self.server) session = smtplib.SMTP(self.server) diff --git a/debexpo/tests/functional/test_package.py b/debexpo/tests/functional/test_package.py index 615f5f96..1febfb7d 100644 --- a/debexpo/tests/functional/test_package.py +++ b/debexpo/tests/functional/test_package.py @@ -8,6 +8,7 @@ from debexpo.model.package_versions import PackageVersion from debexpo.model.source_packages import SourcePackage from debexpo.model.package_subscriptions import PackageSubscription from datetime import datetime +import pylons.test class TestPackageController(TestController): @@ -197,6 +198,7 @@ class TestPackageController(TestController): constants.PACKAGE_COMMENT_STATUS_NOT_UPLOADED) meta.session.delete(comment) # test with a subscriber + pylons.test.pylonsapp.config['debexpo.testsmtp'] = '/tmp/debexpo.msg' user = meta.session.query(User).filter(User.email=='email@example.com').one() packsub = PackageSubscription( package='testpackage', diff --git a/debexpo/tests/functional/test_register.py b/debexpo/tests/functional/test_register.py index d8debf70..f68f5508 100644 --- a/debexpo/tests/functional/test_register.py +++ b/debexpo/tests/functional/test_register.py @@ -1,6 +1,7 @@ from debexpo.tests import TestController, url from debexpo.model import meta from debexpo.model.users import User +import pylons.test class TestRegisterController(TestController): @@ -11,6 +12,7 @@ class TestRegisterController(TestController): count = meta.session.query(User).filter(User.email=='mr_me@example.com').count() self.assertEquals(count, 0) + pylons.test.pylonsapp.config['debexpo.testsmtp'] = '/tmp/debexpo.msg' self.app.post(url(controller='register', action='register'), {'name': 'Mr. Me', 'password': 'password', -- GitLab From 89bc0d06a3ff39085cee93ad49906d85ba257717 Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 14 Oct 2018 12:16:10 +0200 Subject: [PATCH 18/19] Add code coverage for CI --- .gitlab-ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7583b23b..c6ca2415 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,13 +2,17 @@ before_script: - apt-get -q update - env DEBIAN_FRONTEND=noninteractive apt-get -q -y install --no-install-recommends aspcud apt-cudf - env DEBIAN_FRONTEND=noninteractive apt-get -q -y --solver aspcud -o APT::Solver::Strict-Pinning=0 -o Debug::pkgProblemResolver=yes install --no-install-recommends - python-sqlalchemy python-pylons python-debian python-babel iso-codes gnupg python-apt python-lxml + python-sqlalchemy python-pylons python-debian python-babel iso-codes gnupg python-apt python-lxml python-coverage .test_template: &test script: - mkdir -p /tmp/debexpo/pub + - python2.7 setup.py develop - python2.7 setup.py compile_catalog - - python2.7 setup.py test + - python2.7 setup.py nosetests --with-coverage --cover-erase --cover-html + artifacts: + paths: + - cover/ unstable: <<: *test -- GitLab From c746db1182f0378a32b410e6492f79f29c3fa93a Mon Sep 17 00:00:00 2001 From: Baptiste BEAUPLAT Date: Sun, 14 Oct 2018 15:28:01 +0200 Subject: [PATCH 19/19] Adjust pylons language workaround to work with webob > 1.6.2 --- debexpo/lib/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debexpo/lib/base.py b/debexpo/lib/base.py index 33d9a7de..6fa53caf 100644 --- a/debexpo/lib/base.py +++ b/debexpo/lib/base.py @@ -117,7 +117,7 @@ class BaseController(WSGIController): # Set language according to what the browser requested try: languages = request.languages - except AttributeError: + except (AttributeError, TypeError): log.debug("Working around Pylons request.languages bug") languages = [] -- GitLab