from django.test import SimpleTestCase

from api_v1.mdy_plate_order_staging_tiia_upload import _pick_attachment_url


class MDYPlateOrderStagingTiiaUploadUrlPickTest(SimpleTestCase):
    def test_prefers_original_file_full_path(self):
        item = {
            "original_file_full_path": "https://example.com/original.png",
            "DownloadUrl": "https://example.com/download.png",
            "preview_url": "https://example.com/preview.png?token=xxx",
        }
        picked = _pick_attachment_url(item)
        self.assertEqual(picked.url, "https://example.com/original.png")
        self.assertEqual(picked.source_field, "original_file_full_path")

    def test_fallbacks_to_download_url(self):
        item = {
            "DownloadUrl": "https://example.com/download.png",
        }
        picked = _pick_attachment_url(item)
        self.assertEqual(picked.url, "https://example.com/download.png")
        self.assertEqual(picked.source_field, "DownloadUrl")

    def test_returns_none_when_missing(self):
        item = {"preview_url": "https://example.com/preview.png?token=xxx"}
        picked = _pick_attachment_url(item)
        self.assertIsNone(picked.url)
        self.assertIsNone(picked.source_field)

