當前位置: 首頁>>代碼示例>>Python>>正文


Python object.ObjectService類代碼示例

本文整理匯總了Python中river.services.object.ObjectService的典型用法代碼示例。如果您正苦於以下問題:Python ObjectService類的具體用法?Python ObjectService怎麽用?Python ObjectService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ObjectService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_next_approvements

    def test_get_next_approvements(self):
        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(9, approvements.count())

        self.objects[0].approve(self.user1)

        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(8, approvements.count())

        self.objects[0].approve(self.user2)


        # Two approvements exist on same level
        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(8, approvements.count())

        self.objects[0].approve(self.user3)

        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(6, approvements.count())

        self.objects[0].approve(self.user4, next_state=State.objects.get(label='s4'))
        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(2, approvements.count())

        self.objects[0].approve(self.user4, next_state=State.objects.get(label='s4.1'))
        approvements = ApprovementService.get_next_approvements(self.objects[0], self.field)
        self.assertEqual(0, approvements.count())
開發者ID:h3,項目名稱:django-river,代碼行數:31,代碼來源:test__approvement.py

示例2: test_register_for_an_object

    def test_register_for_an_object(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostCompletedHandler.register(test_handler, self.objects[0], 'my_field')

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((self.objects[0], 'my_field'), self.test_args)
開發者ID:pombredanne,項目名稱:django-river,代碼行數:30,代碼來源:test__completed_handler.py

示例3: test_register_for_all

    def test_register_for_all(self):
        self.initialize_normal_scenario()
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0])
        ObjectService.register_object(self.objects[1])

        PostCompletedHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual({"object": self.objects[0]}, self.test_kwargs)
開發者ID:javrasya,項目名稱:django-river,代碼行數:32,代碼來源:test__completed_handler.py

示例4: setUp

    def setUp(self):
        super(test_MemoryHandlerBackend, self).setUp()
        app_config.HANDLER_BACKEND_CLASS = 'river.handlers.backends.memory.MemoryHandlerBackend'
        self.handler_backend = load_handler_backend()
        self.handler_backend.handlers = {}

        ObjectService.register_object(self.objects[0], self.field)
開發者ID:davinirjr,項目名稱:django-river,代碼行數:7,代碼來源:test__memory_handler_backend.py

示例5: test_get_next_proceedings

    def test_get_next_proceedings(self):
        self.initialize_normal_scenario()

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(9, proceedings.count())

        self.objects[0].proceed(self.user1)

        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(8, proceedings.count())

        self.objects[0].proceed(self.user2)

        # Two proceedings exist on same level
        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(7, proceedings.count())

        self.objects[0].proceed(self.user3)

        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(6, proceedings.count())

        self.objects[0].proceed(self.user4, next_state=State.objects.get(label='s4'))
        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(2, proceedings.count())

        self.objects[0].proceed(self.user4, next_state=State.objects.get(label='s4.1'))
        proceedings = ProceedingService.get_next_proceedings(self.objects[0], self.field)
        self.assertEqual(0, proceedings.count())
開發者ID:DjangoBD,項目名稱:django-river,代碼行數:32,代碼來源:test__proceeding_service.py

