Add stamper to update task

This commit is contained in:
Joakim Soderlund 2017-11-04 20:41:22 +01:00
parent 81c4346f10
commit d9619e993a
2 changed files with 22 additions and 1 deletions

View file

@ -32,6 +32,7 @@ from fimfarchive.flavors import DataFormat, UpdateStatus
from fimfarchive.mappers import StoryPathMapper from fimfarchive.mappers import StoryPathMapper
from fimfarchive.selectors import Selector, UpdateSelector from fimfarchive.selectors import Selector, UpdateSelector
from fimfarchive.signals import Signal, SignalSender from fimfarchive.signals import Signal, SignalSender
from fimfarchive.stampers import Stamper, UpdateStamper
from fimfarchive.stories import Story from fimfarchive.stories import Story
from fimfarchive.utils import PersistedDict from fimfarchive.utils import PersistedDict
from fimfarchive.writers import DirectoryWriter from fimfarchive.writers import DirectoryWriter
@ -75,6 +76,7 @@ class UpdateTask(SignalSender):
fimfarchive: Fetcher, fimfarchive: Fetcher,
fimfiction: Fetcher, fimfiction: Fetcher,
selector: Selector = None, selector: Selector = None,
stamper: Stamper = None,
workdir: str = DEFAULT_WORKDIR, workdir: str = DEFAULT_WORKDIR,
retries: int = DEFAULT_RETRIES, retries: int = DEFAULT_RETRIES,
skips: int = DEFAULT_SKIPS, skips: int = DEFAULT_SKIPS,
@ -86,6 +88,7 @@ class UpdateTask(SignalSender):
fimfarchive: Fetcher for the old release. fimfarchive: Fetcher for the old release.
fimfiction: Fetcher for the new release. fimfiction: Fetcher for the new release.
selector: Selector for which story to save. selector: Selector for which story to save.
stamper: Stamper for adding story information.
workdir: Path for storage of state and stories. workdir: Path for storage of state and stories.
retries: Number of retries before giving up. retries: Number of retries before giving up.
skips: Number of skips before giving up. skips: Number of skips before giving up.
@ -95,9 +98,13 @@ class UpdateTask(SignalSender):
if selector is None: if selector is None:
selector = UpdateSelector() selector = UpdateSelector()
if stamper is None:
stamper = UpdateStamper()
self.fimfarchive = fimfarchive self.fimfarchive = fimfarchive
self.fimfiction = fimfiction self.fimfiction = fimfiction
self.select = selector self.select = selector
self.stamp = stamper
self.workdir = workdir self.workdir = workdir
self.retries = retries self.retries = retries
self.skips = skips self.skips = skips
@ -176,6 +183,7 @@ class UpdateTask(SignalSender):
selected = selected.merge(meta=new.meta) selected = selected.merge(meta=new.meta)
if selected: if selected:
self.stamp(selected)
self.write(selected) self.write(selected)
elif new: elif new:
self.skip_writer.write(new) self.skip_writer.write(new)

View file

@ -105,7 +105,14 @@ class TestUpdateTask:
return UpdateSelector() return UpdateSelector()
@pytest.fixture @pytest.fixture
def task(self, fimfarchive, fimfiction, selector, tmpdir): def stamper(self):
"""
Returns a stamper mock.
"""
return MagicMock()
@pytest.fixture
def task(self, fimfarchive, fimfiction, selector, stamper, tmpdir):
""" """
Returns an `UpdateTask` instance. Returns an `UpdateTask` instance.
""" """
@ -113,6 +120,7 @@ class TestUpdateTask:
fimfiction=fimfiction, fimfiction=fimfiction,
fimfarchive=fimfarchive, fimfarchive=fimfarchive,
selector=selector, selector=selector,
stamper=stamper,
workdir=str(tmpdir), workdir=str(tmpdir),
retries=2, retries=2,
skips=2, skips=2,
@ -142,6 +150,7 @@ class TestUpdateTask:
) )
self.verify_run(task, delays) self.verify_run(task, delays)
task.stamp.assert_called_once_with(target)
task.write.assert_called_once_with(target) task.write.assert_called_once_with(target)
assert status in target.flavors assert status in target.flavors
assert task.state['key'] == 4 assert task.state['key'] == 4
@ -150,6 +159,7 @@ class TestUpdateTask:
""" """
Runs the task and verifies an empty fetch. Runs the task and verifies an empty fetch.
""" """
task.write = MagicMock()
task.skip_writer.write = MagicMock() task.skip_writer.write = MagicMock()
target = fetcher.add(key=1, date=1) target = fetcher.add(key=1, date=1)
@ -161,6 +171,8 @@ class TestUpdateTask:
) )
self.verify_run(task, delays) self.verify_run(task, delays)
task.stamp.assert_not_called()
task.write.assert_not_called()
task.skip_writer.write.assert_called_once_with(target) task.skip_writer.write.assert_called_once_with(target)
def verify_failure(self, task, fetcher): def verify_failure(self, task, fetcher):
@ -176,6 +188,7 @@ class TestUpdateTask:
) )
self.verify_run(task, delays) self.verify_run(task, delays)
task.stamp.assert_not_called()
task.write.assert_not_called() task.write.assert_not_called()
def test_created_story(self, task, fimfiction): def test_created_story(self, task, fimfiction):