def test_filter_files(self): self.setup_dir() files = search_files(get_base_dir(), get_output_dir()) save_result(convert(files, get_output_dir())) self.overwrite_file() files = search_files(get_base_dir(), get_output_dir()) for sub_folder in files: file_list = filter_files(files[sub_folder]) if sub_folder == 'Concord': self.assertEqual(len(file_list), 1) else: self.assertEqual(len(file_list), 0) save_result(convert(files, get_output_dir())) self.copy_more_files() files = search_files(get_base_dir(), get_output_dir()) for sub_folder in files: file_list = filter_files(files[sub_folder]) if sub_folder == 'DIF': self.assertEqual(len(file_list), 2) else: self.assertEqual(len(file_list), 0) save_result(convert(files, get_output_dir())) self.delete_files() files = search_files(get_base_dir(), get_output_dir()) for sub_folder in files: file_list = filter_files(files[sub_folder]) self.assertEqual(len(file_list), 0)
def test_convert_dif(self): files = {'DIF': \ [join(get_current_path(), 'samples', 'base_dir2', 'DIF', 'CL Franklin DIF 2016-12-12.xls'), \ join(get_current_path(), 'samples', 'base_dir2', 'DIF', 'CL Franklin DIF 2016-12-15.xls')]} output_dir = join(get_current_path(), 'samples', 'base_dir2', 'result') result = convert(files, output_dir) self.assertEqual(len(result), 3) self.assertEqual(len(result['fail']), 0) self.assertEqual(len(result['pass']), 2) self.assertEqual(result['pass'][0], files['DIF'][0]) self.assertEqual(result['pass'][1], files['DIF'][1]) save_result(result)
def test_convert_jpm(self): files = {'ListCo Equity': [join(get_current_path(), 'samples', 'base_dir1', 'ListCo Equity', 'Positions1219.xlsx'), \ join(get_current_path(), 'samples', 'base_dir1', 'CLO Equity', 'positions - 20161130.xls'), \ join(get_current_path(), 'samples', 'base_dir1', 'CLO Equity', 'JP Morgan Broker Statement 2016-07-06.xls')]} output_dir = join(get_current_path(), 'samples', 'base_dir1', 'result') result = convert(files, output_dir) self.assertEqual(len(result), 3) self.assertEqual(len(result['fail']), 0) self.assertEqual(len(result['pass']), 3) self.assertEqual(result['pass'][0], files['ListCo Equity'][0]) self.assertEqual(result['pass'][1], files['ListCo Equity'][1]) self.assertEqual(result['pass'][2], files['ListCo Equity'][2])
def test_convert_bochk(self): files = {'Concord': \ [join(get_current_path(), 'samples', 'base_dir1', 'Concord', 'Holding _ 19122016.xls'), \ join(get_current_path(), 'samples', 'base_dir1', 'Concord', 'Cash Stt _ 19122016.xls'), \ join(get_current_path(), 'samples', 'base_dir1', 'Concord', 'Cash Stt _ 13122016.xls'), \ join(get_current_path(), 'samples', 'base_dir1', 'Concord', 'sample.txt'), \ join(get_current_path(), 'samples', 'base_dir1', 'Concord', 'Holding _ 20122016.xls')]} output_dir = join(get_current_path(), 'samples', 'base_dir1', 'result') result = convert(files, output_dir) self.assertEqual(len(result), 3) self.assertEqual(len(result['pass']), 3) self.assertEqual(len(result['fail']), 1) self.assertEqual(result['pass'][0], files['Concord'][0]) self.assertEqual(result['pass'][1], files['Concord'][1]) self.assertEqual(result['pass'][2], files['Concord'][2]) self.assertEqual(result['fail'][0], files['Concord'][4]) save_result(result)
def test_result(self): # # copy some files to test # self.setup_dir() files = search_files(get_base_dir(), get_output_dir()) result = convert(files, get_output_dir()) save_result(result) c = get_db_cursor() sql = '''SELECT * FROM file_status''' c.execute(sql) self.assertEqual(len(c.fetchall()), 4) sql = '''SELECT * FROM process_result''' c.execute(sql) self.assertEqual(len(c.fetchall()), 4) sql = '''SELECT * FROM file_status where status="fail"''' c.execute(sql) result = c.fetchall() self.assertEqual(len(result), 1) # print(result[0]) self.assertEqual( result[0][0], join(get_base_dir(), 'Concord', 'Holding _ 20122016.xls')) self.assertEqual(result[0][1], '2016-12-28 17:19:48') # # now overwrite one file with a newer file. # self.overwrite_file() files = search_files(get_base_dir(), get_output_dir()) save_result(convert(files, get_output_dir())) c = get_db_cursor() sql = '''SELECT * FROM file_status''' c.execute(sql) self.assertEqual(len(c.fetchall()), 4) sql = '''SELECT * FROM file_status where status="fail"''' c.execute(sql) result = c.fetchall() self.assertEqual(len(result), 0) # should have no fails # previously failed file now should be OK sql = '''SELECT * FROM file_status where file_fullpath="{0}"'''.\ format(join(get_base_dir(), 'Concord', 'Holding _ 20122016.xls')) c.execute(sql) result = c.fetchone() self.assertEqual(result[1], '2016-12-28 17:43:16') self.assertEqual(result[2], 'pass') sql = '''SELECT * FROM process_result''' c.execute(sql) self.assertEqual(len(c.fetchall()), 5) # one more record added sql = '''SELECT * FROM process_result where file_fullpath="{0}" and m_time="{1}"'''.\ format(join(get_base_dir(), 'Concord', 'Holding _ 20122016.xls'), \ '2016-12-28 17:43:16') c.execute(sql) result = c.fetchone() # print(result) self.assertNotEqual(result, None) # the record should exist # # some more files come in # self.copy_more_files() files = search_files(get_base_dir(), get_output_dir()) save_result(convert(files, get_output_dir())) c = get_db_cursor() sql = '''SELECT * FROM file_status''' c.execute(sql) self.assertEqual(len(c.fetchall()), 6) sql = '''SELECT * FROM file_status where file_fullpath="{0}"'''.\ format(join(get_base_dir(), 'DIF', 'CL Franklin DIF 2016-12-12.xls')) c.execute(sql) result = c.fetchone() self.assertEqual(result[1], '2016-12-13 18:11:27') self.assertEqual(result[2], 'pass') sql = '''SELECT * FROM process_result''' c.execute(sql) self.assertEqual(len(c.fetchall()), 7) sql = '''SELECT m_time,result FROM process_result where file_fullpath="{0}"'''.\ format(join(get_base_dir(), 'DIF', 'CL Franklin DIF 2016-12-15.xls')) c.execute(sql) result = c.fetchall() # print(result) self.assertEqual(len(result), 1) self.assertEqual(result[0][0], '2016-12-16 18:22:51') self.assertEqual(result[0][1], 'pass') # # now delete some files # self.delete_files() files = search_files(get_base_dir(), get_output_dir()) save_result(convert(files, get_output_dir())) c = get_db_cursor() sql = '''SELECT * FROM file_status''' c.execute(sql) self.assertEqual(len(c.fetchall()), 6) # should have no change sql = '''SELECT * FROM file_status where file_fullpath="{0}"'''.\ format(join(get_base_dir(), 'Concord', 'Holding _ 20122016.xls')) c.execute(sql) result = c.fetchone() self.assertEqual(result[1], '2016-12-28 17:43:16') self.assertEqual(result[2], 'pass') sql = '''SELECT * FROM process_result''' c.execute(sql) self.assertEqual(len(c.fetchall()), 7) # should have no change sql = '''SELECT m_time,result FROM process_result where file_fullpath="{0}"'''.\ format(join(get_base_dir(), 'DIF', 'CL Franklin DIF 2016-12-15.xls')) c.execute(sql) result = c.fetchall() # print(result) self.assertEqual(len(result), 1) self.assertEqual(result[0][0], '2016-12-16 18:22:51') self.assertEqual(result[0][1], 'pass')