Switch to pytest and use vcr for request storing

pull/163/head
Patrick Robertson 2025-01-08 11:25:13 +01:00
rodzic ab9335bb7a
commit 9dc4eb35de
5 zmienionych plików z 57421 dodań i 21 usunięć

Wyświetl plik

@ -37,4 +37,4 @@ jobs:
directory: ./ directory: ./
- name: Run Tests - name: Run Tests
run: | run: |
python -m unittest pytest

Wyświetl plik

@ -1,7 +1,8 @@
from auto_archiver.archivers.bluesky_archiver import BlueskyArchiver from auto_archiver.archivers.bluesky_archiver import BlueskyArchiver
from vcr.unittest import VCRMixin
import unittest import unittest
class TestBlueskyArchiver(unittest.TestCase): class TestBlueskyArchiver(VCRMixin, unittest.TestCase):
"""Tests Bluesky Archiver """Tests Bluesky Archiver
Note that these tests will download API responses from the bluesky API, so they may be slow. Note that these tests will download API responses from the bluesky API, so they may be slow.
@ -30,19 +31,19 @@ class TestBlueskyArchiver(unittest.TestCase):
# just make sure bsky haven't changed their format, images should be under "record/embed/media/images" # just make sure bsky haven't changed their format, images should be under "record/embed/media/images"
# there should be 2 images # there should be 2 images
self.assertTrue("record" in post) assert "record" in post
self.assertTrue("embed" in post["record"]) assert "embed" in post["record"]
self.assertTrue("media" in post["record"]["embed"]) assert "media" in post["record"]["embed"]
self.assertTrue("images" in post["record"]["embed"]["media"]) assert "images" in post["record"]["embed"]["media"]
self.assertEqual(len(post["record"]["embed"]["media"]["images"]), 2) assert len(post["record"]["embed"]["media"]["images"]) == 2
# try downloading the media files # try downloading the media files
media = self.bsky._download_bsky_embeds(post) media = self.bsky._download_bsky_embeds(post)
self.assertEqual(len(media), 2) assert len(media) == 2
# check the IDs # check the IDs
self.assertTrue("bafkreiflrkfihcvwlhka5tb2opw2qog6gfvywsdzdlibveys2acozh75tq" in media[0].get('src')) assert "bafkreiflrkfihcvwlhka5tb2opw2qog6gfvywsdzdlibveys2acozh75tq" in media[0].get('src')
self.assertTrue("bafkreibsprmwchf7r6xcstqkdvvuj3ijw7efciw7l3y4crxr4cmynseo7u" in media[1].get('src')) assert "bafkreibsprmwchf7r6xcstqkdvvuj3ijw7efciw7l3y4crxr4cmynseo7u" in media[1].get('src')
def test_download_post_with_single_image(self): def test_download_post_with_single_image(self):
# url https://bsky.app/profile/bellingcat.com/post/3lcxcpgt6j42l # url https://bsky.app/profile/bellingcat.com/post/3lcxcpgt6j42l
@ -50,16 +51,16 @@ class TestBlueskyArchiver(unittest.TestCase):
# just make sure bsky haven't changed their format, images should be under "record/embed/images" # just make sure bsky haven't changed their format, images should be under "record/embed/images"
# there should be 1 image # there should be 1 image
self.assertTrue("record" in post) assert "record" in post
self.assertTrue("embed" in post["record"]) assert "embed" in post["record"]
self.assertTrue("images" in post["record"]["embed"]) assert "images" in post["record"]["embed"]
self.assertEqual(len(post["record"]["embed"]["images"]), 1) assert len(post["record"]["embed"]["images"]) == 1
media = self.bsky._download_bsky_embeds(post) media = self.bsky._download_bsky_embeds(post)
self.assertEqual(len(media), 1) assert len(media) == 1
# check the ID # check the ID
self.assertTrue("bafkreihljdtomy4yulx4nfxuqdatlgvdg45vxdmjzzhclsd4ludk7zfma4" in media[0].get('src')) assert "bafkreihljdtomy4yulx4nfxuqdatlgvdg45vxdmjzzhclsd4ludk7zfma4" in media[0].get('src')
def test_download_post_with_video(self): def test_download_post_with_video(self):
@ -67,14 +68,14 @@ class TestBlueskyArchiver(unittest.TestCase):
post = self.bsky._get_post_from_uri("https://bsky.app/profile/bellingcat.com/post/3le2l4gsxlk2i") post = self.bsky._get_post_from_uri("https://bsky.app/profile/bellingcat.com/post/3le2l4gsxlk2i")
# just make sure bsky haven't changed their format, video should be under "record/embed/video" # just make sure bsky haven't changed their format, video should be under "record/embed/video"
self.assertTrue("record" in post) assert "record" in post
self.assertTrue("embed" in post["record"]) assert "embed" in post["record"]
self.assertTrue("video" in post["record"]["embed"]) assert "video" in post["record"]["embed"]
media = self.bsky._download_bsky_embeds(post) media = self.bsky._download_bsky_embeds(post)
self.assertEqual(len(media), 1) assert len(media) == 1
# check the ID # check the ID
self.assertTrue("bafkreiaiskn2nt5cxjnxbgcqqcrnurvkr2ni3unekn6zvhvgr5nrqg6u2q" in media[0].get('src')) assert "bafkreiaiskn2nt5cxjnxbgcqqcrnurvkr2ni3unekn6zvhvgr5nrqg6u2q" in media[0].get('src')