Add JSON story writer to update task

This commit is contained in:
Joakim Soderlund 2017-11-08 18:41:48 +01:00
parent faea33d7b2
commit 2270df477b
2 changed files with 14 additions and 0 deletions

View file

@ -117,10 +117,12 @@ class UpdateTask(SignalSender):
skip_mapper = self.get_mapper('skip')
epub_mapper = self.get_mapper('epub')
html_mapper = self.get_mapper('html')
json_mapper = self.get_mapper('json')
self.skip_writer = DirectoryWriter(skip_mapper)
self.epub_writer = DirectoryWriter(meta_mapper, epub_mapper)
self.html_writer = DirectoryWriter(meta_mapper, html_mapper)
self.json_writer = DirectoryWriter(meta_mapper, json_mapper)
def get_mapper(self, subdir: str) -> StoryPathMapper:
"""
@ -160,6 +162,8 @@ class UpdateTask(SignalSender):
"""
if DataFormat.HTML in story.flavors:
self.html_writer.write(story)
elif DataFormat.JSON in story.flavors:
self.json_writer.write(story)
elif DataFormat.EPUB in story.flavors:
self.epub_writer.write(story)
else:

View file

@ -281,6 +281,16 @@ class TestUpdateTask:
task.write(story)
task.html_writer.write.assert_called_once_with(story)
def test_write_json(self, task, story):
"""
Tests writing of a story in JSON format.
"""
story = story.merge(flavors=[DataFormat.JSON])
task.json_writer.write = MagicMock()
task.write(story)
task.json_writer.write.assert_called_once_with(story)
def test_write_unsupported(self, task, story):
"""
Tests `ValueError` is raised for unknown data formats.