add mock to podcast tests
This commit is contained in:
parent
f53b1aca38
commit
0162182407
6 changed files with 20 additions and 6 deletions
|
@ -10,6 +10,12 @@ from django.utils.timezone import make_aware
|
||||||
import bleach
|
import bleach
|
||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from catalog.common.downloaders import (
|
||||||
|
get_mock_file,
|
||||||
|
get_mock_mode,
|
||||||
|
_local_response_path,
|
||||||
|
)
|
||||||
|
import pickle
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -28,12 +34,20 @@ class RSS(AbstractSite):
|
||||||
feed = cache.get(url)
|
feed = cache.get(url)
|
||||||
if feed:
|
if feed:
|
||||||
return feed
|
return feed
|
||||||
req = urllib.request.Request(url)
|
if get_mock_mode():
|
||||||
req.add_header("User-Agent", "NeoDB/0.5")
|
feed = pickle.load(open(_local_response_path + get_mock_file(url), "rb"))
|
||||||
try:
|
else:
|
||||||
feed = podcastparser.parse(url, urllib.request.urlopen(req, timeout=3))
|
req = urllib.request.Request(url)
|
||||||
except:
|
req.add_header("User-Agent", "NeoDB/0.5")
|
||||||
return None
|
try:
|
||||||
|
feed = podcastparser.parse(url, urllib.request.urlopen(req, timeout=3))
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
if settings.DOWNLOADER_SAVEDIR:
|
||||||
|
pickle.dump(
|
||||||
|
feed,
|
||||||
|
open(settings.DOWNLOADER_SAVEDIR + "/" + get_mock_file(url), "wb"),
|
||||||
|
)
|
||||||
cache.set(url, feed, timeout=300)
|
cache.set(url, feed, timeout=300)
|
||||||
return feed
|
return feed
|
||||||
|
|
||||||
|
|
BIN
test_data/https___anchor_fm_s_64d6bbe0_podcast_rss
Normal file
BIN
test_data/https___anchor_fm_s_64d6bbe0_podcast_rss
Normal file
Binary file not shown.
BIN
test_data/https___podcasts_files_bbci_co_uk_b006qykl_rss
Normal file
BIN
test_data/https___podcasts_files_bbci_co_uk_b006qykl_rss
Normal file
Binary file not shown.
BIN
test_data/https___rsshub_app_ximalaya_album_51101122_0_shownote
Normal file
BIN
test_data/https___rsshub_app_ximalaya_album_51101122_0_shownote
Normal file
Binary file not shown.
BIN
test_data/https___tiaodao_typlog_io_feed_xml
Normal file
BIN
test_data/https___tiaodao_typlog_io_feed_xml
Normal file
Binary file not shown.
BIN
test_data/https___www_digforfire_net_digforfire_radio_feed_xml
Normal file
BIN
test_data/https___www_digforfire_net_digforfire_radio_feed_xml
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue