def print_log(log, level="info"): formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") logger = logging.getLogger("ATF") logger.setLevel(logging.DEBUG) config_path = get_config("logging", "path") log_path = config_path if config_path else get_log_dir() if log_path: fh = logging.FileHandler(log_path + os.sep + "%s.log" % get_current_date()) fh.setLevel(int(get_config("logging", "level"))) fh.setFormatter(formatter) if "FileHandler" not in str(logger.handlers): logger.addHandler(fh) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(formatter) if "StreamHandler" not in str(logger.handlers): logger.addHandler(ch) logger.log(_get_num_level(level), log) if "FileHandler" in str(logger.handlers): fh.close() ch.close()
def print_log(log, level="info"): formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger("ATF") logger.setLevel(logging.DEBUG) config_path = get_config("logging", "path") log_path = config_path if config_path else get_log_dir() if log_path: fh = logging.FileHandler(log_path + os.sep + "%s.log" % get_current_date()) fh.setLevel(int(get_config("logging", "level"))) fh.setFormatter(formatter) if "FileHandler" not in str(logger.handlers): logger.addHandler(fh) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(formatter) if "StreamHandler" not in str(logger.handlers): logger.addHandler(ch) logger.log(_get_num_level(level), log) if "FileHandler" in str(logger.handlers): fh.close() ch.close()
class MySQL(object): config = { 'user': get_config("mysql", "user"), 'password': get_config("mysql", "pass"), 'host': get_config("mysql", "host"), 'database': get_config("mysql", "db"), 'raise_on_warnings': True, } def __init__(self): try: self.cnn = mysql.connector.connect(**self.config) except mysql.connector.Error as e: print(('connect fails!{}'.format(e)))
def execute_test(test_suite): """ :summary: Execute test cases. :param test_suite: Test suite. """ exec_type = get_config("run-time", "mode") print_log("="*80, "info") print_log( "Execution started, execution type is %s, " % exec_type ) print_log("Testcase(s) to run is(are): \n%s" % str(test_suite)) result_file = get_test_report_path() fp = open(result_file, 'wb') runner = HTMLTestRunner( stream=fp, title="Automation test report", description=( "Automation test report\n" "Execution type is %s" % exec_type ) ) runner.run(test_suite)
def print_log(log, level="info"): formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger("ATF") logger.setLevel(logging.DEBUG) config_path = get_config("logging", "path") log_path = config_path if config_path else get_tmp_dir() if log_path: fh = logging.FileHandler(log_path + os.sep + "log.log") # TODO: Log file name should be more intelligent. fh.setLevel(int(get_config("logging", "level"))) fh.setFormatter(formatter) logger.addHandler(fh) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) ch.setFormatter(formatter) logger.addHandler(ch) logger.log(_get_num_level(level), log)
def setUp(self): host = get_config("selenium", "host") port = get_config("selenium", "port") browser = get_config("selenium", "browser").lower() if browser == "firefox": # Set profile of Firefox profile = webdriver.FirefoxProfile() profile.set_preference( "intl.accept_languages", "en-us, en, en-us, en" ) profile.set_preference( "extensions.addonnotification.showDaytip", "false" ) # Turn off daily tips of Firefox profile.set_preference( "*****@*****.**", "0" ) # Turn off the tip of Firefox passport self.driver = webdriver.Firefox(profile) elif browser == "ie": self.driver = webdriver.Ie() elif browser == "chrome": self.driver = webdriver.Chrome() else: print_log("The browser is not supported! " "Please check your AFT.ini!", "error") raise NoSuchWindowException("The browser you set is not supported, " "please check your config file.") self.driver.maximize_window() self.driver.implicitly_wait( get_config("selenium", "implicitly_wait_time") ) if port: self.driver.get(host + ":" + port) else: print_log("No port is specified.", "debug") self.driver.get(host)
def create(): """ Connect to MySQL database """ conn = None try: dbconf = get_config(config_type='db', section='mysql') conn = pymysql.connect(host=dbconf['host'], database=dbconf['database'], user=dbconf['user'], password=dbconf['password'], port=int(dbconf['port']), autocommit=True) print('Connected to MySQL database') except Error as e: print(e) return conn
def execute_test(test_suite): """ :summary: Execute test cases. :param test_suite: Test suite. """ exec_type = get_config("run-time", "mode") print_log("=" * 80, "info") print_log("Execution started, execution type is %s, " % exec_type) print_log("Testcase(s) to run is(are): \n%s" % str(test_suite)) result_file = get_test_report_path() fp = open(result_file, 'wb') runner = HTMLTestRunner(stream=fp, title="Automation test report", description=("Automation test report\n" "Execution type is %s" % exec_type)) runner.run(test_suite)
def execute_test(test_suite): """ @summary: Execute test cases. @param test_suite: Test suite. """ exec_type = get_config("run-time", "mode") print_log("Testcase(s) to run is(are): %s" % test_suite) result_file = "D:\\test_result.html" fp = file(result_file, 'wb') runner = HTMLTestRunner( stream=fp, title=u"Automation test report", description=( u"Automation test report\n" u"Execution type is %s" % exec_type ) ) runner.run(test_suite)
""" :summary: Execute test cases. :param test_suite: Test suite. """ exec_type = get_config("run-time", "mode") print_log("=" * 80, "info") print_log("Execution started, execution type is %s, " % exec_type) print_log("Testcase(s) to run is(are): \n%s" % str(test_suite)) result_file = get_test_report_path() fp = open(result_file, 'wb') runner = HTMLTestRunner(stream=fp, title="Automation test report", description=("Automation test report\n" "Execution type is %s" % exec_type)) runner.run(test_suite) if __name__ == "__main__": cmd_mode = get_opt().get("mode") mode = cmd_mode if cmd_mode else get_config("run-time", "mode") test_cases = get_testcase(mode) # test_cases = [ # "testcase.web.login_demo.ValidLogin", # ] suite = get_test_suite(test_cases) # unittest.TextTestRunner(verbosity=2).run(suite) execute_test(suite)
def sync_currecies(): # -------------------------------------------------------------------- # READ STOCK CACHED PARAMS # -------------------------------------------------------------------- socket_generic_arguments_dict = get_config(config_type='stock', section='generic-arguments') # -------------------------------------------------------------------- # CREATE CONNECTION # -------------------------------------------------------------------- con = connector.create() cursor = con.cursor() # -------------------------------------------------------------------- # COLLECT OUR COINS IN DB # -------------------------------------------------------------------- data_cap_from_db = pd.read_sql('Select * from currency', con=con) data_cap_from_db.set_index(['id'], inplace=True) # -------------------------------------------------------------------- # COLLECT ALL COINS AND THEIR GENERAL STATISTICS # -------------------------------------------------------------------- market_cap = mc.Cap() data_cap = market_cap.get_data() # -------------------------------------------------------------------- # FILTER OUT INVALUABLE COINS FROM THE LIST SO THAT WE CAN FOCUS ON VALUABLE ONES. # -------------------------------------------------------------------- # read from stock config files limit_coin_24h_usd_volume = int( socket_generic_arguments_dict['limit_coin_24h_usd_volume']) data_cap = data_cap[ data_cap['24h_volume_usd'] >= limit_coin_24h_usd_volume] data_cap.set_index(['id'], inplace=True) # -------------------------------------------------------------------- # COMPARE TWO SET FOR DIFFERENCES # -------------------------------------------------------------------- currency_index_from_db = pd.Index(data_cap_from_db.index) currency_index_from_site = pd.Index(data_cap.index) new_index_from_site = currency_index_from_site.difference( currency_index_from_db) # -------------------------------------------------------------------- # FILTER THESE IDs FROM CAP SITE DATAFRAEM # -------------------------------------------------------------------- data_cap = data_cap.reindex(new_index_from_site, fill_value='missing') len_data_cap = len(data_cap) # -------------------------------------------------------------------- # NEW DATA CAPS ARE BEING WRITTEN INTO CURRENCY TABLES # -------------------------------------------------------------------- if len_data_cap > 0: print(len_data_cap, 'new currencies are going to be written in currency table') for _index, _row in data_cap.iterrows(): values = "'" + _row['symbol'] + "','" + str( _row['Insertion_Time'] ) + "','" + _index + "','" + _row['name'] + "'" cursor.execute( "INSERT INTO currency(symbol, inserted_time, id, name) VALUES (" + values + ")") print('New currencies are inserted to table') else: print('Nothing new to be inserted') # -------------------------------------------------------------------- # CONNECTION DISCONNECTED # -------------------------------------------------------------------- connector.disconnect(con)
def get_time(): if sys.platform == 'win32': default_timer = time.clock() else: default_timer = time.time() return default_timer def convert_timer_to_readable(time): hours, rem = divmod(time, 3600) minutes, seconds = divmod(rem, 60) return "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds) if __name__ == '__main__': socket_generic_arguments_dict = get_config(config_type='stock', section='generic-arguments') currency_update_interval = eval( socket_generic_arguments_dict['currency_update_interval']) print('Application is started on', time.time()) iteration = 0 # ---------------------------------------- # CODE TEST # ---------------------------------------- _exchange = Exchanges() aa = _exchange.get_data() print(aa.head()) # while True: # iteration_start = get_time() # print('*' * 50) # print('*' * 25)
class BaseWizard(LoginObject): """ @summary: All wizards' father class """ def login_as(self, user_name=None, password=None): self.input_username.send_keys(user_name) self.input_password.send_keys(password) self.button_login.click() def logout(self): if not self.is_logout(): self.link_logout.click() return self.is_logout() else: print_log("No need, you are already logging out.") def is_logout(self): return True if __name__ == "__main__": driver = webdriver.Firefox() driver.implicitly_wait(30) driver.get("%s" % get_config("selenium", "host")) bw = BaseWizard(driver) bw.login_as("atf_test", "itestQA") bw.logout() sleep(10) driver.quit()
import requests import pandas as pd from utility.config_parser import get_config bitfinex_stock_dict = get_config(config_type='stock', section='bitfinex') symbols_with_details_api = bitfinex_stock_dict['symbols_with_details_api'] symbols_with_details_data = pd.read_json(symbols_with_details_api) print(xx.head())
def __init__(self): self._db_host = get_config("mongo", "host") self._port = int(get_config("mongo", "port")) self._db_name = get_config("mongo", "db") self.client = pymongo.MongoClient(self._db_host, self._port)
print_log("="*80, "info") print_log( "Execution started, execution type is %s, " % exec_type ) print_log("Testcase(s) to run is(are): \n%s" % str(test_suite)) result_file = get_test_report_path() fp = open(result_file, 'wb') runner = HTMLTestRunner( stream=fp, title="Automation test report", description=( "Automation test report\n" "Execution type is %s" % exec_type ) ) runner.run(test_suite) if __name__ == "__main__": cmd_mode = get_opt().get("mode") mode = cmd_mode if cmd_mode else get_config("run-time", "mode") test_cases = get_testcase(mode) # test_cases = [ # "testcase.web.login_demo.ValidLogin", # ] suite = get_test_suite(test_cases) # unittest.TextTestRunner(verbosity=2).run(suite) execute_test(suite)