import os

from django.test import TestCase, override_settings

from app_data.filestore import tmp_local_filepath, uuid_to_filepath

FAKE_FILESTORE = "/tmp/cavaliba_test_filestore"


@override_settings(CAVALIBA_FILESTORE=FAKE_FILESTORE)
class FilestorePathTest(TestCase):
    def test_uuid_to_filepath_returns_string(self):
        result = uuid_to_filepath("abc-123")
        self.assertIsInstance(result, str)

    def test_uuid_to_filepath_contains_fileid(self):
        fileid = "f5fd12d3-a65a-4cf8-b3c1-22059ea3cbd5"
        result = uuid_to_filepath(fileid)
        self.assertIn(fileid, result)

    def test_uuid_to_filepath_uses_settings(self):
        fileid = "abc-123"
        result = uuid_to_filepath(fileid)
        self.assertTrue(result.startswith(FAKE_FILESTORE))

    def test_uuid_to_filepath_joined_correctly(self):
        fileid = "abc-123"
        result = uuid_to_filepath(fileid)
        self.assertEqual(result, os.path.join(FAKE_FILESTORE, fileid))

    def test_tmp_local_filepath_returns_string(self):
        result = tmp_local_filepath()
        self.assertIsInstance(result, str)

    def test_tmp_local_filepath_uses_settings(self):
        result = tmp_local_filepath()
        self.assertTrue(result.startswith(FAKE_FILESTORE))

    def test_tmp_local_filepath_starts_with_tmp(self):
        result = tmp_local_filepath()
        filename = os.path.basename(result)
        self.assertTrue(filename.startswith("tmp-"))

    def test_tmp_local_filepath_is_unique(self):
        result1 = tmp_local_filepath()
        result2 = tmp_local_filepath()
        self.assertNotEqual(result1, result2)
