def test_update_prop_reference2reference_correct(self): attr = ATTR.objects.get(id=self.attr_ref.id) attr_type_def_old = copy(attr.type_def) response = self.client.get(self.url, { \ 'attr_schema': self.attr_schema2.id, \ 'object_type': self.object_type1.id, \ 'attr': self.attr_ref.id, \ 'name': 'test1', \ 'description': 'test1', \ 'def_value': 'default value', \ 'mask': 'YYYY-MM-DD', \ 'type': self.attr_type_ref.id, \ 'tags': self.tag2.id, \ 'ref_object_type': self.object_type2.id, \ 'displayed': 'false', \ 'multiple': 'true', \ 'read_only': 'false', \ 'hidden': 'true', \ 'required': 'false', \ 'calculable': 'true' }) self.assertEqual(response.status_code, 200) attr = ATTR.objects.get(id=self.attr_ref.id) self.assertEqual(json.loads(response.content)['success'], True) self.assertNotEqual(json.loads(response.content)['message'], None) self.assertEqual(attr.name, 'test1') self.assertEqual(attr.description, 'test1') self.assertEqual(attr.def_value, 'default value') self.assertEqual(attr.mask, 'YYYY-MM-DD') self.assertEqual(attr.type, self.attr_type_ref) #set Attr_property aot = AOT.objects.get(object_type=self.object_type1, schema=self.attr_schema2, attr=self.attr_ref) attr_prop = Attr_property(aot=aot, attr=attr) self.assertEqual(attr_prop.getDisplayed(), False) self.assertEqual(attr_prop.getMultiple(), True ) self.assertEqual(attr_prop.getReadOnly(), False) self.assertEqual(attr_prop.getHidden(), True ) self.assertEqual(attr_prop.getRequired(), False) self.assertEqual(attr_prop.getCalculable(), True ) #инициализируем Property prop = Property(obj=attr) #сравниваем Tag self.assertEqual(attr.properties, 'admintool3_tag=%s' % self.tag2.id) #убеждаемся что reference_old НЕ удалился, т.к. на него могут ссылаться другие атрибуты attr_type_def_old = Type_def.objects.filter(id=attr_type_def_old.id) self.assertEqual(attr_type_def_old.count(), 1) #убеждаемся что reference_new появился attr_type_def_new = Type_def.objects.get(type=self.attr_type_ref, object_type=self.object_type2, schema=self.attr_schema2) self.assertEqual(attr.type_def, attr_type_def_new)
def test_update_prop_type_list2list_correct(self): response = self.client.get(self.url, { \ 'attr_schema': self.attr_schema2.id, \ 'object_type': self.object_type1.id, \ 'attr': self.attr_list.id, \ 'name': 'test1', \ 'description': 'test1', \ 'def_value': 'default value', \ 'mask': 'YYYY-MM-DD', \ 'type': self.attr_type_list.id, \ 'tags': self.tag1.id, \ 'ref_list': self.list2.id, \ 'displayed': 'true', \ 'multiple': 'false', \ 'read_only': 'true', \ 'hidden': 'false', \ 'required': 'true', \ 'calculable': 'false' }) self.assertEqual(response.status_code, 200) attr = ATTR.objects.get(id=self.attr_list.id) self.assertEqual(json.loads(response.content)['success'], True) self.assertNotEqual(json.loads(response.content)['message'], None) self.assertEqual(attr.name, 'test1') self.assertEqual(attr.description, 'test1') self.assertEqual(attr.def_value, 'default value') self.assertEqual(attr.mask, 'YYYY-MM-DD') self.assertEqual(attr.type, self.attr_type_list) self.assertEqual(attr.type_def, self.list2) #set Attr_property aot = AOT.objects.get(object_type=self.object_type1, schema=self.attr_schema2, attr=self.attr_list) attr_prop = Attr_property(aot=aot, attr=attr) self.assertEqual(attr_prop.getDisplayed(), True) self.assertEqual(attr_prop.getMultiple(), False) self.assertEqual(attr_prop.getReadOnly(), True) self.assertEqual(attr_prop.getHidden(), False) self.assertEqual(attr_prop.getRequired(), True) self.assertEqual(attr_prop.getCalculable(), False) #инициализируем Property prop = Property(obj=attr) #сравниваем Tag self.assertEqual(attr.properties, 'admintool3_tag=%s' % self.tag1.id) #убеждаемся что List остался list = Type_def.objects.filter(id=self.list.id) self.assertEqual(list.count(), 1) #убеждаемся что List2 остался list2 = Type_def.objects.filter(id=self.list2.id) self.assertEqual(list2.count(), 1)
def test_create_reference_correct(self): response = self.client.get(self.url, { \ 'attr_schema': self.attr_schema.id, \ 'object_type': self.object_type1.id, \ 'attr_group': self.attr_group1.id, \ 'name': 'Attr_new', \ 'description': 'test1', \ 'def_value': 'default value', \ 'mask': 'YYYY-MM-DD', \ 'type': self.attr_type_ref.id, \ 'tags': self.tag2.id, \ 'ref_object_type': self.object_type2.id, \ 'displayed': 'false', \ 'multiple': 'true', \ 'read_only': 'true', \ 'hidden': 'false', \ 'required': 'false', \ 'calculable': 'false' }) self.assertEqual(response.status_code, 200) attr = ATTR.objects.get(name='Attr_new') self.assertEqual(json.loads(response.content)['success'], True) self.assertNotEqual(json.loads(response.content)['message'], None) self.assertEqual(attr.description, 'test1') self.assertEqual(attr.def_value, 'default value') self.assertEqual(attr.mask, 'YYYY-MM-DD') self.assertEqual(attr.type, self.attr_type_ref) self.assertEqual(attr.group, self.attr_group1) self.assertEqual(attr.schema, self.attr_schema) aot = AOT.objects.get(schema=self.attr_schema, object_type=self.object_type1, attr=attr, options=0) #set Attr_property attr_prop = Attr_property(aot=aot, attr=attr) self.assertEqual(attr_prop.getDisplayed(), False) self.assertEqual(attr_prop.getMultiple(), True ) self.assertEqual(attr_prop.getReadOnly(), True ) self.assertEqual(attr_prop.getHidden(), False) self.assertEqual(attr_prop.getRequired(), False) self.assertEqual(attr_prop.getCalculable(), False) attr_type_def = Type_def.objects.get(schema=self.attr_schema, object_type=self.object_type2, type=self.attr_type_ref) self.assertEqual(attr.type_def, attr_type_def) #инициализируем Property prop = Property(obj=attr) #сравниваем Tag self.assertEqual(attr.properties, 'admintool3_tag=%s' % self.tag2.id)
def test_update_prop_blank_tag(self): response = self.client.get(self.url, { \ 'attr_schema': self.attr_schema.id, \ 'object_type': self.object_type1.id, \ 'attr': self.attr1.id, \ 'name': 'test1', \ 'description': 'test1', \ 'def_value': 'default value', \ 'mask': 'YYYY-MM-DD', \ 'type': self.attr_type2.id, \ 'tags': '', \ 'displayed': 'true', \ 'multiple': 'false', \ 'read_only': 'true', \ 'hidden': 'false', \ 'required': 'true', \ 'calculable': 'false' }) self.assertEqual(response.status_code, 200) attr = ATTR.objects.get(id=self.attr1.id) self.assertEqual(json.loads(response.content)['success'], True) self.assertNotEqual(json.loads(response.content)['message'], None) self.assertEqual(attr.name, 'test1') self.assertEqual(attr.description, 'test1') self.assertEqual(attr.def_value, 'default value') self.assertEqual(attr.mask, 'YYYY-MM-DD') self.assertEqual(attr.type, self.attr_type2) #set Attr_property aot = AOT.objects.get(object_type=self.object_type1, schema=self.attr_schema, attr=self.attr1) attr_prop = Attr_property(aot=aot, attr=attr) self.assertEqual(attr_prop.getDisplayed(), True ) self.assertEqual(attr_prop.getMultiple(), False) self.assertEqual(attr_prop.getReadOnly(), True ) self.assertEqual(attr_prop.getHidden(), False) self.assertEqual(attr_prop.getRequired(), True ) self.assertEqual(attr_prop.getCalculable(), False) #инициализируем Property prop = Property(obj=attr) #сравниваем Tag self.assertEqual(attr.properties, None)
def test_update_not_exist_mask(self): response = self.client.get(self.url, { 'attr_schema': self.attr_schema.id, \ 'attrs': [self.be_attr1.id], \ 'name': 'test1', \ 'description': 'test1', \ 'def_value': 'default value', \ 'type': self.attr_type2.id, \ 'displayed': 'true', \ 'multiple': 'false', \ 'read_only': 'true', \ 'hidden': 'false', \ 'required': 'true', \ 'calculable': 'false' }) self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content)['success'], True) #check attr1 attr1 = ATTR.objects.get(id=self.attr1.id) self.assertEqual(attr1.name, 'test1') self.assertEqual(attr1.description, 'test1') self.assertEqual(attr1.def_value, 'default value') self.assertEqual(attr1.mask, None) self.assertEqual(attr1.type, self.attr_type2) #set Attr_property aots = AOT.objects.filter(schema=self.attr_schema, attr=attr1) for aot in aots: attr_prop = Attr_property(aot=aot, attr=attr1) self.assertEqual(attr_prop.getDisplayed(), True ) self.assertEqual(attr_prop.getMultiple(), False) self.assertEqual(attr_prop.getReadOnly(), True ) self.assertEqual(attr_prop.getHidden(), False) self.assertEqual(attr_prop.getRequired(), True ) self.assertEqual(attr_prop.getCalculable(), False) #check be_attr1 be_attr1 = Tree_bulk_edit.objects.get(id=self.be_attr1.id) self.assertEqual(be_attr1.name, 'test1')
def prepare(schema, aot, attr): """ функция по навешиванию доп. свойств на атрибут """ if aot.options == 0: attr.origin = 'BIND' #атрибут привязан к данному OT в данной AS if aot.options == 2: attr.origin = 'UNBIND' #наследованое атрибута прервано на данном OT в данной AS if aot.options not in (0,2) or aot.options is None: attr.origin = 'UNKNOWN' #непонятный AOT не bind/unbind attr.schema = schema attr.binds = binds(attr) #params attr_prop = Attr_property(aot=aot, attr=attr) attr.displayed = attr_prop.getDisplayed() attr.required = attr_prop.getRequired() attr.read_only = attr_prop.getReadOnly() attr.hidden = attr_prop.getHidden() attr.calculable = attr_prop.getCalculable() attr.multiple = attr_prop.getMultiple() return attr