# Path: studio/model.py
# def reset_storage_providers():
# def get_config(config_file=None):
# def get_db_provider(config=None, blocking_auth=True):
# def get_queue(
#         queue_name=None,
#         cloud=None,
#         config=None,
#         logger=None,
#         close_after=None,
#         verbose=10):
# def shutdown_queue(queue, logger=None, delete_queue=True):
# def get_worker_manager(config, cloud=None, verbose=10):
# 
# Path: studio/extra_util.py
# def has_aws_credentials():
#     artifact_store = storage_setup.get_storage_artifact_store()
#     if artifact_store is None:
#         return False
#     storage_handler = artifact_store.get_storage_handler()
#     if storage_handler.type == StorageType.storageS3:
#         storage_client = storage_handler.get_client()
#         return storage_client._request_signer._credentials is not None
#     else:
#         return False


import unittest
import subprocess
import time
import os
import tempfile
import uuid
from random import randint
from studio import model
from model_test import get_test_experiment
from studio.extra_util import has_aws_credentials
from env_detect import on_gcp, on_aws
        # self.serverp.start()
        self.server_config_file = os.path.join(
            os.path.dirname(
                os.path.realpath(__file__)),
            'test_config_http_server.yaml')

        print(self.server_config_file)

        self.client_config_file = os.path.join(
            os.path.dirname(
                os.path.realpath(__file__)),
            'test_config_http_client.yaml')

        self.serverp = subprocess.Popen([
            'studio-ui',
            '--port=' + str(self.port),
            '--verbose=debug',
            '--config=' + self.server_config_file,
            '--host=localhost'])

        time.sleep(25)

    @classmethod
    def tearDownClass(self):
        print("Shutting down the API server")
        self.serverp.kill()

    def get_db_provider(self):
        config = model.get_config(self.client_config_file)
        config['database']['serverUrl'] = 'http://localhost:' + str(self.port)

# Path: studio/model.py
# def reset_storage_providers():
# def get_config(config_file=None):
# def get_db_provider(config=None, blocking_auth=True):
# def get_queue(
#         queue_name=None,
#         cloud=None,
#         config=None,
#         logger=None,
#         close_after=None,
#         verbose=10):
# def shutdown_queue(queue, logger=None, delete_queue=True):
# def get_worker_manager(config, cloud=None, verbose=10):
# 
# Path: studio/extra_util.py
# def has_aws_credentials():
#     artifact_store = storage_setup.get_storage_artifact_store()
#     if artifact_store is None:
#         return False
#     storage_handler = artifact_store.get_storage_handler()
#     if storage_handler.type == StorageType.storageS3:
#         storage_client = storage_handler.get_client()
#         return storage_client._request_signer._credentials is not None
#     else:
#         return False


# Path: tests/http_provider_test.py
import unittest
import subprocess
import time
import os
import tempfile
import uuid
from random import randint
from studio import model
from model_test import get_test_experiment
from studio.extra_util import has_aws_credentials
from env_detect import on_gcp, on_aws

        # self.serverp.start()
        self.server_config_file = os.path.join(
            os.path.dirname(
                os.path.realpath(__file__)),
            'test_config_http_server.yaml')

        print(self.server_config_file)

        self.client_config_file = os.path.join(
            os.path.dirname(
                os.path.realpath(__file__)),
            'test_config_http_client.yaml')

        self.serverp = subprocess.Popen([
            'studio-ui',
            '--port=' + str(self.port),
            '--verbose=debug',
            '--config=' + self.server_config_file,
            '--host=localhost'])

        time.sleep(25)

    @classmethod
    def tearDownClass(self):
        print("Shutting down the API server")
        self.serverp.kill()

    def get_db_provider(self):
        config = model.get_config(self.client_config_file)
        config['database']['serverUrl'] = 'http://localhost:' + str(self.port)

        return model.get_db_provider(config)