示例#1
0
def test_dq():
    u.init_log('test_dq', True)
    u.mkdirs(gl.OUT_DIR, True)
    u.log_print()

    u.log_print("Test dq no header", dashes=100)
    ttry(td.dq_t, g.E_MH, gl.IN_MH, gl.IN12, gl.OUT1)
    ttry(td.dq_t, g.E_DH, gl.IN11, gl.IN_DH, gl.OUT1)

    u.log_print("Test dup key", dashes=100)
    td.dq_t(gl.IN_DK, gl.IN12, gl.OUT1, tpd=True)

    u.log_print("Test different files comparison", dashes=100)
    dq.file_match(gl.REF1_F, gl.REF2_F, err=False, out_path=gl.OUT_FM)
    dq.file_match(gl.OUT_FM, gl.REF_FDM)

    u.log_print("Test dq No. 1", dashes=100)
    td.dq_t(gl.IN11, gl.IN12, gl.OUT1, gl.REF1, 100, gl.REF_DUP1, sl=10)
    td.dq_t(gl.IN11, gl.IN12, gl.OUT1, gl.REF1, 15, gl.REF_DUP1)
    td.dq_t(gl.IN11, gl.IN12, gl.OUT1, gl.REF1_E, eq=True)

    u.log_print("Test dq No. 2", dashes=100)
    td.dq_t(gl.IN21, gl.IN22, gl.OUT2, gl.REF2, 100, gl.REF_DUP2, 2)
    td.dq_t(gl.IN21, gl.IN22, gl.OUT2, gl.REF2, 15, gl.REF_DUP2, 2)
    td.dq_t(gl.IN21, gl.IN22, gl.OUT2, gl.REF2_E, eq=True)

    u.log_print("Test dq No. 3", dashes=100)
    td.dq_t(gl.IN31, gl.IN32, gl.OUT3, gl.REF3, 15)
    td.dq_t(gl.IN31, gl.IN32, gl.OUT3, gl.REF3_E, eq=True)
    td.dq_t(gl.IN31, gl.IN32, gl.OUT3, gl.REF3, 100, tps=True, mls=6)
    td.file_match(gl.REF_SPLIT_3, gl.OUT_SPLIT_3)

    u.check_log(td.CL)
示例#2
0
def test_sql():
    u.init_log("test_sql", True)
    if not ts.is_test_db_defined():
        return

    u.log_print("Test connect", dashes=100)
    ts.connect()

    u.log_print("Test iutd", dashes=100)
    ts.reset()
    ts.iutd()

    u.log_print("Test upload - missing header in input file", dashes=100)
    t.ttry(ts.upload, u.g.E_MH, gl.IN_MH)

    u.log_print("Test upload - interuption and recovery", dashes=100)
    ts.upload_interrupted()
    ts.upload(gl.IN, tr=True)

    u.log_print("Test download - no output", dashes=100)
    ts.download(gl.QUERY_NO, gl.DL_OUT, ti=True)

    u.log_print("Test download standard", dashes=100)
    ts.reset()
    ts.download(gl.QUERY, gl.DL_OUT)
    dq.file_match(gl.IN, gl.DL_OUT)
    dq.file_match(t.gl.OUT_DUP_TMP, gl.OUT_DUP_REF)

    s = "Test download RG with merge - interuption and recovery"
    u.log_print(s, dashes=100)
    ts.download_interrupted(gl.QUERY_RG, gl.DL_OUT_RG)
    ts.download(gl.QUERY_RG, gl.DL_OUT_RG, tr=True, sl=50)
    dq.file_match(gl.DL_OUT, gl.DL_OUT_RG)

    u.log_print("Test download RG without merge", dashes=100)
    ts.reset()
    ts.download(gl.QUERY_RG, gl.DL_OUT_RG, merge=False, cnx=1, sl=50)
    dq.file_match(gl.RG_REF, gl.RG_COMP)

    u.log_print("Test download - count simple", dashes=100)
    ts.reset()
    ts.download(gl.QUERY_COUNT_1, gl.DL_OUT_COUNT)
    dq.file_match(gl.DL_OUT_COUNT, gl.DL_OUT_COUNT_1_REF)
    ts.download(gl.QUERY_COUNT_1_RG, gl.DL_OUT_COUNT)
    dq.file_match(gl.DL_OUT_COUNT, gl.DL_OUT_COUNT_1_REF)

    u.log_print("Test download - count group by", dashes=100)
    ts.reset()
    ts.download(gl.QUERY_COUNT_2, gl.DL_OUT_COUNT)
    dq.file_match(gl.DL_OUT_COUNT, gl.DL_OUT_COUNT_2_REF)
    ts.download(gl.QUERY_COUNT_2_RG, gl.DL_OUT_COUNT)
    dq.file_match(gl.DL_OUT_COUNT, gl.DL_OUT_COUNT_2_REF)

    ts.clean_db([gl.T_TEST, gl.T_IUTD])

    u.check_log(ts.CL)
示例#3
0
def connect():
    from partools.test import ttry

    u.log_print('Test - nothing configured')
    (sql.gl.CNX_INFO, sql.gl.DB, sql.gl.ENV) = ('', '', '')
    ttry(sql.connect, sql.gl.E_1)
    u.log_print()

    u.log_print('Test - DB undefined')
    sql.gl.DB = 'TEST_DB'
    ttry(sql.connect, sql.gl.E_2.format('TEST_DB'))
    u.log_print()

    u.log_print('Test - ENV undefined')
    (sql.gl.DB, sql.gl.ENV) = ('TEST_DB', 'TEST_ENV')
    ttry(sql.connect, sql.gl.E_3.format('TEST_DB', 'TEST_ENV'))
    u.log_print()

    u.log_print('Test - OK DB only')
    (sql.gl.DB, sql.gl.ENV) = (gl.DB, '')
    sql.connect()
    u.log_print()

    u.log_print('Test - OK DB + ENV')
    (sql.gl.DB, sql.gl.ENV) = (gl.DB, gl.ENV)
    sql.connect()
    u.log_print()

    u.log_print('Test - OK CNX_INFO (via TNS_NAMES)')
    sql.gl.CNX_INFO = gl.CNX_INFO
    sql.connect()
    u.log_print()
    pass
示例#4
0
def test_rl():
    u.init_log('test_rl', True)
    if not ts.is_test_db_defined():
        return

    u.mkdirs(gl.TMP_DIR, True)
    u.mkdirs(ts.gl.TMP_DIR, True)
    u.mkdirs(gl.OUT_DIR, True)
    u.log_print()

    u.log_print('Test join', dashes=100)
    tr.left_join_files(gl.LEFT_1, gl.RIGHT_1, gl.OUT_JOIN_REF_1)
    tr.left_join_files(gl.LEFT_2, gl.RIGHT_2, gl.OUT_JOIN_REF_2)
    tr.left_join_files(gl.LEFT_3, gl.RIGHT_3, gl.OUT_JOIN_REF_3)

    u.log_print('Preparing DB', dashes=100)
    ts.upload(ts.gl.IN)
    arr = u.load_csv(ts.gl.IN)
    arr = [elt[0] for elt in arr]
    u.save_csv(arr, gl.IN_1)

    u.log_print('Test rl - no sql output', dashes=100)
    t.ttry(tr.reqlist, u.g.E_VA, gl.IN_1, gl.OUT_1, gl.QUERY_NO)

    u.log_print('Test rl - no var in query', dashes=100)
    t.ttry(tr.reqlist, u.g.E_MV, gl.IN_1, gl.OUT_1, gl.QUERY_MV)

    u.log_print('Test rl - missing header', dashes=100)
    u.save_csv(arr[1:], gl.IN_MH)
    t.ttry(tr.reqlist, u.g.E_MH, gl.IN_MH, gl.OUT_1, gl.QUERY_1)

    u.log_print('Test rl - standard', dashes=100)
    tr.reqlist(gl.IN_1, gl.OUT_1, gl.QUERY_1, cnx=1)
    tr.reqlist(gl.OUT_1, gl.OUT_2, gl.QUERY_2)
    dq.file_match(ts.gl.IN, gl.OUT_2, del_dup=True)
    dq.file_match(t.gl.OUT_DUP_TMP, gl.OUT_DUP_REF)

    u.log_print('Test rl - interuption and recovery', dashes=100)
    u.mkdirs(gl.TMP_DIR, True)
    u.log_print()
    args = [gl.OUT_1, gl.OUT_3, gl.QUERY_2]
    tr.reqlist_interrupted(*args, cnx=6)
    tr.reqlist(gl.OUT_1, gl.OUT_3, gl.QUERY_2, True, cnx=6)
    dq.file_match(gl.OUT_2, gl.OUT_3)

    ts.clean_db([ts.gl.T_TEST])

    u.check_log(tr.CL)
