mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-11-15 17:21:38 +03:00
B: Fix propagate attribution creation
This commit is contained in:
parent
cb1985ef74
commit
c875a549c9
|
|
@ -135,10 +135,10 @@ class PropagationEngine:
|
|||
return
|
||||
for child_id in children:
|
||||
if not exclude or child_id not in exclude:
|
||||
self.inherit_association(child_id, items)
|
||||
self.inherit_attribution(child_id, items)
|
||||
|
||||
def inherit_association(self, target: int, items: list[Attribution]) -> None:
|
||||
''' Execute inheritance of Associations. '''
|
||||
def inherit_attribution(self, target: int, items: list[Attribution]) -> None:
|
||||
''' Execute inheritance of Attributions. '''
|
||||
operation = self.cache.operation_by_id[target]
|
||||
if operation.result is None or not items:
|
||||
return
|
||||
|
|
@ -153,8 +153,8 @@ class PropagationEngine:
|
|||
|
||||
new_attributions: list[Attribution] = []
|
||||
for attrib in items:
|
||||
new_container = self.cache.get_inheritor(attrib.container_id, target)
|
||||
new_attribute = self.cache.get_inheritor(attrib.attribute_id, target)
|
||||
new_container = self.cache.get_successor(attrib.container_id, target)
|
||||
new_attribute = self.cache.get_successor(attrib.attribute_id, target)
|
||||
if new_container is None or new_attribute is None \
|
||||
or new_attribute == new_container \
|
||||
or (new_container, new_attribute) in existing_attributions:
|
||||
|
|
@ -199,8 +199,8 @@ class PropagationEngine:
|
|||
|
||||
deleted: list[Attribution] = []
|
||||
for attr in attributions:
|
||||
new_container = self.cache.get_inheritor(attr.container_id, child_id)
|
||||
new_attribute = self.cache.get_inheritor(attr.attribute_id, child_id)
|
||||
new_container = self.cache.get_successor(attr.container_id, child_id)
|
||||
new_attribute = self.cache.get_successor(attr.attribute_id, child_id)
|
||||
if new_container is None or new_attribute is None:
|
||||
continue
|
||||
deleted_assoc = Attribution.objects.filter(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
''' Testing API: Change constituents in OSS. '''
|
||||
|
||||
from apps.oss.models import OperationSchema, OperationType
|
||||
from apps.rsform.models import Constituenta, CstType, RSForm
|
||||
from apps.rsform.models import Attribution, Constituenta, CstType, RSForm
|
||||
from shared.EndpointTester import EndpointTester, decl_endpoint
|
||||
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ class TestChangeConstituents(EndpointTester):
|
|||
'crucial': True,
|
||||
}
|
||||
}
|
||||
response = self.executeOK(data, schema=self.ks1.model.pk)
|
||||
self.executeOK(data, schema=self.ks1.model.pk)
|
||||
self.ks1X1.refresh_from_db()
|
||||
d2.refresh_from_db()
|
||||
inherited_cst = Constituenta.objects.get(as_child__parent_id=self.ks1X1.pk)
|
||||
|
|
@ -145,7 +145,7 @@ class TestChangeConstituents(EndpointTester):
|
|||
@decl_endpoint('/api/rsforms/{schema}/delete-multiple-cst', method='patch')
|
||||
def test_delete_constituenta(self):
|
||||
data = {'items': [self.ks2X1.pk]}
|
||||
response = self.executeOK(data, schema=self.ks2.model.pk)
|
||||
self.executeOK(data, schema=self.ks2.model.pk)
|
||||
inherited_cst = Constituenta.objects.get(as_child__parent_id=self.ks2D1.pk)
|
||||
self.ks2D1.refresh_from_db()
|
||||
self.assertEqual(self.ks2.constituentsQ().count(), 1)
|
||||
|
|
@ -168,3 +168,30 @@ class TestChangeConstituents(EndpointTester):
|
|||
self.assertEqual(self.ks3.constituentsQ().count(), 4)
|
||||
self.assertEqual(self.ks1X2.order, 0)
|
||||
self.assertEqual(d2.definition_formal, r'X2\X2\X3')
|
||||
|
||||
|
||||
@decl_endpoint('/api/rsforms/{schema}/create-attribution', method='post')
|
||||
def test_create_attribution(self):
|
||||
data = {'container': self.ks1X1.pk, 'attribute': self.ks1X2.pk}
|
||||
self.executeCreated(data, schema=self.ks1.model.pk)
|
||||
x1_child = Constituenta.objects.get(as_child__parent_id=self.ks1X1.pk)
|
||||
x2_child = Constituenta.objects.get(as_child__parent_id=self.ks1X2.pk)
|
||||
self.assertTrue(Attribution.objects.filter(container=x1_child, attribute=x2_child).exists())
|
||||
|
||||
|
||||
@decl_endpoint('/api/rsforms/{schema}/create-attribution', method='post')
|
||||
def test_create_attribution_substitution(self):
|
||||
self.operation3.result.delete()
|
||||
self.owned.set_substitutions(self.operation3.pk, [{
|
||||
'original': self.ks1X1,
|
||||
'substitution': self.ks2X1
|
||||
}])
|
||||
self.owned.execute_operation(self.operation3)
|
||||
self.operation3.refresh_from_db()
|
||||
self.ks3 = RSForm(self.operation3.result)
|
||||
|
||||
data = {'container': self.ks1X1.pk, 'attribute': self.ks1X2.pk}
|
||||
self.executeCreated(data, schema=self.ks1.model.pk)
|
||||
x1_child = Constituenta.objects.get(as_child__parent_id=self.ks2X1.pk)
|
||||
x2_child = Constituenta.objects.get(as_child__parent_id=self.ks1X2.pk)
|
||||
self.assertTrue(Attribution.objects.filter(container=x1_child, attribute=x2_child).exists())
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TestAttributionsEndpoints(EndpointTester):
|
|||
self.executeBadData(data, item=self.owned_id)
|
||||
|
||||
data = {'container': self.n1.pk, 'attribute': self.x1.pk}
|
||||
self.executeBadData(data, item=self.unowned_id)
|
||||
self.executeForbidden(data, item=self.unowned_id)
|
||||
|
||||
response = self.executeCreated(data, item=self.owned_id)
|
||||
attributions = response.data['attribution']
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
|
|||
'restore_order',
|
||||
'reset_aliases',
|
||||
'produce_structure',
|
||||
'add_attribution',
|
||||
'create_attribution',
|
||||
'delete_attribution',
|
||||
'clear_attributions'
|
||||
]:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user