mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 05:17:59 +01:00
Add JSON story writer to update task
This commit is contained in:
parent
faea33d7b2
commit
2270df477b
2 changed files with 14 additions and 0 deletions
|
@ -117,10 +117,12 @@ class UpdateTask(SignalSender):
|
||||||
skip_mapper = self.get_mapper('skip')
|
skip_mapper = self.get_mapper('skip')
|
||||||
epub_mapper = self.get_mapper('epub')
|
epub_mapper = self.get_mapper('epub')
|
||||||
html_mapper = self.get_mapper('html')
|
html_mapper = self.get_mapper('html')
|
||||||
|
json_mapper = self.get_mapper('json')
|
||||||
|
|
||||||
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)
|
||||||
|
self.json_writer = DirectoryWriter(meta_mapper, json_mapper)
|
||||||
|
|
||||||
def get_mapper(self, subdir: str) -> StoryPathMapper:
|
def get_mapper(self, subdir: str) -> StoryPathMapper:
|
||||||
"""
|
"""
|
||||||
|
@ -160,6 +162,8 @@ class UpdateTask(SignalSender):
|
||||||
"""
|
"""
|
||||||
if DataFormat.HTML in story.flavors:
|
if DataFormat.HTML in story.flavors:
|
||||||
self.html_writer.write(story)
|
self.html_writer.write(story)
|
||||||
|
elif DataFormat.JSON in story.flavors:
|
||||||
|
self.json_writer.write(story)
|
||||||
elif DataFormat.EPUB in story.flavors:
|
elif DataFormat.EPUB in story.flavors:
|
||||||
self.epub_writer.write(story)
|
self.epub_writer.write(story)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -281,6 +281,16 @@ class TestUpdateTask:
|
||||||
task.write(story)
|
task.write(story)
|
||||||
task.html_writer.write.assert_called_once_with(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):
|
def test_write_unsupported(self, task, story):
|
||||||
"""
|
"""
|
||||||
Tests `ValueError` is raised for unknown data formats.
|
Tests `ValueError` is raised for unknown data formats.
|
||||||
|
|
Loading…
Reference in a new issue