From f87f300384933ce17edfe375b83af0049726165c Mon Sep 17 00:00:00 2001 From: geirawsm Date: Tue, 19 Nov 2024 16:15:58 +0100 Subject: [PATCH] Added test for validating feeds --- sausage_bot/test/feeds_core_test.py | 25 +++++++++++++++++++++++-- sausage_bot/test/net_io_test.py | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/sausage_bot/test/feeds_core_test.py b/sausage_bot/test/feeds_core_test.py index 77fabba..3f5bfe6 100755 --- a/sausage_bot/test/feeds_core_test.py +++ b/sausage_bot/test/feeds_core_test.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pytest -import pytest_asyncio -from sausage_bot.util import file_io +from sausage_bot.util import file_io, feeds_core def test_check_similarity_return_number_or_none(): @@ -13,3 +12,25 @@ def test_check_similarity_return_number_or_none(): link3 = False assert file_io.check_similarity(link1, link2) is link2 assert file_io.check_similarity(link1, link3) is None + + +async def test_check_feed_validity_url(): + good_url1 = 'https://open.spotify.com/show/7CJKujLFxINFP3G4zns6nw?'\ + 'si=QM4HOzU5RlGuDOEOVLOtCQ' + good_url2 = 'https://www.metalsucks.net/category/'\ + 'shit-that-comes-out-today/feed/' + good_url3 = 'https://rss.kode24.no/' + bad_url1 = 'https://www.youtube.com' + bad_url2 = '' + + out_good1 = await feeds_core.check_feed_validity(good_url1) + out_good2 = await feeds_core.check_feed_validity(good_url2) + out_good3 = await feeds_core.check_feed_validity(good_url3) + out_bad1 = await feeds_core.check_feed_validity(bad_url1) + out_bad2 = await feeds_core.check_feed_validity(bad_url2) + + assert out_good1 is True + assert out_good2 is True + assert out_good3 is True + assert out_bad1 is False + assert out_bad2 is None diff --git a/sausage_bot/test/net_io_test.py b/sausage_bot/test/net_io_test.py index f85d395..24e6a3f 100755 --- a/sausage_bot/test/net_io_test.py +++ b/sausage_bot/test/net_io_test.py @@ -7,6 +7,20 @@ from sausage_bot.util import net_io +async def test_check_spotify_podcast_url(): + good_url1 = 'https://open.spotify.com/show/7CJKujLFxINFP3G4zns6nw?si=QM4HOzU5RlGuDOEOVLOtCQ' + good_url2 = 'https://open.spotify.com/show/47qpUkCsSOLCkda3oE710f?si=5fb79d4d90ea43bd' + # This lacks the `?si=...` in the end, but is still accepted + good_url3 = 'https://open.spotify.com/show/47qpUkCsSOLCkda3oE710f' + # Obviously not a spotify link + bad_url1 = 'https://www.youtube.com' + + assert type(await net_io.check_spotify_podcast(good_url1)) is int + assert type(await net_io.check_spotify_podcast(good_url2)) is int + assert type(await net_io.check_spotify_podcast(good_url3)) is int + assert await net_io.check_spotify_podcast(bad_url1) is False + + async def test_make_event_start_stop(): date_yes, time_yes = ('17.05.2022', '21:00') date_yes, time_no = ('17.05.2022', '671:00')