import unittest
from weibo_image_rescue.utils import generate_urls_of_all_qualities


class TestGenerateUrlsOfAllQualities(unittest.TestCase):

    def test_default_quality(self):
        url = "https://wx1.sinaimg.cn/x/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg"
        expected_urls = [
            "https://wx1.sinaimg.cn/original/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/large/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/mw2000/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/mw690/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/thumb150/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/orj360/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
        ]
        self.assertEqual(
            sorted(generate_urls_of_all_qualities(url)), sorted(expected_urls)
        )

    def test_multiple_qualities(self):
        url = "https://wx1.sinaimg.cn/large/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg"
        expected_urls = [
            "https://wx1.sinaimg.cn/large/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/mw690/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
        ]
        self.assertEqual(
            sorted(generate_urls_of_all_qualities(url, ["l", "m"])),
            sorted(expected_urls),
        )

    def test_custom_and_mapped_qualities(self):
        url = "https://wx1.sinaimg.cn/abc/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg"
        expected_urls = [
            "https://wx1.sinaimg.cn/x/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/large/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/asd/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
            "https://wx1.sinaimg.cn/mw690/576bb392ly1iau1x1lgn5j21uo18g7wh.jpg",
        ]
        self.assertEqual(
            sorted(generate_urls_of_all_qualities(url, ["l", "x", "asd", "m"])),
            sorted(expected_urls),
        )


if __name__ == "__main__":
    unittest.main()
