当前位置: 首页>>代码示例>>Python>>正文


Python Task.objects_for方法代码示例

本文整理汇总了Python中models.Task.objects_for方法的典型用法代码示例。如果您正苦于以下问题:Python Task.objects_for方法的具体用法?Python Task.objects_for怎么用?Python Task.objects_for使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Task的用法示例。


在下文中一共展示了Task.objects_for方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_object_deletion

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import objects_for [as 别名]
    def test_object_deletion(self):
        """
        Test that tasks are created and deleted correctly by being given an object and a list
        """
        
        # test objects
        normal_object    = self.test_object
        deletable_object = test_object = Site(name='foo', domain='foo.com')
        deletable_object.save()
        
        # check that there are none at the start
        self.assertEqual( Task.objects.count(), 0 )

        # create a couple of tasks
        for obj in [ normal_object, deletable_object ]:
            Task.update_for_object( obj, ['foo'] )

        # check that a task exists
        self.assertEqual( Task.objects.count(), 2 )
        self.assertEqual( Task.objects_for(deletable_object).count(), 1 )

        test_object.delete()
        
        # check that a task exists
        self.assertEqual( Task.objects.count(), 1 )
        self.assertEqual( Task.objects_for(deletable_object).count(), 0 )
开发者ID:Code4SA,项目名称:pombola,代码行数:28,代码来源:tests.py

示例2: test_list_creation_and_deletion

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import objects_for [as 别名]
    def test_list_creation_and_deletion(self):
        """
        Test that tasks are created and deleted correctly by being given an object and a list
        """

        initial_list  = [ self.high_priority_category.slug, self.medium_priority_category.slug ]
        modified_list = [ self.high_priority_category.slug, self.low_priority_category.slug ]

        # check that there are none at the start
        self.assertEqual( Task.objects.count(), 0 )

        # create a couple of tasks
        Task.update_for_object(
            self.test_object,
            initial_list
        )
        self.assertItemsEqual(
            [ i.category.slug for i in Task.objects_for( self.test_object) ],
            initial_list,
        )
        
        # modify one of the tasks
        for task in Task.objects_for( self.test_object ).filter(category__slug='task-code-1'):
            task.note = "test notes"
            task.save()
    
        # run again - this time with a new task
        Task.update_for_object(
            self.test_object,
            modified_list
        )
        self.assertItemsEqual(
            [ i.category.slug for i in Task.objects_for( self.test_object) ],
            modified_list,
        )

        # check previously modified task unchanged
        for task in Task.objects_for( self.test_object ).filter(category__slug='task-code-1'):
            self.assertEqual( task.note, "test notes" )
    
        # run again - with empty list
        Task.update_for_object(
            self.test_object,
            []
        )
        self.assertItemsEqual(
            [ i.category.slug for i in Task.objects_for( self.test_object) ],
            [],
        )
        
        # check that all tasks are now deleted
        self.assertEqual( Task.objects.count(), 0 )
开发者ID:Code4SA,项目名称:pombola,代码行数:54,代码来源:tests.py


注:本文中的models.Task.objects_for方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。