class TestStockRepository(unittest.TestCase): def setUp(self): print '*Entering setUp method*' '''This will create a StockItem instance that can be used throughout the StockItemTest class.''' self.StockRepo1 = StockRepository() def test1_enterStock(self): print '*Entering test_enterStock method*' '''Please enter the new stock item's ID as 1, and the warehouse number as 1. For the test to run correctly these values must be inputed by the user.''' newEntry = self.StockRepo1.enterStock() self.assertEqual(newEntry, {1: 1}) def test2_moveStock(self): print '*Entering test_moveStock method*' '''Previously entered stockItem ID;1, will be changed from warehouse 1 to warehouse 2.''' self.StockRepo1.moveStock([1], 2) self.assertEqual(self.StockRepo1.stockCollection, {1: 2}) def test3_addAllStockInWarehouse(self): print '*Entering test_addAllStockInWarehouse method*' '''This code will add all the stock in warehouse 2. The answer should be 1.''' self.assertEqual(self.StockRepo1.addAllStockInWarehouse(2), 1) def test4_deleteStock(self): print '*Entering test_deleteStock method*' '''Previously entered stockItem ID;1, will be deleted.''' self.StockRepo1.deleteStock([1]) self.assertEqual(self.StockRepo1.stockCollection, {}) def tearDown(self): print '*Entering tearDown method*' pass
def __init__(self): self.IncomingFile = None self.IOController = IOController() self.StockRepository = StockRepository() self.Stock = Stock()
def setUp(self): print '*Entering setUp method*' '''This will create a StockItem instance that can be used throughout the StockItemTest class.''' self.StockRepo1 = StockRepository()
class StockModel(object): def __init__(self): self.IncomingFile = None self.IOController = IOController() self.StockRepository = StockRepository() self.Stock = Stock() def CountSimpleMovingAverage(self, low, high): countResult = None countResult = self.StockRepository.CountSimpleMovingAverage(low, high) return countResult def GetDocumentsByIndustry(self, industry): readResult = None readResult = self.StockRepository.GetDocumentsByIndustry(industry) return readResult def GetSharesOutstandingBySector(self, sector): _readResult = None _readResult = self.StockRepository.GetSharesOustandingPerSector(sector) return _readResult def GetByTicker(self, ticker): _readResult = None _readResult = self.StockRepository.GetByTicker(ticker) return _readResult def GetTopFivePerformingCompanies(self): _readResult = None _readResult = self.StockRepository.GetTopFivePerformingCompanies() return _readResult def Create(self, isTest): createResult = None stock = self.Stock.Create(isTest) try: self.IOController.Write(stock) except Exception as exception: raise exception() jsonResult = self.IOController.Read(self.IOController.Incoming) stocks = [] #map jsonResult to a stock object stockObject = self.Stock.MapToObject(jsonResult) #append stockObject to Stocks stocks.append(stockObject) #Map to Database entity and Save for stock in stocks: stockDict = self.Stock.MapToDatabaseEntity(stockObject) createResult = self.StockRepository.Add(stockDict) return createResult def UpdateVolume(self, ticker, newValue): results = None if (newValue < 0): raise Error("Value must be greater than 0") if (not ticker): raise Error("No ticker provided") print("Updating Volume value...") try: results = self.StockRepository.GetByTicker(ticker) except Exception as exception: raise exception( "Failed to retrieve documents by Ticker: {ticker}".format( ticker=ticker)) for result in results: stock = self.Stock.MapToObject(result) stock.Volume = newValue stockDict = self.Stock.MapToDatabaseEntity(stock) updateResult = self.StockRepository.UpdateVolume(ticker, stockDict) return updateResult def DeleteStock(self, ticker): _deleteResult = None if (not ticker): raise Error("Ticker not provided") _deleteResult = self.StockRepository.DeleteByTicker(ticker) return _deleteResult def CleanupIncomingDirectory(self): self.IOController.RemoveAll()