示例#5
0
def test_mail():
    u.init_log('test_mail', True)

    u.delete_folder('mail_back')
    if os.path.exists(cfg.MAILS_DIR):
        copytree(cfg.MAILS_DIR, 'mail_back')
        u.delete_folder(cfg.MAILS_DIR)

    u.log_print("Test gmail - KO, recipients not configureed", dashes=100)
    args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT]
    ttry(mail.gmail, gl.E_NOT_CONFIGURED, *args)
    u.log_print()

    u.log_print("Test gmail - KO, confidential file not found", dashes=100)
    recipients_path = cfg.MAILS_DIR + gl.MAIL_NAME + '/' + mail.gl.RECIPIENTS
    u.save_list(gl.RECIPIENTS_FILE, recipients_path)
    if os.path.exists(cfg.CFI_PATH):
        os.rename(cfg.CFI_PATH, cfg.CFI_PATH + '_')
    args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT]
    ttry(mail.gmail, gl.E_CFI, *args)
    os.rename(cfg.CFI_PATH + '_', cfg.CFI_PATH)
    u.log_print()

    mail.gl.TEST = True
    u.log_print(f"Test gmail - {gl.S_VDHT}", dashes=100)
    args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT]
    mail.gmail(*args)
    ast(gl.NVAR, gl.HT)
    u.log_print()

    u.log_print(f"Test gmail - {gl.S_VDPT}", dashes=100)
    args = [gl.MAIL_NAME, gl.S_VDPT, gl.VD, [], tm.BODY, gl.RECIPIENTS_IN, KEY]
    mail.gmail(*args)
    ast(gl.NVAR, gl.PT)
    u.log_print()

    u.log_print(f"Test gmail - {gl.S_HT}", dashes=100)
    args = [gl.MAIL_NAME, gl.S_HT]
    mail.gmail(*args)
    ast(gl.VAR, gl.HT)
    u.log_print()

    u.log_print(f"Test gmail - {gl.S_PT}", dashes=100)
    args = [gl.MAIL_NAME, gl.S_PT, [], [], tm.BODY]
    mail.gmail(*args)
    ast(gl.VAR, gl.PT)
    u.log_print()

    u.log_print("Test no_auth", dashes=100)
    args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT]
    ttry(mail.no_auth, gl.E_NO_AUT, *args)
    ast(gl.NVAR, gl.HT)
    u.log_print()

    u.log_print("Test outlook", dashes=100)
    args = [gl.MAIL_NAME, gl.S_VDPT, gl.VD, [], tm.BODY]
    ttry(mail.outlook, gl.E_OUTLOOK, *args)
    ast(gl.NVAR, gl.PT)
    u.log_print()

    # Restauring mail backup
    u.delete_folder(cfg.MAILS_DIR)
    copytree('mail_back', cfg.MAILS_DIR)
    u.delete_folder('mail_back')

    u.check_log(tm.CL)