예제 #1
0
    def test_post_delete_handler(self):
        sender = 'sender_token'
        instance = 'instance_token'

        resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
        resource.post_delete_handler(sender=sender, instance=instance)
        resource.delete_instance.assert_called_once_with(instance)
예제 #2
0
 def test_dispatch_handlers(self):
     resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
     resource._dispatch_handlers()
     django.post_save.connect.assert_called_once_with(
         receiver=resource.post_save_handler, sender=resource.resource_cls)
     django.post_delete.connect.assert_called_once_with(
         receiver=resource.post_delete_handler,
         sender=resource.resource_cls)
예제 #3
0
    def test_post_save_handler__created(self):
        sender = 'sender_token'
        instance = 'instance_token'
        created = True

        resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
        resource.post_save_handler(sender=sender,
                                   instance=instance,
                                   created=created)
        resource.register_instance.assert_called_once_with(instance)
예제 #4
0
    def test_post_save_handler__tomb_field_update(self):
        sender = 'sender_token'
        instance = MagicMock()
        instance.deleted = True
        created = False

        resource = DjangoModelResource(auto_register=False,
                                       tomb_field='deleted',
                                       **self.init_kwargs)
        resource.post_save_handler(sender=sender,
                                   instance=instance,
                                   created=created)
        resource.delete_instance.assert_called_once_with(instance)
예제 #5
0
    def test_clean_list_instances(self):
        resource = DjangoModelResource(auto_register=False, **self.init_kwargs)

        get_return = 'get_token'

        class AnyResource(object):
            objects = MagicMock()

        AnyResource.objects.get = MagicMock(return_value=get_return)

        resource.resource_cls = AnyResource
        instances = [AnyResource(), 2, AnyResource(), 4]
        self.assertEqual(
            resource.clean_list_instances(instances),
            [instances[0], 'get_token', instances[2], 'get_token'])
        AnyResource.objects.get.assert_has_calls(
            [call(**{resource.id_field: 2}),
             call(**{resource.id_field: 4})])
예제 #6
0
 def test_init__do_not_auto_register(self):
     resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
     resource._dispatch_handlers.assert_not_called()
예제 #7
0
 def test_init(self):
     resource = DjangoModelResource(**self.init_kwargs)
     resource._dispatch_handlers.assert_called_once()
예제 #8
0
 def test_clean_int_instances(self):
     instances = 1
     resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
     self.assertIsNotNone(resource.clean_str_instances(instances))
     resource.resource_cls.objects.get.assert_called_once_with(
         **{self.id_field: instances})
예제 #9
0
 def test_clean_instances__instances_is_none(self):
     resource = DjangoModelResource(auto_register=False, **self.init_kwargs)
     resource.resource_cls = str
     self.assertIsNone(resource.clean_instances(None))
예제 #10
0
mini_app_resource = DjangoModelResource(
    rtype='mini_app',
    name=_(u"轻应用"),
    scope_type='system',
    scope_id='bk_sops',
    scope_name=_(u"标准运维"),
    actions=[
        Action(id='view', name=_(u"查看"), is_instance_related=True),
        Action(id='edit', name=_(u"编辑"), is_instance_related=True),
        Action(id='delete', name=_(u"删除"), is_instance_related=True),
        Action(id='create_task', name=_(u"新建任务"), is_instance_related=True)
    ],
    operations=[{
        'operate_id': 'view',
        'actions_id': ['view'],
    }, {
        'operate_id': 'edit',
        'actions_id': ['view', 'edit']
    }, {
        'operate_id': 'delete',
        'actions_id': ['view', 'delete']
    }, {
        'operate_id': 'create_task',
        'actions_id': ['view', 'create_task']
    }],
    parent=project_resource,
    resource_cls=AppMaker,
    id_field='id',
    tomb_field='is_deleted',
    backend=get_backend_from_config(),
    inspect=FixedCreatorTypeFieldInspect(creator_type='user',
                                         creator_id_f='creator',
                                         resource_id_f='id',
                                         resource_name_f='name',
                                         parent_f='project',
                                         scope_id_f=None))
