# Overall imports
import functools
import os
import json
import sys
import dropbox
import pymysql
import smtplib
import boto3
import pandas as pd
import numpy as np
import queue

from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

from common import errors as er
from common import helpers


def run_test(func):

	@functools.wraps(func)
	def test(*args, **kwargs):
		
		data = None
		success = 1
		
		try: 

			data = func(*args, **kwargs)
		
		except Exception as e: 
			
			success = 0
			er.handle_error(error_code ='1')

		return(data, success)
	
	return(test)


@run_test
def test_sql_connect():

	helpers.sql_connect()


@run_test
def test_db_conn():

	helpers.db_conn()


@run_test
def test_db_engine():

	helpers.db_engine()


@run_test
def test_upload_dropbox():

	helpers.upload_dropbox()


@run_test
def test_download_file_s3():

	helpers.download_file_s3()


@run_test
def test_delete_files():

	helpers.delete_files()


@run_test
def test_send_email():

	helpers.send_email()


@run_test
def test_s3(test_file_source, test_file_dest):

	helpers.upload_file_s3(test_file_source, test_file_dest)


@run_test
def test_error_handling():

	msg = 'This is a test. If you see this the test has passed.'
	er.handle_error(error_code ='1', data = {'traceback': msg})

	
@run_test
def test_s3_list():
	
	test = helpers.get_matching_s3_keys(prefix='scripts', suffix='xlsx')
	return(test)


def main():

	results = []
	results.append(test_s3_list())
	return(results)


if __name__ == '__main__':

	results = main()
	print(results)