From c604c4b2add52f66aac65be2689695d66d2f9d39 Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Wed, 8 Nov 2017 20:09:09 +0100 Subject: [PATCH] Write only meta for revived stories in update task --- fimfarchive/tasks/update.py | 7 +++++-- tests/tasks/test_update.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/fimfarchive/tasks/update.py b/fimfarchive/tasks/update.py index b00a928..b25f700 100644 --- a/fimfarchive/tasks/update.py +++ b/fimfarchive/tasks/update.py @@ -28,7 +28,7 @@ from typing import Optional from fimfarchive.exceptions import InvalidStoryError from fimfarchive.fetchers import Fetcher -from fimfarchive.flavors import DataFormat, UpdateStatus +from fimfarchive.flavors import DataFormat, StorySource, UpdateStatus from fimfarchive.mappers import StoryPathMapper from fimfarchive.selectors import Selector, UpdateSelector from fimfarchive.signals import Signal, SignalSender @@ -119,6 +119,7 @@ class UpdateTask(SignalSender): html_mapper = self.get_mapper('html') json_mapper = self.get_mapper('json') + self.meta_writer = DirectoryWriter(meta_mapper) self.skip_writer = DirectoryWriter(skip_mapper) self.epub_writer = DirectoryWriter(meta_mapper, epub_mapper) self.html_writer = DirectoryWriter(meta_mapper, html_mapper) @@ -160,7 +161,9 @@ class UpdateTask(SignalSender): Raises: ValueError: If story flavor is unsupported. """ - if DataFormat.HTML in story.flavors: + if StorySource.FIMFARCHIVE in story.flavors: + self.meta_writer.write(story) + elif DataFormat.HTML in story.flavors: self.html_writer.write(story) elif DataFormat.JSON in story.flavors: self.json_writer.write(story) diff --git a/tests/tasks/test_update.py b/tests/tasks/test_update.py index c795557..b0fa66f 100644 --- a/tests/tasks/test_update.py +++ b/tests/tasks/test_update.py @@ -28,7 +28,7 @@ import pytest from fimfarchive.exceptions import InvalidStoryError, StorySourceError from fimfarchive.fetchers import Fetcher -from fimfarchive.flavors import DataFormat, UpdateStatus +from fimfarchive.flavors import DataFormat, StorySource, UpdateStatus from fimfarchive.selectors import RefetchSelector, UpdateSelector from fimfarchive.stories import Story from fimfarchive.tasks.update import ( @@ -261,6 +261,23 @@ class TestUpdateTask: """ self.verify_failure(task, fimfiction) + def test_write_meta(self, task, story): + """ + Tests writing of meta for stories from Fimfarchive. + """ + story = story.merge(flavors=[ + DataFormat.JSON, + StorySource.FIMFARCHIVE, + ]) + + task.meta_writer.write = MagicMock() + task.json_writer.write = MagicMock() + + task.write(story) + + task.meta_writer.write.assert_called_once_with(story) + task.json_writer.write.assert_not_called() + def test_write_epub(self, task, story): """ Tests writing of a story in EPUB format.