Add redactor to Fimfiction APIv2 fetcher tests

This commit is contained in:
Joakim Soderlund 2018-09-05 19:40:20 +02:00
parent 3139ff9d7c
commit d9a0a78c79

View file

@ -29,6 +29,9 @@ import pytest
from fimfarchive.exceptions import InvalidStoryError from fimfarchive.exceptions import InvalidStoryError
from fimfarchive.fetchers import Fimfiction2Fetcher from fimfarchive.fetchers import Fimfiction2Fetcher
from fimfarchive.utils import JayWalker
from tests.fixtures.responses import Recorder
VALID_STORY_KEY = 9 VALID_STORY_KEY = 9
@ -54,6 +57,20 @@ BULK_COMBINATIONS = [
] ]
class Redactor(JayWalker):
"""
Redacts recorded responses.
"""
def handle(self, data, key, value) -> None:
key = str(key)
if key.endswith('_html') or key == 'short_description':
data[key] = "REDACTED"
else:
self.walk(value)
class TestFimfiction2Fetcher: class TestFimfiction2Fetcher:
""" """
Fimfarchive2Fetcher tests. Fimfarchive2Fetcher tests.
@ -72,6 +89,9 @@ class TestFimfiction2Fetcher:
fetcher.prefetch_meta = False fetcher.prefetch_meta = False
fetcher.prefetch_data = False fetcher.prefetch_data = False
if isinstance(responses, Recorder):
responses.walker = Redactor()
yield fetcher yield fetcher
def fetch_valid(self, fetcher, key): def fetch_valid(self, fetcher, key):