diff --git a/fimfarchive/tasks/update.py b/fimfarchive/tasks/update.py index 8fa1402..b00a928 100644 --- a/fimfarchive/tasks/update.py +++ b/fimfarchive/tasks/update.py @@ -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: diff --git a/tests/tasks/test_update.py b/tests/tasks/test_update.py index 0b3e419..c795557 100644 --- a/tests/tasks/test_update.py +++ b/tests/tasks/test_update.py @@ -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.