谷歌应用引擎,Python 2.7 使用 ndb
当我运行以下测试时-它在最后一个断言上引发错误->
self.assertEqual(models.Log.query().count(), 1)
AssertionError: 0 != 1
Log 是一个基本的 ndb.Model 类。运行这些测试感谢帮助。
import unittest2
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_util
import rm.base.models as models
class TestModels(unittest2.TestCase):
def setUp(self):
# First, create an instance of the Testbed class.
self.testbed = testbed.Testbed()
# Then activate the testbed, which prepares the service stubs for use.
self.testbed.activate()
# Create a consistency policy that will simulate the High Replication consistency model.
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
# Initialize the datastore stub with this policy.
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
def tearDown(self):
self.testbed.deactivate()
def testModelsLog(self):
l = models.Log(comment='hello kitty')
l.put()
self.assertEqual(l.comment, 'hello kitty')
self.assertTrue(l.user is None)
self.assertEqual(models.Log.query().count(), 1)