-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2427 internal users can transfer a facility or operation #2557
Changes from 1 commit
c2cb573
6e62445
a8361b5
c443150
3d59799
ad4ced0
d62b410
b4a908d
6b99ddc
6db5193
d1b51f7
e11ba88
e584d84
4599f90
58ce5fa
062942a
2816b5d
afd6221
49a8a56
47c7222
0e9fb44
e9474f4
5196f68
dc7d1e0
f0b06bb
43b2aae
5e854ad
8ef2f99
aba9f4f
35bc6df
0780dce
93826a2
29f4edc
0f2b1c4
2f22c75
72de680
2d15e58
f1ad03d
ddf8676
8c95f93
4134e7f
b0ee873
2668fbf
acbf3dd
1f9a07a
8c20d4d
20306cd
fa1a690
21bc2e9
f59d3f2
eabb344
2439d76
0a49409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
# ruff: noqa: F401 | ||
from ._operator_id.operations import list_operations_by_operator_id | ||
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,19 +28,6 @@ def test_list_transfer_events(): | |
|
||
@staticmethod | ||
def test_validate_no_overlapping_transfer_events(): | ||
operation = baker.make_recipe('utils.operation') | ||
baker.make_recipe( | ||
'utils.transfer_event', | ||
operation=operation, | ||
status=TransferEvent.Statuses.TO_BE_TRANSFERRED, | ||
) | ||
facilities = baker.make_recipe('utils.facility', _quantity=2) | ||
baker.make_recipe( | ||
'utils.transfer_event', | ||
facilities=facilities, | ||
status=TransferEvent.Statuses.COMPLETE, | ||
) | ||
|
||
# Scenario 1: No overlapping operation or facility | ||
new_operation = baker.make_recipe('utils.operation') | ||
new_facilities = baker.make_recipe('utils.facility', _quantity=2) | ||
|
@@ -52,10 +39,22 @@ def test_validate_no_overlapping_transfer_events(): | |
pytest.fail(f"Unexpected exception raised: {e}") | ||
|
||
# Scenario 2: Overlapping operation | ||
Sepehr-Sobhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
operation = baker.make_recipe('utils.operation') | ||
baker.make_recipe( | ||
'utils.transfer_event', | ||
operation=operation, | ||
status=TransferEvent.Statuses.TO_BE_TRANSFERRED, | ||
) | ||
with pytest.raises(Exception, match="An active transfer event already exists for the selected operation."): | ||
TransferEventService.validate_no_overlapping_transfer_events(operation_id=operation.id) | ||
|
||
# Scenario 3: Overlapping facilities | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK so horrible question, are there situations where we could have overlap between operations and facilities? Like Fruit Operation has facilities Apple and Orange, and Vegetable Operation has Carrot and Spinach. There's a future transfer that's Apple to Vegetable Operation. But then someone wants to transfer Vegetable Operation to a new operator, so what happens to Apple? I don't suggest addressing that in this PR, but if it's a possibility, we could make a card. Probably an edge case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that’s an excellent question—and also a terrifying one! Definitely worth discussing this 😵💫 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a ticket for this: #2588 |
||
facilities = baker.make_recipe('utils.facility', _quantity=2) | ||
baker.make_recipe( | ||
'utils.transfer_event', | ||
facilities=facilities, | ||
status=TransferEvent.Statuses.COMPLETE, | ||
) | ||
with pytest.raises( | ||
Exception, | ||
match="One or more facilities in this transfer event are already part of an active transfer event.", | ||
|
@@ -106,6 +105,26 @@ def test_create_transfer_event_operation_missing_operation(cls, mock_get_by_guid | |
with pytest.raises(Exception, match="Operation is required for operation transfer events."): | ||
TransferEventService.create_transfer_event(cas_analyst.user_guid, payload) | ||
|
||
@classmethod | ||
@patch("service.transfer_event_service.TransferEventService.validate_no_overlapping_transfer_events") | ||
@patch("service.data_access_service.user_service.UserDataAccessService.get_by_guid") | ||
def test_create_transfer_event_operation_using_the_same_operator(cls, mock_get_by_guid, mock_validate_no_overlap): | ||
cas_analyst = baker.make_recipe("utils.cas_analyst") | ||
payload_with_same_from_operator_and_to_operator = cls._get_transfer_event_payload_for_operation() | ||
payload_with_same_from_operator_and_to_operator.to_operator = ( | ||
payload_with_same_from_operator_and_to_operator.from_operator | ||
) | ||
|
||
mock_user = MagicMock() | ||
mock_user.is_cas_analyst.return_value = True | ||
mock_get_by_guid.return_value = cas_analyst | ||
mock_validate_no_overlap.return_value = None | ||
|
||
with pytest.raises(Exception, match="Operations cannot be transferred within the same operator."): | ||
TransferEventService.create_transfer_event( | ||
cas_analyst.user_guid, payload_with_same_from_operator_and_to_operator | ||
) | ||
|
||
@classmethod | ||
@patch("service.transfer_event_service.TransferEventService.validate_no_overlapping_transfer_events") | ||
@patch("service.data_access_service.user_service.UserDataAccessService.get_by_guid") | ||
|
@@ -188,6 +207,22 @@ def test_create_transfer_event_facility_missing_required_fields(cls, mock_get_by | |
): | ||
TransferEventService.create_transfer_event(cas_analyst.user_guid, payload_without_to_operation) | ||
|
||
@classmethod | ||
@patch("service.transfer_event_service.TransferEventService.validate_no_overlapping_transfer_events") | ||
@patch("service.data_access_service.user_service.UserDataAccessService.get_by_guid") | ||
def test_create_transfer_event_facility_between_the_same_operation(cls, mock_get_by_guid, mock_validate_no_overlap): | ||
cas_analyst = baker.make_recipe("utils.cas_analyst") | ||
payload_with_same_from_and_to_operation = cls._get_transfer_event_payload_for_facility() | ||
payload_with_same_from_and_to_operation.to_operation = payload_with_same_from_and_to_operation.from_operation | ||
|
||
mock_user = MagicMock() | ||
mock_user.is_cas_analyst.return_value = True | ||
mock_get_by_guid.return_value = cas_analyst | ||
mock_validate_no_overlap.return_value = None | ||
|
||
with pytest.raises(Exception, match="Facilities cannot be transferred within the same operation."): | ||
TransferEventService.create_transfer_event(cas_analyst.user_guid, payload_with_same_from_and_to_operation) | ||
|
||
@classmethod | ||
@patch("service.transfer_event_service.TransferEventService.validate_no_overlapping_transfer_events") | ||
@patch("service.data_access_service.user_service.UserDataAccessService.get_by_guid") | ||
|
@@ -448,8 +483,10 @@ def test_process_facilities_transfer( | |
@patch( | ||
"service.transfer_event_service.OperationDesignatedOperatorTimelineDataAccessService.create_operation_designated_operator_timeline" | ||
) | ||
@patch("service.operation_service_v2.OperationServiceV2.update_operator") | ||
def test_process_operation_transfer( | ||
self, | ||
mock_update_operator, | ||
mock_create_timeline, | ||
mock_set_timeline, | ||
mock_get_current_timeline, | ||
|
@@ -483,6 +520,7 @@ def test_process_operation_transfer( | |
mock_get_current_timeline.return_value = None | ||
mock_set_timeline.reset_mock() # Reset mock for the next call | ||
mock_create_timeline.reset_mock() # Reset mock for the next call | ||
mock_update_operator.reset_mock() # Reset mock for the next call | ||
|
||
# Call the method under test for the second scenario (no existing timeline) | ||
TransferEventService._process_operation_transfer(transfer_event, user_guid) | ||
|
@@ -500,3 +538,8 @@ def test_process_operation_transfer( | |
|
||
# Verify that set_timeline_status_and_end_date was not called, since the timeline did not exist | ||
mock_set_timeline.assert_not_called() | ||
mock_update_operator.assert_called_once_with( | ||
user_guid, | ||
transfer_event.operation, | ||
transfer_event.to_operator.id, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the docs