Write only meta for revived stories in update task

This commit is contained in:
Joakim Soderlund 2017-11-08 20:09:09 +01:00
parent 2270df477b
commit c604c4b2ad
2 changed files with 23 additions and 3 deletions

View file

@ -28,7 +28,7 @@ from typing import Optional
from fimfarchive.exceptions import InvalidStoryError from fimfarchive.exceptions import InvalidStoryError
from fimfarchive.fetchers import Fetcher 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.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
@ -119,6 +119,7 @@ class UpdateTask(SignalSender):
html_mapper = self.get_mapper('html') html_mapper = self.get_mapper('html')
json_mapper = self.get_mapper('json') json_mapper = self.get_mapper('json')
self.meta_writer = DirectoryWriter(meta_mapper)
self.skip_writer = DirectoryWriter(skip_mapper) self.skip_writer = DirectoryWriter(skip_mapper)
self.epub_writer = DirectoryWriter(meta_mapper, epub_mapper) self.epub_writer = DirectoryWriter(meta_mapper, epub_mapper)
self.html_writer = DirectoryWriter(meta_mapper, html_mapper) self.html_writer = DirectoryWriter(meta_mapper, html_mapper)
@ -160,7 +161,9 @@ class UpdateTask(SignalSender):
Raises: Raises:
ValueError: If story flavor is unsupported. 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) self.html_writer.write(story)
elif DataFormat.JSON in story.flavors: elif DataFormat.JSON in story.flavors:
self.json_writer.write(story) self.json_writer.write(story)

View file

@ -28,7 +28,7 @@ import pytest
from fimfarchive.exceptions import InvalidStoryError, StorySourceError from fimfarchive.exceptions import InvalidStoryError, StorySourceError
from fimfarchive.fetchers import Fetcher 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.selectors import RefetchSelector, UpdateSelector
from fimfarchive.stories import Story from fimfarchive.stories import Story
from fimfarchive.tasks.update import ( from fimfarchive.tasks.update import (
@ -261,6 +261,23 @@ class TestUpdateTask:
""" """
self.verify_failure(task, fimfiction) 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): def test_write_epub(self, task, story):
""" """
Tests writing of a story in EPUB format. Tests writing of a story in EPUB format.