# coding: utf-8

"""
    BeeKeeperAI EscrowAI Enclave API

    Described below is the EscrowAI Enclave API that provides functionality inside a BeeKeeperAI environment. Included are data engineering endpoints and reporting endpoints.

    The version of the OpenAPI document: 1.5.0
    Contact: engineering@beekeeperai.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


import unittest
from unittest.mock import create_autospec, patch, MagicMock

import BeeKeeperRuntimeSDK
from BeeKeeperRuntimeSDK.api.data_api import DataApi  # noqa: E501
from BeeKeeperRuntimeSDK.rest import ApiException
from BeeKeeperRuntimeSDK.api_response import ApiResponse
from BeeKeeperRuntimeSDK.models.sql_response import SQLResponse
from BeeKeeperRuntimeSDK.models.sql_query import SQLQuery
from BeeKeeperRuntimeSDK.models.get_available_files200_response import GetAvailableFiles200Response


class TestDataApi(unittest.TestCase):
    """DataApi unit test stubs"""

    @patch.object(
        BeeKeeperRuntimeSDK.api.data_api.ApiClient,
        "get_default",
        return_value=MagicMock(spec=BeeKeeperRuntimeSDK.api.data_api.ApiClient),
        autospec=True
    )
    def setUp(self, mock_client):
        self.api = BeeKeeperRuntimeSDK.api.data_api.DataApi()  # noqa: E501
        self.mock_api_client = mock_client

    def tearDown(self):
        pass

    def test_data_files_filename_get(self):
        """Test case for data_files_filename_get

        Retrieve a file by its filename  # noqa: E501
        """
        mock_response = MagicMock(spec=ApiResponse)
        mock_response.data = bytearray()
        mock_response.raw_data = bytearray()
        self.mock_api_client.return_value.call_api.return_value = mock_response
        response = self.api.data_files_filename_get('testfile')
        self.mock_api_client.return_value.call_api.assert_called()
        args, kwargs = self.mock_api_client.return_value.call_api.call_args
        assert args[0] == '/data/files/{filename}'
        assert args[1] == 'GET'
        assert args[2] == {'filename': 'testfile'}
        assert args[3] == []
        assert isinstance(response, ApiResponse)
        assert isinstance(response.data, bytearray)

    def test_data_sql_select_post(self):
        """Test case for data_sql_select_post

        Execute a SQL query  # noqa: E501
        """
        mock_sql_query = SQLQuery(query='SELECT * FROM USERS;', message='Goku')
        mock_response = MagicMock(spec=SQLResponse, results=[{"name": "Goku"}], message="Goku")
        self.mock_api_client.return_value.call_api.return_value = mock_response
        response = self.api.data_sql_select_post(mock_sql_query)
        self.mock_api_client.return_value.call_api.assert_called()
        args, kwargs = self.mock_api_client.return_value.call_api.call_args
        assert args[0] == '/data/sql/select'
        assert args[1] == 'POST'
        assert args[2] == {}
        assert args[3] == []
        assert isinstance(response, SQLResponse)

    def test_get_available_files(self):
        """Test case for get_available_files

        Retrieve a list of available files  # noqa: E501
        """
        self.mock_api_client.return_value.call_api.return_value = MagicMock(spec=GetAvailableFiles200Response)
        response = self.api.get_available_files(1, 20)
        self.mock_api_client.return_value.call_api.assert_called()
        args, kwargs = self.mock_api_client.return_value.call_api.call_args
        assert args[0] == '/data/files'
        assert args[1] == 'GET'
        assert args[2] == {}
        assert args[3] == [('page', 1), ('limit', 20)]
        assert isinstance(response, GetAvailableFiles200Response)


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