本文整理匯總了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())
示例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)
示例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)
示例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)
示例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())
示例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)
示例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)
示例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())
示例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])
示例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)
示例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)
示例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())
示例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)
示例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)
示例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())