Exemplo n.º 1
0
 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'))
Exemplo n.º 2
0
  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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def testNotComputedProperty(self):
   with self.assertRaises(utils.PropertyError):
     utils.GetLocalComputedPropertyValue(self.inst, 'a')
Exemplo n.º 5
0
 def testUnknownProperty(self):
   with self.assertRaises(utils.PropertyError):
     utils.GetLocalComputedPropertyValue(self.inst, 'NotARealProperty')