def setUp(self): self.url = '/api/aot/rebind' setProjectSimple(project='default') self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent_id=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.attr_type2 = Type.objects.create(name='Memo', id=nc_id.get()) self.object_type1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type1) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.attr3 = ATTR.objects.create(name='Attr3', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema) self.aot2 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema) self.aot_unbind = AOT.create(attr=self.attr3, options=2, object_type=self.object_type2, schema=self.attr_schema)
def setUp(self): self.client = Client() self.object_type_all = OT.objects.create(name="All", description=None, id=nc_id.get(), parent=None) self.object_type_ot1 = OT.objects.create( name="OT1", description=None, id=nc_id.get(), parent=self.object_type_all )
def setUp(self): self.url = "/api/attr_schema/data" self.client = Client() self.attr_schema = AS.objects.create(name="Root", id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name="Root", id=nc_id.get(), parent=self.attr_schema)
def setUp(self): self.client = Client() self.tag1 = Tag.objects.create(name='Tag1', description=None) self.tag2 = Tag.objects.create(name='Tag2', description=None) self.object_type_all = OT.objects.create(name='All', description=None, id=nc_id.get(), parent=None) self.object_type_ot1 = OT.objects.create(name='OT1', description=None, id=nc_id.get(), parent=self.object_type_all)
def setUp(self): self.url = '/api/object_type/path' self.client = Client() self.object_type_ot1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type_ot2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type_ot1) self.object_type_ot3 = OT.objects.create(name='OT3', id=nc_id.get(), parent=self.object_type_ot2) self.object_type_ot4 = OT.objects.create(name='OT4', id=nc_id.get(), parent=self.object_type_ot3)
def setUp(self): self.url = '/api/attr_group/data' self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent=None) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema, description='digi1', subgroup='DIGI1') self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema, description='digi2', subgroup='DIGI2') self.attr_group3 = AG.objects.create(name='DiGi3', id=nc_id.get(), schema=self.attr_schema, description='digi3', subgroup='DIGI3')
def setUp(self): self.url = '/api/bulk/update' setProjectSimple(project='default') self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.attr_type2 = Type.objects.create(name='Memo', id=nc_id.get()) self.object_type1 = OT.objects.create(name='OT1', id=nc_id.get(), description = '', parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), description = '', parent=self.object_type1) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema) #Bulk edit self.be_object_type1 = Tree_bulk_edit.objects.create(name=self.object_type1.name, orig_id=self.object_type1.id, parent=None, type='object_type', attr_schema=self.attr_schema) self.be_object_type2 = Tree_bulk_edit.objects.create(name=self.object_type2.name, orig_id=self.object_type2.id, parent=self.be_object_type1, type='object_type', attr_schema=self.attr_schema) self.be_attr_group1 = Tree_bulk_edit.objects.create(name=self.attr_group1.name, orig_id=self.attr_group1.id, parent=self.be_object_type1, type='attr_group', attr_schema=self.attr_schema) self.be_attr_group2 = Tree_bulk_edit.objects.create(name=self.attr_group2.name, orig_id=self.attr_group2.id, parent=self.be_object_type2, type='attr_group', attr_schema=self.attr_schema) self.be_attr1 = Tree_bulk_edit.objects.create(name=self.attr1.name, orig_id=self.attr1.id, parent=self.be_attr_group1, type='attr', attr_schema=self.attr_schema) self.be_attr2 = Tree_bulk_edit.objects.create(name=self.attr2.name, orig_id=self.attr2.id, parent=self.be_attr_group2, type='attr', attr_schema=self.attr_schema)
def setUp(self): self.url = '/api/attr/order/update' self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent_id=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.attr_group = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(order=1, name='Attr1', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema) self.attr2 = ATTR.objects.create(order=2, name='Attr2', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema) self.attr3 = ATTR.objects.create(order=3, name='Attr3', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema)
def worker(req): """ функция создания списка """ schema = req.params()['attr_schema'] name = req.params()['name'] Type_def.objects.create(type_id=7, name=name, id=nc_id.get(), schema=schema) return { "success": True, "message": "Список успешно создан"}
def setUp(self): self.url = '/api/attr/order/index' self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent_id=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.attr_group = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.object_type = OT.objects.create(name='All1', id=nc_id.get(), parent=None) self.attr1 = ATTR.objects.create(order=1, name='Attr1', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema) self.attr2 = ATTR.objects.create(order=2, name='Attr2', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema) self.attr3 = ATTR.objects.create(order=3, name='Attr3', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type, schema=self.attr_schema) self.aot2 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type, schema=self.attr_schema) self.aot3 = AOT.create(attr=self.attr3, options=0, object_type=self.object_type, schema=self.attr_schema)
def setUp(self): self.url = '/api/value/order' self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='new schema', id=nc_id.get(), parent=None) self.attr_type_list = Type.objects.create(name='List', id=7) self.list1 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List1') self.value1_1 = Value.objects.create(id=nc_id.get(), list=self.list1, content='value1', order=0) self.value1_2 = Value.objects.create(id=nc_id.get(), list=self.list1, content='value2', order=1) self.value1_3 = Value.objects.create(id=nc_id.get(), list=self.list1, content='value3', order=2) self.value1_4 = Value.objects.create(id=nc_id.get(), list=self.list1, content='value3', order=3) #дублируем значение self.value1_5 = Value.objects.create(id=nc_id.get(), list=self.list1, content='value3', order=4) #дублируем значение
def worker(req): """ функция обновления содержимого списка """ value = req.params()['value'] if value is not None: #просто обновляем значение value.content = req.params()['content'] value.save() else: #создаём новое значение Value.objects.create(content=req.params()['content'], id=nc_id.get(), list=req.params()['list']) return { "success": True, "message": "Список успешно обновлён" }
def setUp(self): self.url = '/api/list/create' self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='new schema', id=nc_id.get(), parent=None) self.attr_type_list = Type.objects.create(name='List', id=7) self.list1 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List1') self.list2 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List2') self.list3 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List3') self.list4 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List4') self.list5 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List5')
def setUp(self): self.url = '/api/aot/clone' self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.object_type1 = OT.objects.create(name='All', description = '', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='All', description = '', id=nc_id.get(), parent=self.object_type1) self.attr_group1 = AG.objects.create(name='DiGi1', description = '', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', description = '', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', description = '', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema, id=nc_id.get()) self.aot2 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type1, schema=self.attr_schema, id=nc_id.get())
def setUp(self): self.url = '/api/search/index' self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.object_type1 = OT.objects.create(name='OT1', description='ot1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', description='ot2', id=nc_id.get(), parent=self.object_type1) self.attr_group1 = AG.objects.create(name='AG1', id=nc_id.get(), schema=self.attr_schema, description='ag1', subgroup='DIGI1') self.attr_group2 = AG.objects.create(name='AG2', id=nc_id.get(), schema=self.attr_schema, description='ag2', subgroup='DIGI2') self.attr1 = ATTR.objects.create(name='Attr1', description='attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', description='attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.aot1 = AOT.create(schema=self.attr_schema, object_type=self.object_type1, attr=self.attr1, options=0) self.aot2 = AOT.create(schema=self.attr_schema, object_type=self.object_type2, attr=self.attr2, options=0)
def setUp(self): self.url = '/api/log' #clean logs Log.objects.all().delete() self.client = Client() self.log1 = Log.objects.create( \ id=nc_id.get(), \ date=datetime.now(), \ user=u'user1', \ type=u'delete', \ nc_id=nc_id.get(), \ name=u'Attr1', \ operation=0, \ message=u'delete Attr1' ) self.log2 = Log.objects.create( \ id=nc_id.get(), \ date=datetime.now(), \ user=u'user2', \ type=u'create', \ nc_id=nc_id.get(), \ name=u'Attr2', \ operation=1, \ message=u'create Attr2' ) self.log3 = Log.objects.create( \ id=nc_id.get(), \ date=datetime.now(), \ user=u'user3', \ type=u'update', \ nc_id=nc_id.get(), \ name=u'Attr3', \ operation=2, \ message=u'update Attr3' \ )
def setUp(self): self.url = '/api/object_type/data' self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='Root', id=nc_id.get(), parent=self.attr_schema) self.tag1 = Tag.objects.create(name='Tag1', description=None) self.tag2 = Tag.objects.create(name='Tag2', description=None) self.object_type_ot1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type_ot2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type_ot1) self.object_type_ot3 = OT.objects.create(name='OT3', id=nc_id.get(), parent=self.object_type_ot2) self.object_type_ot4 = OT.objects.create(name='OT4', id=nc_id.get(), parent=self.object_type_ot3) #обновляем Tag prop = Property(obj=self.object_type_ot1) prop.tag.set(tags=[self.tag1, self.tag2,]) prop = Property(obj=self.object_type_ot2) prop.tag.set(tags=[self.tag2,])
def setUp(self): self.client = Client() self.object_type1 = OT.objects.create(name='All', id=nc_id.get(), description='', parent=None) self.object_type2 = OT.objects.create(name='Cable', id=nc_id.get(), description='', parent=self.object_type1)
def worker(req): """ функция создания атрибутной группы """ attr_schema = req.params()['attr_schema'] name = req.params()['name'] description = req.params()['description'] subgroup = req.params()['subgroup'] #создаём новый объектный тип(генерируем следующий object_type_id) attr_group = AG.objects.create(name=name, description=description, schema=attr_schema, id=nc_id.get(), subgroup=subgroup) return { "success": True, "message": "атрибутная группа %s успешно создана" % str(attr_group.id) }
def worker(req): """ функция создания объектного типа """ parent = req.params()['object_type'] name = req.params()['name'] description = req.params()['description'] tags = req.params()['tags'] #создаём новый объектный тип(генерируем следующий object_type_id) object_type = OT.objects.create(name=name, description=description, parent=parent, id=nc_id.get()) #обновляем Tag если tags пришли if not tags == -1: object_type.set(tags=tags) return { "success": True, "id": str(object_type.id), "iconCls": settings.OBJECT_TYPE_ICON, "message": "объектный тип %s успешно создан" % str(object_type.id) }
def test_correct5(self): AS.objects.all().delete() OT.objects.all().delete() AG.objects.all().delete() ATTR.objects.all().delete() AOT.objects.all().delete() Type.objects.all().delete() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent_id=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.object_type1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type1) self.object_type3 = OT.objects.create(name='OT3', id=nc_id.get(), parent=self.object_type1) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema) self.attr_group3 = AG.objects.create(name='DiGi3', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.attr3 = ATTR.objects.create(name='Attr3', id=nc_id.get(), type=self.attr_type, group=self.attr_group3, schema=self.attr_schema) self.aot1_exist = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema) self.aot2_exist = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema) self.aot3_exist = AOT.create(attr=self.attr3, options=0, object_type=self.object_type3, schema=self.attr_schema) aot13_bind = AOT.create(attr=self.attr1, options=0, object_type=self.object_type3, schema=self.attr_schema) aot12_bind = AOT.create(attr=self.attr1, options=0, object_type=self.object_type2, schema=self.attr_schema) response = self.client.get(self.url, {'attr': self.attr1.id }) self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content)[0], \ { \ 'origin': None, \ 'leaf': False, \ 'description': None, \ 'text': self.attr_schema.name, \ 'expanded': True, \ 'type': 'AS', \ 'nc_id': str(self.attr_schema.id), \ 'iconCls': settings.ATTR_SCHEMA_ICON, \ 'attr_schema_name': self.attr_schema.name, \ 'id': 26, \ 'children': [{ \ 'origin': 'bind', \ 'leaf': False, \ 'description': None, \ 'text': self.object_type1.name, \ 'expanded': True, \ 'nc_id': str(self.object_type1.id), \ 'type': 'OT', \ 'id': 27, \ 'attr_schema_name': self.attr_schema.name, \ 'iconCls': settings.BIND_ICON, \ 'children': [{ \ 'origin': 'bind', \ 'leaf': True, \ 'description': None, \ 'text': self.object_type3.name, \ 'expanded': False, \ 'nc_id': str(self.object_type3.id), \ 'type': 'OT', \ 'id': 29, \ 'attr_schema_name': self.attr_schema.name, \ 'iconCls': settings.BIND_ICON \ },{ 'origin': 'bind', \ 'leaf': True, \ 'description': None, \ 'text': self.object_type2.name, \ 'expanded': False, \ 'nc_id': str(self.object_type2.id), \ 'type': 'OT', \ 'id': 28, \ 'attr_schema_name': self.attr_schema.name, \ 'iconCls': settings.BIND_ICON \ }] \ }] \ } \ )
def setUp(self): self.url = '/api/list/index' self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='new schema', id=nc_id.get(), parent=None) self.attr_type_list = Type.objects.create(name='List', id=7) self.list1 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List1') self.list2 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List2') self.list3 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List3') self.list4 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List4') self.list5 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List5') self.list_atm1 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='ATM_') self.value_atm1 = Value.objects.create(id=nc_id.get(), list=self.list_atm1, content='ATM_') self.list_atm2 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='_ATM') self.value_atm2 = Value.objects.create(id=nc_id.get(), list=self.list_atm2, content='_ATM') self.list_atm3 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='_ATM_') self.value_atm3 = Value.objects.create(id=nc_id.get(), list=self.list_atm3, content='_ATM_') self.list_atm4 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='ATM') self.value_atm4 = Value.objects.create(id=nc_id.get(), list=self.list_atm4, content='ATM')
def setUp(self): self.client = Client() self.attr_scheme_root = AS.objects.create(id=nc_id.get(), name=u'Root', description=None, parent=None) self.attr_scheme_digi = AS.objects.create(id=nc_id.get(), name=u'DiGi', description=None, parent=self.attr_scheme_root)
def setUp(self): self.url = "/api/bulk/index" setProjectSimple(project="default") self.client = Client() self.attr_schema = AS.objects.create(name="Root", description="", id=nc_id.get(), parent=None) self.attr_type = Type.objects.create(name="Text", id=nc_id.get()) self.attr_type2 = Type.objects.create(name="Memo", id=nc_id.get()) self.object_type1 = OT.objects.create(name="OT1", id=nc_id.get(), description="", parent=None) self.object_type2 = OT.objects.create(name="OT2", id=nc_id.get(), description="", parent=self.object_type1) self.attr_group1 = AG.objects.create(name="DiGi1", id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name="DiGi2", id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create( name="Attr1", id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema ) self.attr2 = ATTR.objects.create( name="Attr2", id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema ) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema) self.aot1 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema) # Bulk edit self.be_object_type1 = Tree_bulk_edit.objects.create( name=self.object_type1.name, orig_id=self.object_type1.id, parent=None, type="object_type", attr_schema=self.attr_schema, ) self.be_object_type2 = Tree_bulk_edit.objects.create( name=self.object_type2.name, orig_id=self.object_type2.id, parent=self.be_object_type1, type="object_type", attr_schema=self.attr_schema, ) self.be_attr_group1 = Tree_bulk_edit.objects.create( name=self.attr_group1.name, orig_id=self.attr_group1.id, parent=self.be_object_type1, type="attr_group", attr_schema=self.attr_schema, ) self.be_attr_group2 = Tree_bulk_edit.objects.create( name=self.attr_group2.name, orig_id=self.attr_group2.id, parent=self.be_object_type2, type="attr_group", attr_schema=self.attr_schema, ) self.be_attr1 = Tree_bulk_edit.objects.create( name=self.attr1.name, orig_id=self.attr1.id, parent=self.be_attr_group1, type="attr", attr_schema=self.attr_schema, ) self.be_attr2 = Tree_bulk_edit.objects.create( name=self.attr2.name, orig_id=self.attr2.id, parent=self.be_attr_group2, type="attr", attr_schema=self.attr_schema, )
def setUp(self): self.url = '/api/analytic' setProjectSimple(project='default') self.client = Client() self.attr_schema = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.object_type1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type1) self.object_type3 = OT.objects.create(name='OT3', id=nc_id.get(), parent=self.object_type2) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema) self.attr_group3 = AG.objects.create(name='DiGi3', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.attr3 = ATTR.objects.create(name='Attr3', id=nc_id.get(), type=self.attr_type, group=self.attr_group3, schema=self.attr_schema) self.aot1_exist = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema, id=nc_id.get()) self.aot2_exist = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema, id=nc_id.get()) self.aot3_exist = AOT.create(attr=self.attr3, options=0, object_type=self.object_type3, schema=self.attr_schema, id=nc_id.get())
def setUp(self): self.url = '/api/attr/index' self.client = Client() self.attr_schema = AS.objects.create(name='Root', description = '', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='DiGi', description = '', id=nc_id.get(), parent=self.attr_schema) self.attr_type = Type.objects.create(name='Text', id=nc_id.get()) self.attr_type2 = Type.objects.create(name='Memo', id=nc_id.get()) self.object_type1 = OT.objects.create(name='All1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type1) self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema) self.attr1 = ATTR.objects.create(name='Attr1', id=nc_id.get(), type=self.attr_type, group=self.attr_group1, schema=self.attr_schema) self.attr2 = ATTR.objects.create(name='Attr2', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) self.attr3 = ATTR.objects.create(name='Attr3', id=nc_id.get(), type=self.attr_type, group=self.attr_group2, schema=self.attr_schema) #reference attribute self.attr_type_ref = Type.objects.create(name='Reference', id=9) self.attr_type_def = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_ref, schema=self.attr_schema, object_type=self.object_type1) self.attr_ref = ATTR.objects.create(name='Reference', id=nc_id.get(), type=self.attr_type_ref, group=self.attr_group2, schema=self.attr_schema, type_def=self.attr_type_def) #list attribute self.attr_type_list = Type.objects.create(name='List', id=7) self.list = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List1') self.list2 = Type_def.objects.create(id=nc_id.get(), type=self.attr_type_list, schema=self.attr_schema, object_type=None, name='List2') self.attr_list = ATTR.objects.create(name='Attribute List', id=nc_id.get(), type=self.attr_type_list, group=self.attr_group2, schema=self.attr_schema, type_def=self.list) self.aot1 = AOT.create(attr=self.attr1, options=0, object_type=self.object_type1, schema=self.attr_schema) self.aot2 = AOT.create(attr=self.attr2, options=0, object_type=self.object_type2, schema=self.attr_schema) self.aot4 = AOT.create(attr=self.attr_ref, options=0, object_type=self.object_type1, schema=self.attr_schema2) self.aot5 = AOT.create(attr=self.attr_list, options=0, object_type=self.object_type1, schema=self.attr_schema2) #unbind self.aot_unbind = AOT.create(attr=self.attr3, options=2, object_type=self.object_type2, schema=self.attr_schema2)
def worker(req): """ функция модификации атрибута """ schema = req.params()["attr_schema"] object_type = req.params()["object_type"] group = req.params()["attr_group"] name = req.params()["name"] description = req.params()["description"] type = req.params()["type"] def_value = req.params()["def_value"] mask = req.params()["mask"] tags = req.params()["tags"] displayed = req.params()["displayed"] multiple = req.params()["multiple"] read_only = req.params()["read_only"] hidden = req.params()["hidden"] required = req.params()["required"] calculable = req.params()["calculable"] # создаём атрибут attr = ATTR.objects.create( id=nc_id.get(), group=group, schema=schema, type=type, name=name, description=description, def_value=def_value, mask=mask, ) # создаём AOT AOT().create(schema=schema, object_type=object_type, attr=attr, options=0) aot = AOT.objects.get(schema=schema, object_type=object_type, attr=attr) # set Attr_property attr_prop = Attr_property(aot=aot, attr=attr) attr_prop.setDisplayed(displayed) attr_prop.setRequired(required) attr_prop.setMultiple(multiple) attr_prop.setReadOnly(read_only) attr_prop.setHidden(hidden) attr_prop.setCalculable(calculable) # обновляем Tag если Tags пришли if not tags == -1: attr.set(tags=tags) # TYPE if attr.type.id == 7: # это List req = ListRequired(request=req.request, req_params=["ref_list"]) if req.success(): # создаём ссылку на List attr.type_def = req.params()["ref_list"] else: return {"success": False, "errors": req.errors()} if attr.type.id == 9: # это Reference req = OTRequired(request=req.request, req_params=["ref_object_type"]) if req.success(): # создаём Reference attr.type_def = Type_def.objects.create( id=nc_id.get(), type=attr.type, schema=schema, object_type=req.params()["ref_object_type"] ) else: return {"success": False, "errors": req.errors()} # сохраняем атрибут attr.save() return {"success": True, "message": "Атрибут %s успешно создан" % str(attr.id)}
def change_type(**args): '''смена типа атрибута''' attr = args['attr'] old_type = args['old_type'] new_type = args['new_type'] request = args['request'] schema = args['schema'] success = True errors = None ''' OTHER ''' #переход из other в other if old_type.id not in (7,9) and new_type.id not in (7,9): if not old_type.id == new_type.id: attr.type = new_type #переход из other в List if old_type.id not in (7,9) and new_type.id == 7: req = ListRequired(request=request, req_params=['ref_list']) if req.success(): ref_list = req.params()['ref_list'] if ref_list is not None: #ref_list пришёл => создаём ссылку на List attr.type = new_type attr.type_def = ref_list else: success = False errors = req.errors() #переход из other в Reference if old_type.id not in (7,9) and new_type.id == 9: #это Reference req = OTRequired(request=request, req_params=['ref_object_type']) if req.success(): ref_object_type = req.params()['ref_object_type'] if ref_object_type is not None: #ref_object_type пришёл => создаём новый Reference type_ref = Type_def.objects.create(id=nc_id.get(), type=new_type, schema=schema, object_type=ref_object_type) attr.type = new_type attr.type_def = type_ref else: success = False errors = req.errors() ''' LIST ''' #переход из List в other if old_type.id == 7 and new_type.id not in (7,9): attr.type_def = None attr.type = new_type #переход из List в List if old_type.id == 7 and new_type.id == 7: req = ListRequired(request=request, req_params=['ref_list']) if req.success(): ref_list = req.params()['ref_list'] if ref_list is not None: #ref_list пришёл => создаём ссылку на List и это ссылка на другой List if not attr.type_def == ref_list: attr.type_def = ref_list else: success = False errors = req.errors() #переход из List в Reference if old_type.id == 7 and new_type.id == 9: #это Reference req = OTRequired(request=request, req_params=['ref_object_type']) if req.success(): ref_object_type = req.params()['ref_object_type'] if ref_object_type is not None: #ref_object_type пришёл => создаём новый Reference type_ref = Type_def.objects.create(id=nc_id.get(), type=new_type, schema=schema, object_type=ref_object_type) attr.type = new_type attr.type_def = type_ref else: success = False errors = req.errors() ''' REFERENCE ''' #переход из Reference в other if old_type.id == 9 and new_type.id not in (7,9): attr.type_def = None attr.type = new_type #переход из Reference в List if old_type.id == 9 and new_type.id == 7: req = ListRequired(request=request, req_params=['ref_list']) if req.success(): ref_list = req.params()['ref_list'] if ref_list is not None: #ref_list пришёл => создаём ссылку на List attr.type_def = ref_list attr.type = new_type else: success = False errors = req.errors() #переход из Reference в Reference if old_type.id == 9 and new_type.id == 9: #это Reference req = OTRequired(request=request, req_params=['ref_object_type']) if req.success(): ref_object_type = req.params()['ref_object_type'] if ref_object_type is not None: try: #пытаем найти нужный reference type_ref = Type_def.objects.get(type=new_type, schema=schema, object_type=ref_object_type) except ObjectDoesNotExist: #такого reference ещё не существует - создадим его type_ref = Type_def.objects.create(id=nc_id.get(), type=new_type, schema=schema, object_type=ref_object_type) attr.type_def = type_ref except MultipleObjectsReturned: #подобных типов много - выберем любой из них type_ref = Type_def.objects.filter(type=new_type, schema=schema, object_type=ref_object_type)[0] if not attr.type_def == type_ref: #если текущий reference и новый не совпадают - обновим type_def attr.type_def = type_ref else: if not attr.type_def == type_ref: #если текущий reference и новый не совпадают - обновим type_def attr.type_def = type_ref else: success = False errors = req.errors() #в случае ошибок возвращаем описание ошибки if success and errors is None: return (True, None) else: return (False, errors)
def setUp(self): self.url = '/api/attr/data' self.client = Client() #AS self.attr_schema1 = AS.objects.create(name='Root', id=nc_id.get(), parent=None) self.attr_schema2 = AS.objects.create(name='Root', id=nc_id.get(), parent=self.attr_schema1) #Tag self.tag1 = Tag.objects.create(name='Tag1', description=None) self.tag2 = Tag.objects.create(name='Tag2', description=None) #Type self.attr_type1 = Type.objects.create(name='Text', id=nc_id.get()) self.attr_type2 = Type.objects.create(name='Memo', id=nc_id.get()) #OT self.object_type1 = OT.objects.create(name='OT1', id=nc_id.get(), parent=None) self.object_type2 = OT.objects.create(name='OT2', id=nc_id.get(), parent=self.object_type1) #AG self.attr_group1 = AG.objects.create(name='DiGi1', id=nc_id.get(), schema=self.attr_schema1) self.attr_group2 = AG.objects.create(name='DiGi2', id=nc_id.get(), schema=self.attr_schema2) #ATTR self.attr11 = ATTR.objects.create(name='Attr11', id=nc_id.get(), type=self.attr_type1, group=self.attr_group1, schema=self.attr_schema1) self.attr12 = ATTR.objects.create(name='Attr12', id=nc_id.get(), type=self.attr_type1, group=self.attr_group1, schema=self.attr_schema1) self.attr21 = ATTR.objects.create(name='Attr21', id=nc_id.get(), type=self.attr_type2, group=self.attr_group2, schema=self.attr_schema2) self.attr22 = ATTR.objects.create(name='Attr22', id=nc_id.get(), type=self.attr_type2, group=self.attr_group2, schema=self.attr_schema2) #AOT self.aot11 = AOT.create(attr=self.attr11, options=0, object_type=self.object_type1, schema=self.attr_schema1) self.aot12 = AOT.create(attr=self.attr12, options=0, object_type=self.object_type2, schema=self.attr_schema1) self.aot21 = AOT.create(attr=self.attr21, options=0, object_type=self.object_type1, schema=self.attr_schema2) self.aot22 = AOT.create(attr=self.attr22, options=0, object_type=self.object_type2, schema=self.attr_schema2) #обновляем Tag prop = Property(obj=self.attr11) prop.tag.set(tags=[self.tag1,]) prop = Property(obj=self.attr22) prop.tag.set(tags=[self.tag2,]) prop = Property(obj=self.attr21) prop.tag.set(tags=[self.tag2, self.tag1,]) prop = Property(obj=self.attr12) prop.tag.set(tags=[self.tag1, self.tag2,])