"""
Test dataset-related operations
"""

from unittest.mock import patch

import pytest

from galaxy_mcp.server import galaxy_state, upload_file


class TestDatasetOperations:
    """Test dataset operations"""

    def test_upload_file(self, mock_galaxy_instance):
        """Test file upload to history"""
        mock_galaxy_instance.tools.upload_file.return_value = {
            "outputs": [{"id": "new_dataset_1", "name": "test.txt"}]
        }

        with patch.dict(galaxy_state, {"connected": True, "gi": mock_galaxy_instance}):
            with patch("os.path.exists", return_value=True):
                result = upload_file("/path/to/test.txt", "test_history_1")

                assert result["outputs"][0]["id"] == "new_dataset_1"
                assert result["outputs"][0]["name"] == "test.txt"
                mock_galaxy_instance.tools.upload_file.assert_called_once()

    def test_upload_file_not_found(self, mock_galaxy_instance):
        """Test upload with non-existent file"""
        with patch.dict(galaxy_state, {"connected": True, "gi": mock_galaxy_instance}):
            with patch("os.path.exists", return_value=False):
                with pytest.raises(ValueError, match="File not found"):
                    upload_file("/nonexistent/file.txt", "test_history_1")

    def test_download_dataset(self, mock_galaxy_instance):
        """Test dataset download"""
        # Download functionality doesn't exist in current implementation
        # This test is a placeholder for future functionality
        pass

    def test_get_dataset_details(self, mock_galaxy_instance):
        """Test getting dataset details"""
        # Dataset details functionality doesn't exist in current implementation
        # This test is a placeholder for future functionality
        pass

    def test_dataset_operations_not_connected(self):
        """Test dataset operations fail when not connected"""
        with patch.dict(galaxy_state, {"connected": False}):
            with pytest.raises(Exception):
                upload_file("/path/to/file.txt", "history_1")

            # Download and get_dataset_details don't exist yet
            pass
