mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 21:37:59 +01:00
Fix blacklist not working for older archives
This commit is contained in:
parent
feb0cbacaf
commit
00afaedb60
2 changed files with 33 additions and 23 deletions
|
@ -246,8 +246,8 @@ def is_blacklisted(story: Story) -> bool:
|
||||||
Returns:
|
Returns:
|
||||||
True if a story has been blacklisted.
|
True if a story has been blacklisted.
|
||||||
"""
|
"""
|
||||||
story_id = story.key
|
story_id = int(story.meta['id'])
|
||||||
author_id = story.meta['author']['id']
|
author_id = int(story.meta['author']['id'])
|
||||||
|
|
||||||
if story_id in STORY_WHITELIST:
|
if story_id in STORY_WHITELIST:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -37,13 +37,6 @@ from fimfarchive.utils import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
BLACKLISTED_AUTHOR = 1
|
|
||||||
BLACKLISTED_STORY = 2
|
|
||||||
WHITELISTED_STORY = 3
|
|
||||||
UNLISTED_AUTHOR = 4
|
|
||||||
UNLISTED_STORY = 5
|
|
||||||
|
|
||||||
|
|
||||||
class TestEmpty:
|
class TestEmpty:
|
||||||
"""
|
"""
|
||||||
Empty tests.
|
Empty tests.
|
||||||
|
@ -327,27 +320,34 @@ class TestIsBlacklisted:
|
||||||
"""
|
"""
|
||||||
is_blacklisted tests.
|
is_blacklisted tests.
|
||||||
"""
|
"""
|
||||||
|
BLACKLISTED_AUTHOR = 1
|
||||||
|
BLACKLISTED_STORY = 2
|
||||||
|
WHITELISTED_STORY = 3
|
||||||
|
UNLISTED_AUTHOR = 4
|
||||||
|
UNLISTED_STORY = 5
|
||||||
|
|
||||||
@pytest.fixture
|
COMBINATIONS = [
|
||||||
def utils(self):
|
|
||||||
"""
|
|
||||||
Patches the blacklists and whitelists.
|
|
||||||
"""
|
|
||||||
ab = patch.object(utils, 'AUTHOR_BLACKLIST', {BLACKLISTED_AUTHOR})
|
|
||||||
sb = patch.object(utils, 'STORY_BLACKLIST', {BLACKLISTED_STORY})
|
|
||||||
sw = patch.object(utils, 'STORY_WHITELIST', {WHITELISTED_STORY})
|
|
||||||
|
|
||||||
with ab, sb, sw:
|
|
||||||
yield utils
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('key,author,result', [
|
|
||||||
(BLACKLISTED_STORY, BLACKLISTED_AUTHOR, True),
|
(BLACKLISTED_STORY, BLACKLISTED_AUTHOR, True),
|
||||||
(BLACKLISTED_STORY, UNLISTED_AUTHOR, True),
|
(BLACKLISTED_STORY, UNLISTED_AUTHOR, True),
|
||||||
(UNLISTED_STORY, BLACKLISTED_AUTHOR, True),
|
(UNLISTED_STORY, BLACKLISTED_AUTHOR, True),
|
||||||
(UNLISTED_STORY, UNLISTED_AUTHOR, False),
|
(UNLISTED_STORY, UNLISTED_AUTHOR, False),
|
||||||
(WHITELISTED_STORY, BLACKLISTED_AUTHOR, False),
|
(WHITELISTED_STORY, BLACKLISTED_AUTHOR, False),
|
||||||
(WHITELISTED_STORY, UNLISTED_AUTHOR, False),
|
(WHITELISTED_STORY, UNLISTED_AUTHOR, False),
|
||||||
])
|
]
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def utils(self):
|
||||||
|
"""
|
||||||
|
Patches the blacklists and whitelists.
|
||||||
|
"""
|
||||||
|
ab = patch.object(utils, 'AUTHOR_BLACKLIST', {self.BLACKLISTED_AUTHOR})
|
||||||
|
sb = patch.object(utils, 'STORY_BLACKLIST', {self.BLACKLISTED_STORY})
|
||||||
|
sw = patch.object(utils, 'STORY_WHITELIST', {self.WHITELISTED_STORY})
|
||||||
|
|
||||||
|
with ab, sb, sw:
|
||||||
|
yield utils
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('key,author,result', COMBINATIONS)
|
||||||
def test_blacklisted(self, utils, story, key, author, result):
|
def test_blacklisted(self, utils, story, key, author, result):
|
||||||
"""
|
"""
|
||||||
Tests the various blacklist combinations.
|
Tests the various blacklist combinations.
|
||||||
|
@ -356,3 +356,13 @@ class TestIsBlacklisted:
|
||||||
story = story.merge(key=key, meta=meta)
|
story = story.merge(key=key, meta=meta)
|
||||||
|
|
||||||
assert result is is_blacklisted(story)
|
assert result is is_blacklisted(story)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('key,author,result', COMBINATIONS)
|
||||||
|
def test_blacklisted_string(self, utils, story, key, author, result):
|
||||||
|
"""
|
||||||
|
Tests the various blacklist combinations when IDs are strings.
|
||||||
|
"""
|
||||||
|
meta = {'id': str(key), 'author': {'id': str(author)}}
|
||||||
|
story = story.merge(key=key, meta=meta)
|
||||||
|
|
||||||
|
assert result is is_blacklisted(story)
|
||||||
|
|
Loading…
Reference in a new issue