import os, logging, errno, time
import xbridge_config

from utils import xbridge_utils

os.chdir(os.path.dirname(__file__))
program_dir = os.getcwd()

# LOG_DIR = program_dir + "\\logs\\"
LOG_DIR = program_dir + os.sep + "logs"

max_Char_Length = xbridge_config.get_param_max_char_length_to_display()

try:
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)
except OSError as e:
    if e.errno != errno.EEXIST:
        LOG_DIR = ""
        raise

log_time_str = time.strftime("%Y%m%d-%H%M%S")
# log_file_name_str = xbridge_config.get_conf_log_dir() + log_time_str + "_testing_log.txt"
log_file_name_str = LOG_DIR + os.sep + log_time_str + "_testing_log.txt"
print("log files will be logged there: %s" % log_file_name_str)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.FileHandler(log_file_name_str)
formatter = logging.Formatter('%(message)s')
handler.setFormatter(formatter)
import unittest
import xbridge_logger
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

from interface import xbridge_rpc
from utils import xbridge_utils

import sys
sys.path.insert(0, '..')
import xbridge_config

MAX_LOG_LENGTH = xbridge_config.get_param_max_char_length_to_display()


class Info_Polling_UnitTest(unittest.TestCase):
    def test_get_transactions(self):
        try:
            self.assertIsInstance(xbridge_rpc.dxGetTransactions(), list)
            log_json = {
                "group": "test_get_transactions",
                "success": 1,
                "failure": 0,
                "error": 0
            }
            xbridge_utils.ERROR_LOG.append(log_json)
        except AssertionError as ass_err:
            log_json = {
                "group": "test_get_transactions",
                "success": 0,
                "failure": 1,
                "error": 0