예제 #11
0
common_template_resource = DjangoModelResource(
    rtype='common_flow',
    name=_(u"公共流程"),
    scope_type='system',
    scope_id='bk_sops',
    scope_name=_(u"标准运维"),
    actions=[
        Action(id='create', name=_(u"新建"), is_instance_related=False),
        Action(id='view', name=_(u"查看"), is_instance_related=True),
        Action(id='edit', name=_(u"编辑"), is_instance_related=True),
        Action(id='delete', name=_(u"删除"), is_instance_related=True),
        Action(id='create_task', name=_(u"新建任务"), is_instance_related=True)
    ],
    operations=[{
        'operate_id': 'create',
        'actions_id': ['create']
    }, {
        'operate_id': 'view',
        'actions_id': ['view']
    }, {
        'operate_id': 'edit',
        'actions_id': ['view', 'edit']
    }, {
        'operate_id': 'delete',
        'actions_id': ['view', 'delete']
    }, {
        'operate_id': 'create_task',
        'actions_id': ['view', 'create_task']
    }, {
        'operate_id': 'clone',
        'actions_id': ['view']
    }, {
        'operate_id': 'export',
        'actions_id': ['view']
    }, {
        'operate_id': 'create_scheme',
        'actions_id': ['view', 'edit']
    }, {
        'operate_id': 'delete_scheme',
        'actions_id': ['view', 'edit']
    }],
    resource_cls=CommonTemplate,
    id_field='id',
    tomb_field='is_deleted',
    backend=get_backend_from_config(),
    inspect=FixedCreatorTypeFieldInspect(creator_type='user',
                                         creator_id_f='creator_name',
                                         resource_id_f='id',
                                         resource_name_f='name',
                                         parent_f='project',
                                         scope_id_f=None))
예제 #12
0
taskflow_resource = DjangoModelResource(rtype='task',
                                        name=_(u"任务实例"),
                                        scope_type='system',
                                        scope_id='bk_sops',
                                        scope_name=_(u"标准运维"),
                                        actions=[
                                            Action(id='view',
                                                   name=_(u"查看"),
                                                   is_instance_related=True),
                                            Action(id='edit',
                                                   name=_(u"编辑"),
                                                   is_instance_related=True),
                                            Action(id='operate',
                                                   name=_(u"控制"),
                                                   is_instance_related=True),
                                            Action(id='claim',
                                                   name=_(u"认领"),
                                                   is_instance_related=True),
                                            Action(id='delete',
                                                   name=_(u"删除"),
                                                   is_instance_related=True),
                                            Action(id='clone',
                                                   name=_(u"克隆"),
                                                   is_instance_related=True)
                                        ],
                                        operations=[{
                                            'operate_id': 'view',
                                            'actions_id': ['view']
                                        }, {
                                            'operate_id':
                                            'edit',
                                            'actions_id': ['view', 'edit']
                                        }, {
                                            'operate_id':
                                            'operate',
                                            'actions_id': ['view', 'operate']
                                        }, {
                                            'operate_id':
                                            'claim',
                                            'actions_id': ['view', 'claim']
                                        }, {
                                            'operate_id':
                                            'delete',
                                            'actions_id': ['view', 'delete']
                                        }, {
                                            'operate_id':
                                            'clone',
                                            'actions_id': ['view', 'clone']
                                        }],
                                        parent=project_resource,
                                        resource_cls=TaskFlowInstance,
                                        id_field='id',
                                        tomb_field='is_deleted',
                                        backend=get_backend_from_config(),
                                        inspect=FixedCreatorTypeFieldInspect(
                                            creator_type='user',
                                            creator_id_f='creator',
                                            resource_id_f='id',
                                            resource_name_f='name',
                                            parent_f='project',
                                            scope_id_f=None))
예제 #13
0
project_resource = DjangoModelResource(
    rtype='project',
    name=_(u"项目"),
    scope_type='system',
    scope_id='bk_sops',
    scope_name=_(u"标准运维"),
    actions=[
        Action(id='create', name=_(u"新建"), is_instance_related=False),
        Action(id='view', name=_(u"查看"), is_instance_related=True),
        Action(id='edit', name=_(u"编辑"), is_instance_related=True),
        Action(id='create_template', name=_(u"新建流程"),
               is_instance_related=True),
        Action(id='use_common_template',
               name=_(u"使用公共流程"),
               is_instance_related=True),
        Action(id='fast_create_task',
               name=_(u"快速新建一次性任务"),
               is_instance_related=True),
    ],
    operations=[{
        'operate_id': 'create',
        'actions_id': ['create']
    }, {
        'operate_id': 'view',
        'actions_id': ['view']
    }, {
        'operate_id': 'edit',
        'actions_id': ['view', 'edit']
    }, {
        'operate_id': 'create_template',
        'actions_id': ['view', 'create_template']
    }, {
        'operate_id': 'use_common_template',
        'actions_id': ['view', 'use_common_template']
    }, {
        'operate_id': 'fast_create_task',
        'actions_id': ['view', 'fast_create_task']
    }],
    resource_cls=Project,
    id_field='id',
    backend=get_backend_from_config(),
    inspect=FixedCreatorTypeFieldInspect(creator_type='user',
                                         creator_id_f='creator',
                                         resource_id_f='id',
                                         resource_name_f='name',
                                         parent_f=None,
                                         scope_id_f=None))