Coverage for backend/flowsheetInternals/unitops/serializers/PortSerializer.py: 81%
30 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1from rest_framework import serializers
2from flowsheetInternals.unitops.models.Port import Port
3from rest_framework.response import Response
4from flowsheetInternals.unitops.models.compound_propogation import update_compounds_on_add_stream, update_compounds_on_merge
5from flowsheetInternals.unitops.models.SimulationObject import SimulationObject
6from flowsheetInternals.unitops.models.flow_tracking import get_connected_ports
7class PortSerializer(serializers.ModelSerializer):
9 class Meta:
10 model = Port
11 fields = '__all__'
14 def update(self, port_instance, validated_data):
15 stream: SimulationObject = validated_data.get('stream')
16 if stream is not None or port_instance.stream is not None: 16 ↛ 40line 16 didn't jump to line 40 because the condition on line 16 was always true
17 prev_stream = port_instance.stream
19 if prev_stream is not None and stream is not None: 19 ↛ 29line 19 didn't jump to line 29 because the condition on line 19 was always true
20 if port_instance.direction == "inlet":
21 # prev stream start of loop, new stream end of loop
22 has_loop = prev_stream.has_path_to(stream)
23 else:
24 # new stream start of loop, prev stream end of loop
25 has_loop = stream.has_path_to(prev_stream)
26 if has_loop: 26 ↛ 27line 26 didn't jump to line 27 because the condition on line 26 was never true
27 stream.delete_control_values()
28 stream.attach_recycle()
29 port_instance.stream = stream
30 port_instance.save()
31 if prev_stream is not None: 31 ↛ 33line 31 didn't jump to line 33 because the condition on line 31 was always true
32 prev_stream.reevaluate_properties_enabled()
33 stream.reevaluate_properties_enabled()
35 if prev_stream is not None: 35 ↛ 38line 35 didn't jump to line 38 because the condition on line 35 was always true
36 update_compounds_on_merge(stream, prev_stream)
37 else:
38 update_compounds_on_add_stream(port_instance,stream)
40 return super().update(port_instance, validated_data)