本文整理汇总了Python中gae2django.models.RegressionTestModel类的典型用法代码示例。如果您正苦于以下问题:Python RegressionTestModel类的具体用法?Python RegressionTestModel怎么用?Python RegressionTestModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegressionTestModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_unicode
def test_filter_unicode(self): # issue22
# This test passes with Python >= 2.6 either way.
obj = TestModel()
obj.xstring = 'foo'
obj.save()
query = db.GqlQuery((u'SELECT * FROM RegressionTestModel'
u' WHERE xstring = :foo'), foo=u'foo')
self.assertEqual(query.count(), 1)
示例2: test_query_listproperty
def test_query_listproperty(self):
obj = TestModel()
obj.xlist = ['foo', 'bar', 'baz']
obj.save()
query = db.GqlQuery(('SELECT * FROM RegressionTestModel'
' WHERE xlist = :1'), 'foo')
self.assertEqual([obj], list(query))
self.assertEqual(query.count(), 1)
tobj = query.get()
self.assertEqual(tobj.xlist, ['foo', 'bar', 'baz'])
query = db.GqlQuery(('SELECT * FROM RegressionTestModel'
' WHERE xlist = :1'), 'nomatch')
self.assertEqual([], list(query))
self.assertEqual(query.count(), 0)
tobj.xlist = ['bar', 'baz']
tobj.save()
query = db.GqlQuery(('SELECT * FROM RegressionTestModel'
' WHERE xlist = :1'), 'foo')
self.assertEqual([], list(query))
self.assertEqual(query.count(), 0)
示例3: KeyTest
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))
示例4: test_key_item_saved
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()
示例5: test_get_or_insert
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()
示例6: QueryTest
class QueryTest(unittest.TestCase):
def setUp(self):
TestModel.all().delete()
self.item1 = TestModel(key_name='foo1')
self.item1.put()
def tearDown(self):
self.item1.delete()
self.item1 = None
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()))
def test_key_only(self):
q = TestModel.all(keys_only=True)
res = q.fetch(1000)
self.assertEqual(len(res), 1)
self.assertEqual(res[0], self.item1.id)
示例7: setUp
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()
示例8: test_auto_current_user_add
def test_auto_current_user_add(self):
c = Client()
c.login(username='test', password='testpw')
response = c.get('/')
user = response.context['user']
self.assert_(user is not None)
obj = TestModel()
obj.save()
self.assertEqual(obj.xuser, user)
示例9: test_gql
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()
item2.delete()
示例10: test_protected_attr
def test_protected_attr(self):
m = TestModel()
m2 = TestModel2()
m2.put()
m.ref = m2
m.put()
self.assert_(hasattr(m, '_ref'))
self.assert_(isinstance(m._ref, db.Key))
self.assertEqual(m._ref, m2.key())
示例11: test_get_value_for_datastore
def test_get_value_for_datastore(self):
m = TestModel()
m2 = TestModel2()
m2.put()
m.ref = m2
m.put()
self.assert_(isinstance(TestModel.ref.get_value_for_datastore(m),
db.Key))
self.assertEqual(TestModel.ref.get_value_for_datastore(m), m2.key())
示例12: test_filter
def test_filter(self):
q = TestModel.all()
self.assert_(isinstance(q, db.Query))
q = q.filter('xstring =', 'foo1')
self.assert_(isinstance(q, db.Query))
self.assertEqual(len(list(q)), 1)
q = TestModel.all().filter('xstring =', 'foo')
self.assert_(isinstance(q, db.Query))
self.assertEqual(len(list(q)), 0)
示例13: test_user_property_patched
def test_user_property_patched(self):
c = Client()
c.login(username='test', password='testpw')
response = c.get('/')
user = response.context['user']
obj = TestModel()
obj.save()
self.assert_(callable(obj.xuser.email))
self.assert_(hasattr(obj.xuser, 'nickname'))
self.assert_(callable(obj.xuser.nickname))
示例14: test_properties
def test_properties(self):
props = TestModel.properties()
self.assert_('xstring' in props)
self.assert_(isinstance(props['xstring'], db.StringProperty))
self.assert_('gae_parent_id' not in props)
# From a App Engine perspective this is wrong. Choices should
# be ('foo', 'bar'). For Django this is right.
self.assertEqual(props['choices'].choices,
[('foo', 'foo'), ('bar', 'bar')])
示例15: test_ancestor
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)