From d9a0a78c7963ec38d4237db649fa8b2e02003c52 Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Wed, 5 Sep 2018 19:40:20 +0200 Subject: [PATCH] Add redactor to Fimfiction APIv2 fetcher tests --- tests/fetchers/test_fimfiction2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/fetchers/test_fimfiction2.py b/tests/fetchers/test_fimfiction2.py index 8eb286f..d6f4f49 100644 --- a/tests/fetchers/test_fimfiction2.py +++ b/tests/fetchers/test_fimfiction2.py @@ -29,6 +29,9 @@ import pytest from fimfarchive.exceptions import InvalidStoryError from fimfarchive.fetchers import Fimfiction2Fetcher +from fimfarchive.utils import JayWalker + +from tests.fixtures.responses import Recorder 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: """ Fimfarchive2Fetcher tests. @@ -72,6 +89,9 @@ class TestFimfiction2Fetcher: fetcher.prefetch_meta = False fetcher.prefetch_data = False + if isinstance(responses, Recorder): + responses.walker = Redactor() + yield fetcher def fetch_valid(self, fetcher, key):