diff --git a/fimfarchive/utils.py b/fimfarchive/utils.py index 6f92d6c..0095b91 100644 --- a/fimfarchive/utils.py +++ b/fimfarchive/utils.py @@ -246,8 +246,8 @@ def is_blacklisted(story: Story) -> bool: Returns: True if a story has been blacklisted. """ - story_id = story.key - author_id = story.meta['author']['id'] + story_id = int(story.meta['id']) + author_id = int(story.meta['author']['id']) if story_id in STORY_WHITELIST: return False diff --git a/tests/test_utils.py b/tests/test_utils.py index 3be0b5c..e571aa9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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: """ Empty tests. @@ -327,27 +320,34 @@ class TestIsBlacklisted: """ is_blacklisted tests. """ + BLACKLISTED_AUTHOR = 1 + BLACKLISTED_STORY = 2 + WHITELISTED_STORY = 3 + UNLISTED_AUTHOR = 4 + UNLISTED_STORY = 5 - @pytest.fixture - 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', [ + COMBINATIONS = [ (BLACKLISTED_STORY, BLACKLISTED_AUTHOR, True), (BLACKLISTED_STORY, UNLISTED_AUTHOR, True), (UNLISTED_STORY, BLACKLISTED_AUTHOR, True), (UNLISTED_STORY, UNLISTED_AUTHOR, False), (WHITELISTED_STORY, BLACKLISTED_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): """ Tests the various blacklist combinations. @@ -356,3 +356,13 @@ class TestIsBlacklisted: story = story.merge(key=key, meta=meta) 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)