mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 05:17:59 +01:00
Add stampers module
This commit is contained in:
parent
55c7b95d93
commit
c9eadd0c92
2 changed files with 123 additions and 0 deletions
59
fimfarchive/stampers.py
Normal file
59
fimfarchive/stampers.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""
|
||||
Stampers for Fimfarchive.
|
||||
"""
|
||||
|
||||
|
||||
#
|
||||
# Fimfarchive, preserves stories from Fimfiction.
|
||||
# Copyright (C) 2015 Joakim Soderlund
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
from fimfarchive.stories import Story
|
||||
|
||||
|
||||
class Stamper:
|
||||
"""
|
||||
Adds archive-related information to stories.
|
||||
"""
|
||||
|
||||
def get_archive(self, story: Story) -> Dict[str, Any]:
|
||||
"""
|
||||
Finds or creates an archive dict.
|
||||
|
||||
Args:
|
||||
story: The story to stamp.
|
||||
|
||||
Returns:
|
||||
An archive dict for the story.
|
||||
"""
|
||||
meta = story.meta
|
||||
|
||||
if 'archive' not in meta:
|
||||
meta['archive'] = dict()
|
||||
|
||||
return meta['archive']
|
||||
|
||||
def __call__(self, story: Story) -> None:
|
||||
"""
|
||||
Applies the stamp to the story.
|
||||
|
||||
Args:
|
||||
story: The story to stamp.
|
||||
"""
|
||||
raise NotImplementedError()
|
64
tests/test_stampers.py
Normal file
64
tests/test_stampers.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
"""
|
||||
Stamper tests.
|
||||
"""
|
||||
|
||||
|
||||
#
|
||||
# Fimfarchive, preserves stories from Fimfiction.
|
||||
# Copyright (C) 2015 Joakim Soderlund
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
from typing import Dict
|
||||
|
||||
import pytest
|
||||
|
||||
from fimfarchive.stampers import Stamper
|
||||
|
||||
|
||||
class TestStamper:
|
||||
"""
|
||||
Stamper tests.
|
||||
"""
|
||||
|
||||
@pytest.fixture
|
||||
def stamper(self):
|
||||
"""
|
||||
Returns a new stamper instance.
|
||||
"""
|
||||
return Stamper()
|
||||
|
||||
def test_missing_archive_dict(self, stamper, story):
|
||||
"""
|
||||
Tests archive dict is created if none exists.
|
||||
"""
|
||||
meta = story.meta
|
||||
assert 'archive' not in meta
|
||||
|
||||
archive = stamper.get_archive(story)
|
||||
assert meta['archive'] is archive
|
||||
|
||||
def test_existing_archive_dict(self, stamper, story):
|
||||
"""
|
||||
Tests archive dict is kept if it exists.
|
||||
"""
|
||||
meta = story.meta
|
||||
original: Dict = dict()
|
||||
meta['archive'] = original
|
||||
archive = stamper.get_archive(story)
|
||||
|
||||
assert archive is original
|
||||
assert meta['archive'] is original
|
Loading…
Reference in a new issue