From 33855853d4dd98eac3d00ff7a22da013c5b0a69c Mon Sep 17 00:00:00 2001 From: Travis Briggs Date: Sat, 4 May 2024 10:46:43 +0200 Subject: [PATCH] Don't allow empty include lists --- wp1/selection/models/wikiproject.py | 5 ++++- wp1/selection/models/wikiproject_test.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wp1/selection/models/wikiproject.py b/wp1/selection/models/wikiproject.py index 7d493e11..bf1f2fcd 100644 --- a/wp1/selection/models/wikiproject.py +++ b/wp1/selection/models/wikiproject.py @@ -25,6 +25,9 @@ def build(self, content_type, **params): raise Wp1FatalSelectionError('Missing param `wp10db`') if 'include' not in params: raise Wp1FatalSelectionError('Missing param `include`') + if not params['include']: + raise Wp1FatalSelectionError( + 'Cannot create selection with empty `include` list') included_articles = set() for project in params['include']: @@ -42,7 +45,7 @@ def build(self, content_type, **params): def validate(self, **params): if 'wp10db' not in params: raise Wp1FatalSelectionError('Cannot validate without param `wp10db`') - if 'include' not in params: + if 'include' not in params or not params['include']: return ([], [], ['Missing articles to include']) valid = [] diff --git a/wp1/selection/models/wikiproject_test.py b/wp1/selection/models/wikiproject_test.py index 3b65ed31..b280c311 100644 --- a/wp1/selection/models/wikiproject_test.py +++ b/wp1/selection/models/wikiproject_test.py @@ -63,6 +63,11 @@ def test_validate_missing_include(self): actual = self.builder.validate(wp10db=self.wp10db, **params) self.assertEqual(([], [], ['Missing articles to include']), actual) + def test_validate_empty_include(self): + params = {'include': [], 'exclude': ['Water Elements', 'Fire']} + actual = self.builder.validate(wp10db=self.wp10db, **params) + self.assertEqual(([], [], ['Missing articles to include']), actual) + def test_validate_missing_exclude(self): params = {'include': ['Water Elements', 'Fire']} actual = self.builder.validate(wp10db=self.wp10db, **params) @@ -142,3 +147,10 @@ def test_build_missing_include(self): self.builder.build('text/tab-separated-values', wp10db=self.wp10db, **params) + + def test_build_empty_include(self): + params = {'include': [], 'exclude': ['Fire']} + with self.assertRaises(Wp1FatalSelectionError): + self.builder.build('text/tab-separated-values', + wp10db=self.wp10db, + **params)