def test_removestrategy(self): ''' Demonstrates Strategies relationship with Images, Description and Links and cascacde delete for each Not sure if the relationships work for creation (through a Strategy object) But then there is no call for it in the structjour strategy browser; each of the fields are created from a different button ''' scrud = StrategyCrud() stratName = 'Schnork' img = '/c/an/image/for/schnork.gif' desc = "Schnork is a strategy of percentages." link = 'https://A/thorough/description/of/the percentages/of/schnork.html' scrud.addStrategy(stratName) scrud.setImage1(stratName, img) scrud.setDescription(stratName, desc) scrud.setLink(stratName, link) strat = Strategy.getStrategy(stratName) self.assertIn(img, [x.name for x in strat.images]) self.assertIn(desc, [x.description for x in strat.description]) self.assertIn(link, [x.link for x in strat.links]) scrud.removeStrategy(stratName) strat = Strategy.getStrategy(stratName) # Tests have to get all links, descriptions, and images from their own table to test they were deleted links = Links.getAllLinks() descriptions = Description.getAllDescriptions() images = Images.getAllImages() self.assertIsNone(strat) self.assertNotIn(img, [x.name for x in images]) self.assertNotIn(img, [x.description for x in descriptions]) self.assertNotIn(img, [x.link for x in links])
def test_setdescription(self): name = 'Mistake' desc1 = "The description for the mistake category is don't do that anymore. But still ..." scrud = StrategyCrud() scrud.setDescription(name, desc1) strat = Strategy.getStrategy(name) self.assertIsNotNone(strat) self.assertEqual(desc1, strat.description[0].description) desc2 = "The description for the mistake category is don't do that anymore. But still, everyone has some." scrud.setDescription(name, desc2) strat = Strategy.getStrategy(name) self.assertEqual(desc2, strat.description[0].description) descriptions = Description.getAllDescriptions() self.assertNotIn(desc1, [x.description for x in descriptions])
def setPreferred(self, name, pref): Strategy.setPreferred(name, pref)
def getPreferred(self, pref=1): strats = Strategy.getPreferred(pref) # Manipulate results to match DBAPI method strats = [[x.id, x.name, x.preferred] for x in strats] return strats
def getStrategies(self): strats = Strategy.getStrategies() # manipulate this to match the return from the old DBAPI method strats = [[x.id, x.name, x.preferred] for x in strats] return strats
def removeStrategy(self, name): Strategy.removeStrategy(name)
def getStrategy(self, name=None, id=None): s = Strategy.getStrategy(name, id) if not s: return None return s
def addStrategy(self, name, preferred=True): Strategy.addStrategy(name, preferred)
def getId(self, name): if not name: return [] q = Strategy.getId(name) return q