From befc92deb46651d6c86e9c45b44cf010acb19c82 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Fri, 17 Jan 2025 17:29:13 +0100 Subject: [PATCH] Further unit test tidy ups --- ...e_archiver.py => test_generic_archiver.py} | 3 ++- tests/archivers/test_twitter_api_archiver.py | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) rename tests/archivers/{test_base_archiver.py => test_generic_archiver.py} (99%) diff --git a/tests/archivers/test_base_archiver.py b/tests/archivers/test_generic_archiver.py similarity index 99% rename from tests/archivers/test_base_archiver.py rename to tests/archivers/test_generic_archiver.py index 03a7a9b..b6f460e 100644 --- a/tests/archivers/test_base_archiver.py +++ b/tests/archivers/test_generic_archiver.py @@ -1,6 +1,7 @@ import pytest from pathlib import Path import datetime +import os from auto_archiver.archivers.generic_archiver import GenericArchiver @@ -44,7 +45,7 @@ class TestGenericArchiver(TestArchiverBase): item = make_item("https://www.tiktok.com/@funnycats0ftiktok/video/7345101300750748970") result = self.archiver.download(item) assert result.get_url() == "https://www.tiktok.com/@funnycats0ftiktok/video/7345101300750748970" - + @pytest.mark.download def test_youtube_download(self, make_item): # url https://www.youtube.com/watch?v=5qap5aO4i9A diff --git a/tests/archivers/test_twitter_api_archiver.py b/tests/archivers/test_twitter_api_archiver.py index c8009f1..a95f2c7 100644 --- a/tests/archivers/test_twitter_api_archiver.py +++ b/tests/archivers/test_twitter_api_archiver.py @@ -53,14 +53,15 @@ class TestTwitterApiArchiver(TestArchiverBase): chosen_variant = self.archiver.choose_variant(variant_list) assert chosen_variant == variant_list[3] - + @pytest.mark.skipif(not os.environ.get("TWITTER_BEARER_TOKEN"), reason="No Twitter bearer token provided") @pytest.mark.download def test_download_nonexistent_tweet(self, make_item): # this tweet does not exist url = "https://x.com/Bellingcat/status/17197025860711058" response = self.archiver.download(make_item(url)) assert not response - + + @pytest.mark.skipif(not os.environ.get("TWITTER_BEARER_TOKEN"), reason="No Twitter bearer token provided") @pytest.mark.download def test_download_malformed_tweetid(self, make_item): # this tweet does not exist @@ -68,6 +69,7 @@ class TestTwitterApiArchiver(TestArchiverBase): response = self.archiver.download(make_item(url)) assert not response + @pytest.mark.skipif(not os.environ.get("TWITTER_BEARER_TOKEN"), reason="No Twitter bearer token provided") @pytest.mark.download def test_download_tweet_no_media(self, make_item): @@ -81,6 +83,7 @@ class TestTwitterApiArchiver(TestArchiverBase): "twitter-api: success" ) + @pytest.mark.skipif(not os.environ.get("TWITTER_BEARER_TOKEN"), reason="No Twitter bearer token provided") @pytest.mark.download def test_download_video(self, make_item): url = "https://x.com/bellingcat/status/1871552600346415571" @@ -91,14 +94,15 @@ class TestTwitterApiArchiver(TestArchiverBase): datetime.datetime(2024, 12, 24, 13, 44, 46, tzinfo=datetime.timezone.utc) ) - @pytest.mark.parametrize("url, title, timestamp, image_hash", [ - ("https://x.com/SozinhoRamalho/status/1876710769913450647", "ignore tweet, testing sensitivity warning nudity https://t.co/t3u0hQsSB1", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "image_hash"), - ("https://x.com/SozinhoRamalho/status/1876710875475681357", "ignore tweet, testing sensitivity warning violence https://t.co/syYDSkpjZD", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "image_hash"), - ("https://x.com/SozinhoRamalho/status/1876711053813227618", "ignore tweet, testing sensitivity warning sensitive https://t.co/XE7cRdjzYq", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "image_hash"), - ("https://x.com/SozinhoRamalho/status/1876711141314801937", "ignore tweet, testing sensitivity warning nudity, violence, sensitivity https://t.co/YxCFbbhYE3", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "image_hash"), + @pytest.mark.skipif(not os.environ.get("TWITTER_BEARER_TOKEN"), reason="No Twitter bearer token provided") + @pytest.mark.parametrize("url, title, timestamp, image_src", [ + ("https://x.com/SozinhoRamalho/status/1876710769913450647", "ignore tweet, testing sensitivity warning nudity https://t.co/t3u0hQsSB1", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "https://pbs.twimg.com/media/GgtqkomWkAAHUUl.jpg"), + ("https://x.com/SozinhoRamalho/status/1876710875475681357", "ignore tweet, testing sensitivity warning violence https://t.co/syYDSkpjZD", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "https://pbs.twimg.com/media/GgtqkomWkAAHUUl.jpg"), + ("https://x.com/SozinhoRamalho/status/1876711053813227618", "ignore tweet, testing sensitivity warning sensitive https://t.co/XE7cRdjzYq", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "https://pbs.twimg.com/media/GgtqkomWkAAHUUl.jpg"), + ("https://x.com/SozinhoRamalho/status/1876711141314801937", "ignore tweet, testing sensitivity warning nudity, violence, sensitivity https://t.co/YxCFbbhYE3", datetime.datetime(2024, 12, 31, 14, 18, 33, tzinfo=datetime.timezone.utc), "https://pbs.twimg.com/media/GgtqkomWkAAHUUl.jpg"), ]) @pytest.mark.download - def test_download_sensitive_media(self, url, title, timestamp, image_hash, make_item): + def test_download_sensitive_media(self, url, title, timestamp, image_src, make_item): """Download tweets with sensitive media""" @@ -109,4 +113,4 @@ class TestTwitterApiArchiver(TestArchiverBase): timestamp ) assert len(post.media) == 1 - assert post.media[0].hash == image_hash \ No newline at end of file + assert post.media[0].get('src') == image_src \ No newline at end of file