def testNormal(self): self.assertIsNone(utils.GetLocalComputedPropertyValue(self.inst, 'b')) self.inst.put() self.assertEqual('x', utils.GetLocalComputedPropertyValue(self.inst, 'b')) self.inst.a = 'cdg' self.assertEqual('x', utils.GetLocalComputedPropertyValue(self.inst, 'b')) self.inst.put() self.assertEqual('c', utils.GetLocalComputedPropertyValue(self.inst, 'b'))
def to_dict(self, include=None, exclude=None): # pylint: disable=g-bad-name if exclude is None: exclude = [] exclude += ['score'] result = super(Blockable, self).to_dict(include=include, exclude=exclude) # NOTE: This is not ideal but it prevents CalculateScore from being # called when serializing Blockables. This will return an inaccurate value # if a vote was cast after the Blockable was retrieved but this can be # avoided by wrapping the call to to_dict in a transaction. result['score'] = datastore_utils.GetLocalComputedPropertyValue( self, 'score') return result
def to_dict(self, include=None, exclude=None): # pylint: disable=g-bad-name if exclude is None: exclude = [] exclude += ['score'] result = super(Blockable, self).to_dict(include=include, exclude=exclude) # NOTE: This is not ideal but it prevents CalculateScore from being # called when serializing Blockables. This will return an inaccurate value # if a vote was cast after the Blockable was retrieved but this can be # avoided by wrapping the call to to_dict in a transaction. result['score'] = datastore_utils.GetLocalComputedPropertyValue( self, 'score') allowed, reason = self.IsVotingAllowed() result['is_voting_allowed'] = allowed result['voting_prohibited_reason'] = reason if not allowed: logging.info('Voting on this Blockable is not allowed (%s)', reason) return result
def testNotComputedProperty(self): with self.assertRaises(utils.PropertyError): utils.GetLocalComputedPropertyValue(self.inst, 'a')
def testUnknownProperty(self): with self.assertRaises(utils.PropertyError): utils.GetLocalComputedPropertyValue(self.inst, 'NotARealProperty')