Coverage for backend/django/flowsheetInternals/unitops/serializers/PortSerializer.py: 96%

34 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-07-22 05:22 +0000

1from core.serializer_base import StateOwnedModelSerializer 

2from rest_framework import serializers 

3from flowsheetInternals.unitops.models.Port import Port 

4from rest_framework.response import Response 

5from flowsheetInternals.unitops.models.compound_propogation import update_compounds_on_add_stream, update_compounds_on_merge 

6from flowsheetInternals.unitops.models.SimulationObject import SimulationObject 

7from flowsheetInternals.unitops.models.flow_tracking import get_connected_ports 

8class PortSerializer(StateOwnedModelSerializer): 

9 

10 class Meta: 

11 model = Port 

12 fields = '__all__' 

13 

14 

15 def update(self, port_instance, validated_data): 

16 stream: SimulationObject = validated_data.get('stream') 

17 if stream is not None: 

18 prev_stream = port_instance.stream 

19 

20 if prev_stream is not None and stream is not None: 

21 if port_instance.direction == "inlet": 

22 # prev stream start of loop, new stream end of loop 

23 has_loop = prev_stream.has_path_to(stream) 

24 else: 

25 # new stream start of loop, prev stream end of loop 

26 has_loop = stream.has_path_to(prev_stream) 

27 if has_loop: 

28 stream.delete_control_values() 

29 stream.attach_recycle() 

30 port_instance.stream = stream 

31 port_instance.save() 

32 if prev_stream is not None: 

33 prev_stream.reevaluate_properties_enabled() 

34 if stream is not None: 34 ↛ 37line 34 didn't jump to line 37 because the condition on line 34 was always true

35 stream.reevaluate_properties_enabled() 

36 

37 if prev_stream is not None and stream is not None: 

38 update_compounds_on_merge(stream, prev_stream) 

39 elif stream is not None: 39 ↛ 42line 39 didn't jump to line 42 because the condition on line 39 was always true

40 update_compounds_on_add_stream(port_instance,stream) 

41 

42 port_instance.flowsheet_state.flowsheet.record_content_change() 

43 

44 return super().update(port_instance, validated_data)