def test_copy_files(self):
     delete_test_temp_files()
     self.assertEqual(len(glob(join(get_test_temp_dir(), '*.txt'))), 0)
     file_list = [join(get_current_path(), 'samples', 'log_0file.txt'), \
                     join(get_current_path(), 'samples', 'log_3files.txt')]
     copy_files(file_list, get_test_temp_dir())
     self.assertEqual(len(glob(join(get_test_temp_dir(), '*.txt'))), 2)
Beispiel #2
0
 def test_is_bochk_cash_file(self):
     file1 = join(
         get_current_path(), 'samples',
         'BOC Bank Statement 2012-06-30 (OVERSEAS (CAPITAL) SUB FUND BOND)-HKD.xls'
     )
     file2 = join(
         get_current_path(), 'samples',
         'BOC Bank Statement 2016-11-30 (CLASS A-HK SUB FUND I) -HKD.xls')
     self.assertFalse(is_bochk_cash_file(file1))
     self.assertTrue(is_bochk_cash_file(file2))
Beispiel #3
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)
Beispiel #4
0
 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])
Beispiel #5
0
    def test_search_file(self):
        """
        Use samples\base_dir1 to test.
        """
        base_dir = join(get_current_path(), 'samples', 'base_dir1')
        output_dir = join(get_current_path(), 'samples', 'base_dir1', 'result')
        files = search_files(base_dir, output_dir)
        self.assertTrue(self.verify_sub_folders(list(files.keys())))

        # sub folders under Concord is not counted, only files
        self.assertEqual(len(files['Concord']), 5)
        self.assertEqual(len(files['ListCo Equity']), 1)
        self.assertEqual(len(files['CLO Equity']), 2)
        self.assertEqual(files['ListCo Equity'][0],
                         join(base_dir, 'ListCo Equity', 'Positions1219.xlsx'))
    def test_read_log(self):
        pass_list = read_log(
            join(get_current_path(), 'samples', 'log_0file.txt'))
        self.assertEqual(len(pass_list), 0)

        pass_list = read_log(
            join(get_current_path(), 'samples', 'log_1file_then_timeout.txt'))
        self.assertEqual(len(pass_list), 1)
        # print(pass_list)
        self.assertEqual(pass_list[0], '/pub/example/ConsoleClient.png')

        pass_list = read_log(
            join(get_current_path(), 'samples', 'log_3files.txt'))
        self.assertEqual(len(pass_list), 3)
        self.assertEqual(pass_list[0], '/pub/example/ConsoleClient.png')
        self.assertEqual(pass_list[1], '/pub/example/FtpDownloader.png')
        self.assertEqual(pass_list[2], '/pub/example/mail-editor.png')
def get_db_connection():
	if 'conn' not in get_db_connection.__dict__:
		get_db_connection.conn = None

	if get_db_connection.conn is None:
		if in_test_mode():
			logger.info('get_db_connection(): connect to test database')
			get_db_connection.conn = get_test_db_connection()
		else:
			logger.info('get_db_connection(): connect to database: records.db')
			get_db_connection.conn = sqlite3.connect(os.path.join(get_current_path(), 'records.db'))

	return get_db_connection.conn
Beispiel #8
0
    def test_update_cash_entries(self):
        file1 = join(
            get_current_path(), 'samples',
            'BOC Bank Statement 2016-11-30 (CLASS A-HK SUB FUND I) -HKD.xls')
        file2 = join(
            get_current_path(), 'samples',
            'BOC Bank Statement 2016-12-13 (CLASS A-HK SUB FUND I) (HKD).xls')
        file3 = join(
            get_current_path(), 'samples',
            'BOC Bank Statement 2016-12-15 (CLASS A-HK SUB FUND I) (USD).xls')
        file4 = join(get_current_path(), 'samples',
                     'BOC Bank Statement 2013-12-31 (CLASS A-HK) -HKD.xls')
        cash_entries = []

        file_list = [file1, file2, file3, file4]
        cash_entries = []
        for filename in file_list:
            port_values = {}
            read_cash_bochk(filename, port_values)
            update_cash_entries(port_values, cash_entries)

        self.assertTrue(len(cash_entries), 3)
        matched = 0
        for cash_entry in cash_entries:
            if cash_entry['Account Name'] == 'CLT-CLI HK BR (CLASS A- HK) TRUST FUND - SUB FUND I' \
                and cash_entry['Currency'] == 'HKD':
                self.verify_cash1(cash_entry)
                matched = matched + 1
            elif cash_entry['Account Name'] == 'CLT-CLI HK BR (CLASS A- HK) TRUST FUND - SUB FUND I' \
                and cash_entry['Currency'] == 'USD':
                self.verify_cash2(cash_entry)
                matched = matched + 1
            elif cash_entry['Account Name'] == 'CLT-CLI HK BR (CLASS A- HK) TRUST FUND' \
                and cash_entry['Currency'] == 'HKD':
                self.verify_cash3(cash_entry)
                matched = matched + 1

        self.assertEqual(matched, 3)
Beispiel #9
0
    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)
Beispiel #10
0
def get_source_dir2():
    return join(get_current_path(), 'samples', 'source2')
Beispiel #11
0
def get_base_dir():
    return join(get_current_path(), 'samples', 'base_dir')
def get_test_winscp_script_dir():
    return join(get_current_path(), 'samples', 'winscp_script')
def get_test_temp_dir():
    return join(get_current_path(), 'samples', 'temp')
def get_test_winscp_log_dir():
    return join(get_current_path(), 'samples', 'winscp_log')