From 7e9088814688c191c1dda3fe8057a022d384cc07 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 6 Jan 2025 16:36:47 -0600 Subject: [PATCH] fix: add `get_effective_rows()` method for batch handler --- src/wuttjamaican/batch.py | 13 +++++++++++++ tests/test_batch.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/wuttjamaican/batch.py b/src/wuttjamaican/batch.py index c9ca664..98e8aa9 100644 --- a/src/wuttjamaican/batch.py +++ b/src/wuttjamaican/batch.py @@ -416,6 +416,19 @@ class BatchHandler(GenericHandler): :returns: Markdown text describing batch execution. """ + def get_effective_rows(self, batch): + """ + This should return a list of "effective" rows for the batch. + + In other words, which rows should be "acted upon" when the + batch is executed. + + The default logic returns the full list of batch + :attr:`~wuttjamaican.db.model.batch.BatchMixin.rows`, but + subclass may need to filter by status code etc. + """ + return batch.rows + def do_execute(self, batch, user, progress=None, **kwargs): """ Perform the execution steps for a batch. diff --git a/tests/test_batch.py b/tests/test_batch.py index 7d22244..7a2e643 100644 --- a/tests/test_batch.py +++ b/tests/test_batch.py @@ -130,6 +130,26 @@ else: self.session.flush() self.assertEqual(batch.row_count, 0) + def test_get_effective_rows(self): + model = self.app.model + handler = self.make_handler() + + user = model.User(username='barney') + self.session.add(user) + batch = handler.make_batch(self.session, created_by=user) + self.session.add(batch) + self.session.flush() + + self.assertEqual(handler.get_effective_rows(batch), []) + + row = handler.make_row() + handler.add_row(batch, row) + self.session.flush() + + rows = handler.get_effective_rows(batch) + self.assertEqual(len(rows), 1) + self.assertIs(rows[0], row) + def test_do_execute(self): model = self.app.model user = model.User(username='barney')