Web: test a couple poll feed errors

pull/777/head
Ryan Barrett 2024-01-06 13:04:22 -10:00
rodzic 5f1c521500
commit 1db5358688
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 36 dodań i 3 usunięć

Wyświetl plik

@ -1963,6 +1963,39 @@ class WebTest(TestCase):
self.assert_task(mock_create_task, 'poll-feed', '/queue/poll-feed',
domain='user.com', eta_seconds=expected_eta)
def test_poll_feed_fails(self, mock_get, _):
common.RUN_TASKS_INLINE = False
self.user.obj.mf2 = {
**ACTOR_MF2,
'rel-urls': {
'https://foo/rss': {'rels': ['alternate'], 'type': rss.CONTENT_TYPE},
},
}
self.user.obj.put()
mock_get.side_effect = requests.ConnectionError()
got = self.post('/queue/poll-feed', data={'domain': 'user.com'})
self.assertEqual(504, got.status_code)
self.assertIsNone(self.user.key.get().last_polled_feed)
def test_poll_feed_wrong_content_type(self, mock_get, _):
common.RUN_TASKS_INLINE = False
self.user.obj.mf2 = {
**ACTOR_MF2,
'rel-urls': {
'https://foo/rss': {'rels': ['alternate'], 'type': rss.CONTENT_TYPE},
},
}
self.user.obj.put()
mock_get.return_value = requests_response(
'nope', headers={'Content-Type': 'text/plain'})
got = self.post('/queue/poll-feed', data={'domain': 'user.com'})
self.assertEqual(200, got.status_code)
self.assertIsNone(self.user.key.get().last_polled_feed)
def _test_verify(self, redirects, hcard, actor, redirects_error=None):
self.user.has_redirects = False
self.user.put()

6
web.py
Wyświetl plik

@ -651,9 +651,6 @@ def poll_feed_task():
# fetch feed
resp = util.requests_get(url)
user.last_polled_feed = util.now()
user.put()
content_type = resp.headers.get('Content-Type')
type = FEED_TYPES.get(content_type.split(';')[0])
if type == 'atom':
@ -667,6 +664,9 @@ def poll_feed_task():
logger.info(msg)
return msg
user.last_polled_feed = util.now()
user.put()
# create Objects and receive tasks
published_last = None
published_deltas = [] # timedeltas between entry published times