feat: add basic batch feature, data model and partial handler
hopefully data model is complete enough for now, but handler does not yet have all methods, e.g. execute()
This commit is contained in:
parent
51accc5a93
commit
a514d9cfba
9 changed files with 813 additions and 1 deletions
70
tests/test_batch.py
Normal file
70
tests/test_batch.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from wuttjamaican import batch as mod
|
||||
|
||||
try:
|
||||
import sqlalchemy as sa
|
||||
from wuttjamaican.db import model
|
||||
from wuttjamaican.testing import DataTestCase
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
|
||||
class MockBatch(model.BatchMixin, model.Base):
|
||||
__tablename__ = 'testing_batch_mock'
|
||||
|
||||
class MockBatchRow(model.BatchRowMixin, model.Base):
|
||||
__tablename__ = 'testing_batch_mock_row'
|
||||
__batch_class__ = MockBatch
|
||||
|
||||
class MockBatchHandler(mod.BatchHandler):
|
||||
model_class = MockBatch
|
||||
|
||||
class TestBatchHandler(DataTestCase):
|
||||
|
||||
def make_handler(self, **kwargs):
|
||||
return MockBatchHandler(self.config, **kwargs)
|
||||
|
||||
def test_model_class(self):
|
||||
handler = mod.BatchHandler(self.config)
|
||||
self.assertRaises(NotImplementedError, getattr, handler, 'model_class')
|
||||
|
||||
def test_make_batch(self):
|
||||
handler = self.make_handler()
|
||||
batch = handler.make_batch(self.session)
|
||||
self.assertIsInstance(batch, MockBatch)
|
||||
|
||||
def test_consume_batch_id(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
first = handler.consume_batch_id(self.session)
|
||||
second = handler.consume_batch_id(self.session)
|
||||
self.assertEqual(second, first + 1)
|
||||
|
||||
third = handler.consume_batch_id(self.session, as_str=True)
|
||||
self.assertEqual(third, f'{first + 2:08d}')
|
||||
|
||||
def test_should_populate(self):
|
||||
handler = self.make_handler()
|
||||
batch = handler.make_batch(self.session)
|
||||
self.assertFalse(handler.should_populate(batch))
|
||||
|
||||
def test_do_populate(self):
|
||||
handler = self.make_handler()
|
||||
batch = handler.make_batch(self.session)
|
||||
# nb. coverage only; tests nothing
|
||||
handler.do_populate(batch)
|
||||
|
||||
def test_make_row(self):
|
||||
handler = self.make_handler()
|
||||
row = handler.make_row()
|
||||
self.assertIsInstance(row, MockBatchRow)
|
||||
|
||||
def test_add_row(self):
|
||||
handler = self.make_handler()
|
||||
batch = handler.make_batch(self.session)
|
||||
self.session.add(batch)
|
||||
row = handler.make_row()
|
||||
self.assertIsNone(batch.row_count)
|
||||
handler.add_row(batch, row)
|
||||
self.assertEqual(batch.row_count, 1)
|
Loading…
Add table
Add a link
Reference in a new issue