本文整理汇总了Python中gae2django.models.RegressionTestModel.key方法的典型用法代码示例。如果您正苦于以下问题:Python RegressionTestModel.key方法的具体用法?Python RegressionTestModel.key怎么用?Python RegressionTestModel.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gae2django.models.RegressionTestModel
的用法示例。
在下文中一共展示了RegressionTestModel.key方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_key_item_saved
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_key_item_saved(self):
# make sure that an instance of this model is saved at least
# once before retrieving the key
item = TestModel()
self.assertRaises(db.NotSavedError, item.key)
item.put()
item.key()
示例2: test_parent
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_parent(self):
t1 = TestModel(xstring="child", parent=self._test)
t1.put()
self.assertEqual(t1.key().parent(), self._key)
t1.delete()
t2 = TestModel(xstring="child", parent=self._test_name)
t2.put()
self.assertEqual(t2.key().parent(), self._key_name)
t2.delete()
示例3: test_get_by_id
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_get_by_id(self):
item1 = TestModel(xstring='test1')
item1.put()
self.assertEqual(TestModel.get_by_id(item1.key().id()), item1)
self.assertEqual(TestModel.get_by_id(-1), None)
self.assertEqual(TestModel.get_by_id([item1.key().id(), -1]),
[item1, None])
item2 = TestModel(xstring='test2')
item2.put()
self.assertEqual(TestModel.get_by_id([item1.key().id(),
item2.key().id()]),
[item1, item2])
item1.delete()
item2.delete()
示例4: test_listproperty_save_restore
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_listproperty_save_restore(self):
obj = TestModel()
obj.xlist = ["foo", "bar", "baz"]
obj.save()
tobj = TestModel.get_by_id(obj.key().id())
self.assertEqual(tobj, obj)
self.assertEqual(tobj.xlist, ["foo", "bar", "baz"])
示例5: test_blobproperty_save_restore
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_blobproperty_save_restore(self):
obj = TestModel()
obj.blob = db.Blob("test")
obj.save()
tobj = TestModel.get_by_id(obj.key().id())
self.assertEqual(tobj, obj)
self.assertEqual(obj.blob, "test")
self.assertEqual(tobj.blob, "test")
self.assert_(isinstance(tobj.blob, db.Blob))
示例6: test_refkey
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
def test_refkey(self):
# Regression for issue23.
i1 = TestModel2()
i1.put()
i2 = TestModel()
i2.ref = i1
i2.put()
q = TestModel.all()
q.filter('ref =', i1.key())
res = list(q.fetch(1000))
self.assertEqual(len(res), 1)
self.assertEqual(str(res[0].key()), str(i2.key()))
示例7: DatastoreModelTest
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
class DatastoreModelTest(unittest.TestCase):
def setUp(self):
self.item1 = TestModel(key_name='foo1')
self.item1.put()
def tearDown(self):
self.item1.delete()
self.item1 = None
# Class methods
def test_get(self):
item1 = TestModel(key_name='test1')
item1.put()
self.assertEqual(TestModel.get('test1'), item1)
self.assertEqual(TestModel.get('foo'), None)
self.assertEqual(TestModel.get(['test1', 'test2']), [item1, None])
item2 = TestModel(key_name='test2')
item2.put()
self.assertEqual(TestModel.get(['test1', 'test2']), [item1, item2])
item1.delete()
item2.delete()
def test_get_by_id(self):
item1 = TestModel(xstring='test1')
item1.put()
self.assertEqual(TestModel.get_by_id(item1.key().id()), item1)
self.assertEqual(TestModel.get_by_id(-1), None)
self.assertEqual(TestModel.get_by_id([item1.key().id(), -1]),
[item1, None])
item2 = TestModel(xstring='test2')
item2.put()
self.assertEqual(TestModel.get_by_id([item1.key().id(),
item2.key().id()]),
[item1, item2])
item1.delete()
item2.delete()
def test_get_by_key_name(self):
self.assertEqual(TestModel.get_by_key_name('foo'), None)
self.assertEqual(TestModel.get_by_key_name(['foo', 'bar']),
[None, None])
item1 = TestModel(key_name='test1')
item1.put()
self.assertEqual(TestModel.get_by_key_name('test1'), item1)
self.assertEqual(TestModel.get_by_key_name(['test1', 'test2']),
[item1, None])
item2 = TestModel(key_name='test2')
item2.put()
self.assertEqual(TestModel.get_by_key_name(['test1', 'test2']),
[item1, item2])
self.assertEqual(TestModel.get_by_key_name(['test1']),
[item1])
item1.delete()
item2.delete()
def test_get_or_insert(self):
item1 = TestModel.get_or_insert('test1', xstring='foo')
self.assert_(isinstance(item1, TestModel))
test = TestModel.get_or_insert('test1')
self.assertEqual(item1, test)
self.assertEqual(item1.xstring, 'foo')
item1.delete()
def test_all(self):
self.assertEqual(len(TestModel.all()), 1)
item1 = TestModel.get_or_insert('test1')
self.assertEqual(len(TestModel.all()), 2)
self.assert_(item1 in TestModel.all())
item1.delete()
def test_ancestor(self):
grandpa = TestModel.get_or_insert('grandpa')
dad = TestModel.get_or_insert('dad', parent=grandpa)
TestModel.get_or_insert('junior', parent=dad)
TestModel.get_or_insert('unrelated')
q = TestModel.all()
q.ancestor(grandpa)
self.assertEqual(len(q), 2)
q2 = TestModel.all()
q2.ancestor(dad)
self.assertEqual(len(q2), 1)
# ancestor() accepts keys too
q = TestModel.all()
q.ancestor(grandpa.key())
self.assertEqual(len(q), 2)
q2 = TestModel.all()
q2.ancestor(dad.key())
self.assertEqual(len(q2), 1)
def test_gql(self):
item1 = TestModel.get_or_insert('test1', xstring='foo')
item2 = TestModel.get_or_insert('test2', xstring='foo')
results = TestModel.gql('WHERE xstring = \'foo\'')
self.assertEqual(results.count(), 2)
self.assert_(item1 in results)
self.assert_(item2 in results)
item1.delete()
#.........这里部分代码省略.........
示例8: KeyTest
# 需要导入模块: from gae2django.models import RegressionTestModel [as 别名]
# 或者: from gae2django.models.RegressionTestModel import key [as 别名]
class KeyTest(unittest.TestCase):
def setUp(self):
self._test = TestModel(xstring="foo")
self._test.put()
self._key = self._test.key()
self._test_name = TestModel(xstring="foo", key_name="fookey")
self._test_name.put()
self._key_name = self._test_name.key()
def tearDown(self):
self._test.delete()
self._test_name.delete()
self._test = self._key = None
self._test_name = self._key_name = None
# constructor
def test_constructor(self):
self.assertRaises(TypeError, db.Key, ('foo',), {'should': 'fail'})
self.assertRaises(db.BadArgumentError, db.Key, (123,))
self.assertRaises(db.BadArgumentError, db.Key, (range(2),))
# class methods
def test_from_path(self):
self.assertRaises(db.BadArgumentError, db.Key.from_path,
('foo', 1), should='fail')
self.assertRaises(db.BadArgumentError, db.Key.from_path,
('foo',))
self.assertEqual(db.Key.from_path('RegressionTestModel',
self._test.id), self._key)
k = db.Key.from_path('RegressionTestModel', 'fookey')
self.assertEqual(db.Key.from_path('RegressionTestModel', 'fookey'),
self._key_name)
# instance methods
def test_app(self):
self.assertEqual(self._key.app(), 'gae2django')
def test_kind(self):
self.assertEqual(self._key.kind(), 'RegressionTestModel')
def test_id(self):
self.assertEqual(self._key.id(), self._test.id)
self.assertEqual(self._key_name.id(), None)
def test_name(self):
self.assertEqual(self._key_name.name(), 'fookey')
self.assertEqual(self._key.name(), None)
def test_id_or_name(self):
self.assertEqual(self._key.id_or_name(), self._test.id)
self.assertEqual(self._key_name.id_or_name(), 'fookey')
def test_has_id_or_name(self):
self.assertEqual(self._key.has_id_or_name(), True)
self.assertEqual(self._key_name.has_id_or_name(), True)
def test_parent(self):
t1 = TestModel(xstring="child", parent=self._test)
t1.put()
self.assertEqual(t1.key().parent(), self._key)
t1.delete()
t2 = TestModel(xstring="child", parent=self._test_name)
t2.put()
self.assertEqual(t2.key().parent(), self._key_name)
t2.delete()
# internals
def test_compare(self):
# see issue8
k1 = db.Key('foo1')
k2 = db.Key('foo1')
self.assert_(k1 == k2, '%r doesn\'t compare equal to %r' % (k1, k2))
self.assert_(k2 in set([k1]), 'set comparsion failed')
self.assert_(not k1 is k2, 'is comparsion failed')
def test__str__(self):
k1 = db.Key('foo1')
self.assertEqual('foo1', str(k1))