mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Fix constituenta editing
This commit is contained in:
parent
2c6038116a
commit
7415eed8cd
|
@ -43,9 +43,15 @@ class ConstituentaSerializer(serializers.ModelSerializer):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = ('id', 'order', 'alias', 'cst_type')
|
read_only_fields = ('id', 'order', 'alias', 'cst_type')
|
||||||
|
|
||||||
def update(self, instance: Constituenta, validated_data):
|
def update(self, instance: Constituenta, validated_data) -> Constituenta:
|
||||||
|
if ('term_raw' in validated_data):
|
||||||
|
validated_data['term_resolved'] = validated_data['term_raw']
|
||||||
|
if ('definition_raw' in validated_data):
|
||||||
|
validated_data['definition_resolved'] = validated_data['definition_raw']
|
||||||
|
|
||||||
|
result = super().update(instance, validated_data)
|
||||||
instance.schema.save()
|
instance.schema.save()
|
||||||
return super().update(instance, validated_data)
|
return result
|
||||||
|
|
||||||
|
|
||||||
class StandaloneCstSerializer(serializers.ModelSerializer):
|
class StandaloneCstSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -31,6 +31,10 @@ class TestConstituentaAPI(APITestCase):
|
||||||
alias='X1', schema=self.rsform_owned, order=1, convention='Test')
|
alias='X1', schema=self.rsform_owned, order=1, convention='Test')
|
||||||
self.cst2 = Constituenta.objects.create(
|
self.cst2 = Constituenta.objects.create(
|
||||||
alias='X2', schema=self.rsform_unowned, order=1, convention='Test1')
|
alias='X2', schema=self.rsform_unowned, order=1, convention='Test1')
|
||||||
|
self.cst3 = Constituenta.objects.create(
|
||||||
|
alias='X3', schema=self.rsform_owned, order=2,
|
||||||
|
term_raw='Test1', term_resolved='Test1',
|
||||||
|
definition_raw='Test1', definition_resolved='Test2')
|
||||||
|
|
||||||
def test_retrieve(self):
|
def test_retrieve(self):
|
||||||
response = self.client.get(f'/api/constituents/{self.cst1.id}/')
|
response = self.client.get(f'/api/constituents/{self.cst1.id}/')
|
||||||
|
@ -57,6 +61,17 @@ class TestConstituentaAPI(APITestCase):
|
||||||
response = self.client.patch(f'/api/constituents/{self.cst1.id}/', data, content_type='application/json')
|
response = self.client.patch(f'/api/constituents/{self.cst1.id}/', data, content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_partial_update_update_resolved(self):
|
||||||
|
data = json.dumps({
|
||||||
|
'term_raw': 'New term',
|
||||||
|
'definition_raw': 'New def'
|
||||||
|
})
|
||||||
|
response = self.client.patch(f'/api/constituents/{self.cst3.id}/', data, content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.cst3.refresh_from_db()
|
||||||
|
self.assertEqual(self.cst3.term_resolved, 'New term')
|
||||||
|
self.assertEqual(self.cst3.definition_resolved, 'New def')
|
||||||
|
|
||||||
def test_readonly_cst_fields(self):
|
def test_readonly_cst_fields(self):
|
||||||
data = json.dumps({'alias': 'X33', 'order': 10})
|
data = json.dumps({'alias': 'X33', 'order': 10})
|
||||||
response = self.client.patch(f'/api/constituents/{self.cst1.id}/', data, content_type='application/json')
|
response = self.client.patch(f'/api/constituents/{self.cst1.id}/', data, content_type='application/json')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user