Skip to content

Commit a35263c

Browse files
committed
Update tests
1 parent 5ed8e47 commit a35263c

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

recipes/em-tomo-align.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"ispyb_command": "insert_tomogram",
77
"program_id": "{appid}",
88
"store_result": "ispyb_tomogram_id",
9-
"x_location": "{x_location}",
10-
"y_location": "{y_location}",
9+
"pixel_location_x": "{x_location}",
10+
"pixel_location_y": "{y_location}",
1111
"grid_square_id": "{search_map_id}"
1212
},
1313
"queue": "ispyb_connector",

tests/util/test_ispyb_commands.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
from datetime import datetime
44
from unittest import mock
55

6+
from sqlalchemy.exc import SQLAlchemyError
7+
68
from cryoemservices.util import ispyb_commands
79

810

11+
def raise_sql_error(mock_call):
12+
raise SQLAlchemyError("Mock error")
13+
14+
915
@mock.patch("cryoemservices.util.ispyb_commands.models")
1016
def test_insert_movie_id_notime(mock_models):
1117
def mock_movie_parameters(p):
@@ -699,6 +705,9 @@ def mock_tomogram_parameters(p):
699705
"proj_xy": "/path/to/xy",
700706
"proj_xz": "/path/to/xz",
701707
"alignment_quality": 0.2,
708+
"grid_square_id": 12345,
709+
"pixel_location_x": 200,
710+
"pixel_location_y": 400,
702711
}
703712
return tomogram_parameters[p]
704713

@@ -738,6 +747,9 @@ def mock_tomogram_parameters(p):
738747
projXY="/path/to/xy",
739748
projXZ="/path/to/xz",
740749
globalAlignmentQuality=0.2,
750+
gridSquareId=12345,
751+
pixelLocationX=200,
752+
pixelLocationY=400,
741753
)
742754
mock_session.add.assert_called()
743755
mock_session.commit.assert_called()
@@ -767,6 +779,9 @@ def mock_tomogram_parameters(p):
767779
"proj_xy": "/path/to/xy",
768780
"proj_xz": "/path/to/xz",
769781
"alignment_quality": 0.2,
782+
"grid_square_id": 12345,
783+
"pixel_location_x": 200,
784+
"pixel_location_y": 400,
770785
}
771786
return tomogram_parameters[p]
772787

@@ -807,12 +822,30 @@ def mock_tomogram_parameters(p):
807822
"projXY": "/path/to/xy",
808823
"projXZ": "/path/to/xz",
809824
"globalAlignmentQuality": 0.2,
825+
"gridSquareId": 12345,
826+
"pixelLocationX": 200,
827+
"pixelLocationY": 400,
810828
}
811829
)
812830
mock_session.add.assert_not_called()
813831
mock_session.commit.assert_called()
814832

815833

834+
def test_insert_tomogram_failure():
835+
def mock_tomogram_parameters(p):
836+
return None
837+
838+
# Mock which returns an existing object
839+
mock_session = mock.MagicMock()
840+
mock_session.add.side_effect = raise_sql_error
841+
842+
return_value = ispyb_commands.insert_tomogram(
843+
{}, mock_tomogram_parameters, mock_session
844+
)
845+
assert return_value is False
846+
mock_session.add.assert_called()
847+
848+
816849
@mock.patch("cryoemservices.util.ispyb_commands.models")
817850
def test_insert_processed_tomogram(mock_models):
818851
def mock_tomogram_parameters(p):
@@ -839,6 +872,21 @@ def mock_tomogram_parameters(p):
839872
mock_session.commit.assert_called()
840873

841874

875+
def test_insert_processed_tomogram_failure():
876+
def mock_tomogram_parameters(p):
877+
return None
878+
879+
# Mock which returns an existing object
880+
mock_session = mock.MagicMock()
881+
mock_session.add.side_effect = raise_sql_error
882+
883+
return_value = ispyb_commands.insert_processed_tomogram(
884+
{}, mock_tomogram_parameters, mock_session
885+
)
886+
assert return_value is False
887+
mock_session.add.assert_called()
888+
889+
842890
@mock.patch("cryoemservices.util.ispyb_commands.models")
843891
def test_insert_tilts_has_movie(mock_models):
844892
def mock_tilt_parameters(p):

0 commit comments

Comments
 (0)