fix: add get_effective_rows()
method for batch handler
This commit is contained in:
parent
60a25ab342
commit
7e90888146
|
@ -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.
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue