Skip to content

Commit

Permalink
Don't allow empty include lists
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed May 4, 2024
1 parent 5689513 commit 3385585
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion wp1/selection/models/wikiproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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 = []
Expand Down
12 changes: 12 additions & 0 deletions wp1/selection/models/wikiproject_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 3385585

Please sign in to comment.