本文整理匯總了Python中couchexport.models.SavedBasicExport.by_index方法的典型用法代碼示例。如果您正苦於以下問題:Python SavedBasicExport.by_index方法的具體用法?Python SavedBasicExport.by_index怎麽用?Python SavedBasicExport.by_index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類couchexport.models.SavedBasicExport
的用法示例。
在下文中一共展示了SavedBasicExport.by_index方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_get_by_index
# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import by_index [as 別名]
def test_get_by_index(self):
index = ['some', 'index']
saved_export = SavedBasicExport(configuration=_mk_config(index=index))
saved_export.save()
back = SavedBasicExport.by_index(index)
self.assertEqual(1, len(back))
self.assertEqual(saved_export._id, back[0]._id)
示例2: test_get_saved_and_delete_copies_multiple
# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import by_index [as 別名]
def test_get_saved_and_delete_copies_multiple(self):
index = ['multiple']
# make three exports with the last one being the most recently updated
timestamp = datetime.datetime.utcnow()
for i in range(3):
saved_export = SavedBasicExport(configuration=_mk_config(index=index),
last_updated=timestamp + datetime.timedelta(days=i))
saved_export.save()
self.assertEqual(3, len(SavedBasicExport.by_index(index)))
chosen_one = get_saved_export_and_delete_copies(index)
# this relies on the variable being set last in the loop which is a bit unintuitive
self.assertEqual(saved_export._id, chosen_one._id)
saved_after_deletion = SavedBasicExport.by_index(index)
self.assertEqual(1, len(saved_after_deletion))
self.assertEqual(chosen_one._id, saved_after_deletion[0]._id)
示例3: get_saved_export_and_delete_copies
# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import by_index [as 別名]
def get_saved_export_and_delete_copies(index):
matching = SavedBasicExport.by_index(index)
if not matching:
return None
if len(matching) == 1:
return matching[0]
else:
# delete all matches besides the last updated match
matching = sorted(matching, key=lambda x: x.last_updated)
for match in matching[:-1]:
match.delete()
return matching[-1]