示例6: test_register_for_a_transition

    def test_register_for_a_transition(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostTransitionHandler.register(test_handler, self.objects[0], 'my_field', source_state=State.objects.get(label='s2'), destination_state=State.objects.get(label='s3'))

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.approve_transition(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.approve_transition(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.approve_transition(self.objects[0], self.field, self.user3)

        self.assertEqual((self.objects[0], 'my_field'), self.test_args)
        self.assertDictEqual(
            {
                'approvement': Approvement.objects.filter(meta__transition__source_state=State.objects.get(label='s2'), meta__transition__destination_state=State.objects.get(label='s3'))[2],
                'source_state': State.objects.get(label='s2'),
                'destination_state': State.objects.get(label='s3')
            }, self.test_kwargs)
開發者ID:h3,項目名稱:django-river,代碼行數:35,代碼來源:test__transition_handler.py

示例7: test_register_for_all

    def test_register_for_all(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostCompletedHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.approve_transition(self.objects[0], self.field, self.user1)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        # Approved but no transition
        TransitionService.approve_transition(self.objects[0], self.field, self.user2)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.approve_transition(self.objects[0], self.field, self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0]
            }, self.test_kwargs)
開發者ID:h3,項目名稱:django-river,代碼行數:35,代碼來源:test__completed_handler.py

示例8: test_init

    def test_init(self):
        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        initial_state = StateService.get_initial_state(self.content_type, self.field)

        self.assertEqual(initial_state, getattr(self.objects[0], self.field))
        self.assertEqual(18, Approvement.objects.count())
開發者ID:h3,項目名稱:django-river,代碼行數:8,代碼來源:test__object_service.py

示例9: setUp

    def setUp(self):
        super(test_DatabaseHandlerBackend, self).setUp()
        self.initialize_normal_scenario()
        app_config.HANDLER_BACKEND_CLASS = 'river.handlers.backends.database.DatabaseHandlerBackend'
        self.handler_backend = load_handler_backend()
        self.handler_backend.handlers = {}

        ObjectService.register_object(self.objects[0])
開發者ID:javrasya,項目名稱:django-river,代碼行數:8,代碼來源:test__database_handler_backend.py

示例10: setUp

    def setUp(self):
        super(test_DatabaseHandlerBackend, self).setUp()

        RiverConfig.HANDLER_BACKEND_CLASS = 'river.handlers.backends.database.DatabaseHandlerBackend'
        self.handler_backend = load_handler_backend()
        self.handler_backend.handlers = {}

        ObjectService.register_object(self.objects[0], self.field)
開發者ID:sigma-geosistemas,項目名稱:django-river,代碼行數:8,代碼來源:test__database_handler_backend.py

示例11: test_get_field

    def test_get_field(self):
        field = ObjectService.get_field(TestModel)
        self.assertEqual('my_field', field.name)

        try:
            ObjectService.get_field(TestModelWithoutStateField)
            self.assertFalse(True, "Trying getting field from a model does not contains state field should have thrown the error with code '8'")
        except RiverException as re:
            self.assertEqual(ErrorCode.NO_STATE_FIELD, re.code)
開發者ID:javrasya,項目名稱:django-river,代碼行數:9,代碼來源:test__object_service.py

示例12: test_init

    def test_init(self):
        self.initialize_normal_scenario()

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        initial_state = StateService.get_initial_state(self.content_type, self.field)

        self.assertEqual(initial_state, getattr(self.objects[0], self.field))
        self.assertEqual(18, Proceeding.objects.count())
開發者ID:DjangoBD,項目名稱:django-river,代碼行數:10,代碼來源:test__object_service.py

示例13: _post_save

def _post_save(sender, instance, created, *args, **kwargs):  # signal, sender, instance):
    """
    Desc:  Generate TransitionApprovements according to TransitionApproverDefinition of the content type at the beginning.
    :param kwargs:
    :return:
    """

    if created:
        for f in instance._meta.fields:
            if isinstance(f, StateField):
                ObjectService.register_object(instance, f.name)
開發者ID:h3,項目名稱:django-river,代碼行數:11,代碼來源:state.py

示例14: test_register_for_all

    def test_register_for_all(self):
        self.test_args = None
        self.test_kwargs = None

        def test_handler(*args, **kwargs):
            self.test_args = args
            self.test_kwargs = kwargs

        ObjectService.register_object(self.objects[0], self.field)
        ObjectService.register_object(self.objects[1], self.field)

        PostTransitionHandler.register(test_handler)

        self.assertIsNone(self.test_args)
        self.assertIsNone(self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user1)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s1'), meta__transition__destination_state=State.objects.get(label='s2'))[0],
                'source_state': State.objects.get(label='s1'),
                'destination_state': State.objects.get(label='s2')
            }, self.test_kwargs)


        # Proceeded but no transition
        TransitionService.proceed(self.objects[0], self.field, self.user2)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s1'), meta__transition__destination_state=State.objects.get(label='s2'))[0],
                'source_state': State.objects.get(label='s1'),
                'destination_state': State.objects.get(label='s2')
            }, self.test_kwargs)

        TransitionService.proceed(self.objects[0], self.field, self.user3)

        self.assertEqual((), self.test_args)
        self.assertDictEqual(
            {
                'field': 'my_field',
                'object': self.objects[0],
                'proceeding': Proceeding.objects.filter(meta__transition__source_state=State.objects.get(label='s2'), meta__transition__destination_state=State.objects.get(label='s3'))[2],
                'source_state': State.objects.get(label='s2'),
                'destination_state': State.objects.get(label='s3')
            }, self.test_kwargs)
開發者ID:davinirjr,項目名稱:django-river,代碼行數:53,代碼來源:test__transition_handler.py

示例15: test_get_objects_waiting_for_approval_for_user

    def test_get_objects_waiting_for_approval_for_user(self):
        on_approval_objects = ObjectService.get_objects_waiting_for_approval(self.content_type, self.field, self.user1)
        self.assertEqual(2, on_approval_objects.count())
        self.assertEqual(self.objects[0], on_approval_objects[0])

        on_approval_objects = ObjectService.get_objects_waiting_for_approval(self.content_type, self.field, self.user2)
        self.assertEqual(0, on_approval_objects.count())

        on_approval_objects = ObjectService.get_objects_waiting_for_approval(self.content_type, self.field, self.user3)
        self.assertEqual(0, on_approval_objects.count())

        on_approval_objects = ObjectService.get_objects_waiting_for_approval(self.content_type, self.field, self.user4)
        self.assertEqual(0, on_approval_objects.count())
開發者ID:davinirjr,項目名稱:django-river,代碼行數:13,代碼來源:test__object_service.py


注:本文中的river.services.object.ObjectService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。