import unittest
import sys
for path in ['../', './']:
    sys.path.insert(1, path)

#####################################
### Don't include for test report ###
#####################################

try:
    class TestCoverage(unittest.TestCase):
        def test_init_main(self):
            try:
                # python -m unittest discover
                # add modules folder to interpreter path
                import sys
                import os
                import prance
                from pathlib import Path

                modules_path = '../../../modules/'
                if os.path.exists(modules_path):
                    sys.path.insert(1, modules_path)

                # init logging to file
                import logging
                LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d:  %(message)s')
                logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
                LOGGER = logging.getLogger(__name__)
            except Exception as e:
                print ("Exception found:")
                print (e)

            #############################
            try:
                import connexion
                from security import swagger_util
                from env_info import is_running_locally, get_resources_path 
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from database.repository import Repository
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from messaging.MessageHandler import MessageHandler
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from messaging.ReconnectingMessageManager import ReconnectingMessageManager
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from messaging.rest_fetcher import RestFetcher
                from flask import request
                from flask import redirect
            except Exception as e:
                print ("Exception found:")
                print (e)
            try:
                import main
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_database(self):
            # global imports (dont't worry, red is normal)
            try:
                from typing import List, Dict
                import network_constants as netconst
                from database.MongoRepositoryBase import MongoRepositoryBase
                from database.entities.transaction import Transaction
                
                import pymongo
                import json
                import time
            except Exception as e:
                print ("Exception found:")
                print (e)
            try:
                from database import repository
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_messaging(self):
            try:
                from security.token_manager import TokenManager
                import network_constants
                from database.entities.transaction import Transaction
                from database.repository import Repository
                from messaging.rest_fetcher import RestFetcher

                import json
                import hashlib
                import logging
                import requests

                from typing import Dict
                from typing import List
            except Exception as e:
                print ("Exception found:")
                print (e)
            try:
                from messaging import MessageHandler
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from messaging import rest_fetcher
            except Exception as e:
                print ("Exception found:")
                print (e)

        def test_routes(self):
            #global imports
            try:
                from database.entities.transaction import Transaction
                from database.repository import Repository
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                import json
                from flask import Response, request
            except Exception as e:
                print ("Exception found:")
                print (e)

            try:
                from routes import transactions
            except Exception as e:
                print ("Exception found:")
                print (e)

        

    if __name__ == '__main__':
        unittest.main()
except Exception as e:
    print ("Exception found:")
    print (e)