本文整理汇总了Python中casexml.apps.case.models.CommCareCase.has_index方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase.has_index方法的具体用法?Python CommCareCase.has_index怎么用?Python CommCareCase.has_index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.models.CommCareCase
的用法示例。
在下文中一共展示了CommCareCase.has_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IndexSimpleTest
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import has_index [as 别名]
class IndexSimpleTest(SimpleTestCase):
def setUp(self):
self.i1 = CommCareCaseIndex(identifier="i1", referenced_type="t1", referenced_id="id1")
self.i2 = CommCareCaseIndex(identifier="i2", referenced_type="t2", referenced_id="id2")
self.case = CommCareCase(indices=[self.i1, self.i2])
def testHasIndex(self):
self.assertEqual(True, self.case.has_index("i1"))
self.assertEqual(True, self.case.has_index("i2"))
self.assertEqual(False, self.case.has_index("i3"))
def testGetIndex(self):
self.assertEqual(self.i1, self.case.get_index("i1"))
self.assertEqual(self.i2, self.case.get_index("i2"))
self.assertEqual(None, self.case.get_index("i3"))
self.assertEqual(None, self.case.get_index("id1"))
def testGetIndexByRef(self):
self.assertEqual(self.i1, self.case.get_index_by_ref_id("id1"))
self.assertEqual(self.i2, self.case.get_index_by_ref_id("id2"))
self.assertEqual(None, self.case.get_index_by_ref_id("id3"))
self.assertEqual(None, self.case.get_index_by_ref_id("i1"))
def testRemoveIndexByRef(self):
self.assertEqual(2, len(self.case.indices))
self.case.remove_index_by_ref_id("id1")
self.assertEqual(1, len(self.case.indices))
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, "id3")
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, "i2")
示例2: IndexSimpleTest
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import has_index [as 别名]
class IndexSimpleTest(SimpleTestCase):
def setUp(self):
self.i1 = CommCareCaseIndex(
identifier='i1',
referenced_type='t1',
referenced_id='id1'
)
self.i2 = CommCareCaseIndex(
identifier='i2',
referenced_type='t2',
referenced_id='id2'
)
self.case = CommCareCase(indices=[self.i1, self.i2])
def testHasIndex(self):
self.assertEqual(True, self.case.has_index('i1'))
self.assertEqual(True, self.case.has_index('i2'))
self.assertEqual(False, self.case.has_index('i3'))
def testGetIndex(self):
self.assertEqual(self.i1, self.case.get_index('i1'))
self.assertEqual(self.i2, self.case.get_index('i2'))
self.assertEqual(None, self.case.get_index('i3'))
self.assertEqual(None, self.case.get_index('id1'))
def testGetIndexByRef(self):
self.assertEqual(self.i1, self.case.get_index_by_ref_id('id1'))
self.assertEqual(self.i2, self.case.get_index_by_ref_id('id2'))
self.assertEqual(None, self.case.get_index_by_ref_id('id3'))
self.assertEqual(None, self.case.get_index_by_ref_id('i1'))
def testRemoveIndexByRef(self):
self.assertEqual(2, len(self.case.indices))
self.case.remove_index_by_ref_id('id1')
self.assertEqual(1, len(self.case.indices))
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, 'id3')
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, 'i2')