Remove catching KeyError from FeedBuilder
This builder is programmed defensively
This commit is contained in:
parent
062cb9f012
commit
cffcd954d7
2 changed files with 2 additions and 26 deletions
|
|
@ -45,12 +45,7 @@ class FeedBuilder(PostBuilder):
|
||||||
entries = self.payload.get("entries", [])
|
entries = self.payload.get("entries", [])
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
try:
|
|
||||||
post = self.build_post(entry)
|
post = self.build_post(entry)
|
||||||
except KeyError:
|
|
||||||
logger.exception(f"Failed building post")
|
|
||||||
continue
|
|
||||||
|
|
||||||
instances.append(post)
|
instances.append(post)
|
||||||
|
|
||||||
self.instances = duplicate_handler.check(instances)
|
self.instances = duplicate_handler.check(instances)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
@ -390,21 +389,3 @@ class FeedBuilderTestCase(TestCase):
|
||||||
self.assertEqual(Post.objects.count(), 1)
|
self.assertEqual(Post.objects.count(), 1)
|
||||||
|
|
||||||
self.assertEqual(post.body, "Yippie\n Ya\n Yee")
|
self.assertEqual(post.body, "Yippie\n Ya\n Yee")
|
||||||
|
|
||||||
@patch("newsreader.news.collection.feed.FeedBuilder.build_post")
|
|
||||||
def test_post_key_error(self, mocked_build_post):
|
|
||||||
rule = FeedFactory()
|
|
||||||
mock_stream = Mock(rule=rule)
|
|
||||||
|
|
||||||
identifier = str(uuid4())
|
|
||||||
build_post = FeedPostFactory.build(rule=rule, remote_identifier=identifier)
|
|
||||||
|
|
||||||
mocked_build_post.side_effect = (KeyError, build_post)
|
|
||||||
|
|
||||||
with FeedBuilder({"entries": [{}, {}]}, mock_stream) as builder:
|
|
||||||
builder.build()
|
|
||||||
builder.save()
|
|
||||||
|
|
||||||
posts = Post.objects.values_list("remote_identifier", flat=True)
|
|
||||||
|
|
||||||
self.assertCountEqual(posts, (identifier,))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue