def testAll(self): clearRepoData() saveRepoMasterFileToDB( join(getCurrentDir(), 'samples', 'RepoMaster_20210315_20210315193134.xml')) saveRepoTradeFileToDB( join(getCurrentDir(), 'samples', 'RepoTrade_20210315_20210315194216.xml')) saveRepoRerateFileToDB( join(getCurrentDir(), 'samples', 'Repo_ReRate_20210315_20210315211227.xml')) file1 = join(getCurrentDir(), 'samples', 'Repo_PosRecon_20210315_1.csv') file2 = join(getCurrentDir(), 'samples', 'Repo_PosRecon_20210315_2.csv') result = compose( list, partial(map, partial(updateAccruedInterest, getDateFromFilename(file1))), chain.from_iterable, partial(map, partial(enrichPosition, getRepoData())), loadRepoPosition)(file1, file2) self.verifyEnrichedPosition5(result) self.verifyEnrichedPosition6(result)
def setUp(self): #-- when fileConfig is being called, it will remove all the loggers created #-- when importing AppControllers.py when importing file repo_data #-- added disable_existing_loggers=False to prevent this logging.config.fileConfig( join(getCurrentDirectory(), "..", "logging_config.ini"), defaults={'date': datetime.now().date().strftime('%Y-%m-%d')}, disable_existing_loggers=False) initializeDatastore("uat") clearRepoData()
def testEnrichPosition(self): """ To complete this test, load information into database first, then enrich repo position with database info. """ clearRepoData() files = [ 'RepoMaster_20210309_20210309165806', 'RepoMaster_20210309_20210309190550', 'RepoMaster_20210309_20210309204006', 'RepoMaster_20210310_20210310225909' ] for file in files: saveRepoMasterFileToDB( join(getCurrentDir(), 'samples', file + '.xml')) files = [ 'RepoTrade_20210309_20210309174113', 'RepoTrade_20210309_20210309190913', 'RepoTrade_20210309_20210309204024', 'RepoTrade_20210310_20210310230717' ] for file in files: saveRepoTradeFileToDB( join(getCurrentDir(), 'samples', file + '.xml')) saveRepoRerateFileToDB( join(getCurrentDir(), 'samples', 'Repo_ReRate_20210309_20210309174543.xml')) file1 = join(getCurrentDir(), 'samples', 'Repo_PosRecon_20210309_1.csv') file2 = join(getCurrentDir(), 'samples', 'Repo_PosRecon_20210309_2.csv') L = compose( list, partial(map, partial(updateAccruedInterest, getDateFromFilename(file1))), chain.from_iterable, partial(map, partial(enrichPosition, getRepoData())), loadRepoPosition)(file1, file2) self.assertEqual(10, len(L)) self.verifyEnrichedPosition1(L) # closed position self.verifyEnrichedPosition2(L) # multi collateral, type OPEN self.verifyEnrichedPosition3(L) # fixed term self.verifyEnrichedPosition4(L) # not started yet
def testAll(self): """ Add 7 repo positions, 3 of type OPEN, 4 of type fixed term. Then close 1, cancel 1, both of type OPEN. """ clearRepoData() self.assertEqual( 7, saveRepoMasterFileToDB( join(getCurrentDir(), 'samples', 'RepoMaster_20210305_20210305154653.xml'))) self.assertEqual( 9, saveRepoTradeFileToDB( join(getCurrentDir(), 'samples', 'RepoTrade_20210305_20210305155621.xml'))) data = getRepo() self.assertEqual(6, len(data)) # 6 not canceled self.verifyHKDRepoPosition(data) self.verifyUSDRepoPosition(data) self.verifyClosedRepoPosition(data) # there is one repo canceled data = getRepo(status='canceled') self.assertEqual(1, len(data)) self.verifyCanceledRepoPosition(data) # Add 2 rerate actions to a repo position 316444 self.assertEqual( 2, saveRepoRerateFileToDB( join(getCurrentDir(), 'samples', 'Repo_ReRate_20210305_20210305174826.xml'))) # add the same file again, 2 more rerate actions added self.assertEqual( 2, saveRepoRerateFileToDB( join(getCurrentDir(), 'samples', 'Repo_ReRate_20210305_20210305174826.xml'))) self.assertEqual( 4, len( list( filter(lambda el: el['Action'] == 'rerate', getRepoTransactionHistory('316444')))))
def testClearRepoData(self): #-- test if NoDataClearingInProuctionModeError raise under production mode initializeDatastore("production") with self.assertRaises(NoDataClearingInProuctionModeError): clearRepoData() initializeDatastore("uat") clearRepoData() session = sessionmaker(bind=DBConn.get_db(self.unittest_dbmode))() self.assertEqual(0, session.query(func.count(RepoMaster.id)).scalar()) self.assertEqual( 0, session.query(func.count(RepoTransaction.id)).scalar()) self.assertEqual( 0, session.query(func.count(RepoTransactionHistory.id)).scalar())
def testAddRepoMaster(self): clearRepoData() inputFile = join(getCurrentDir(), 'samples', 'RepoMaster_20210218_20210218121101.xml') self.assertEqual(2, saveRepoMasterFileToDB(inputFile)) self.assertEqual(0, saveRepoMasterFileToDB(inputFile)) # duplicate