99Unit tests for the record helper module
1010"""
1111
12+ import socket
1213from unittest import TestCase , mock
1314import model .database .records as records
1415
@@ -32,9 +33,8 @@ def test_create_reduction_record_starts_db(db_layer):
3233 db_layer .start_database .return_value .data_model \
3334 .ReductionRun .assert_called_once ()
3435
35- @mock .patch ("model.database.access" )
36- @mock .patch ("datetime.datetime" )
37- def test_create_reduction_record_forwards_correctly (self , datetime_patch , db_layer ):
36+ @mock .patch ("model.database.records.timezone" )
37+ def test_create_reduction_record_forwards_correctly (self , timezone_mock ):
3838 """
3939 Test: Reduction Record uses args correctly.
4040 Any fields which are hard-coded are mocked with ANY to prevent
@@ -50,22 +50,23 @@ def test_create_reduction_record_forwards_correctly(self, datetime_patch, db_lay
5050 mock_script_text = mock .NonCallableMock ()
5151 mock_status = mock .NonCallableMock ()
5252
53- returned = records .create_reduction_run_record (experiment = mock_experiment ,
54- instrument = mock_inst ,
55- message = mock_msg ,
56- run_version = mock_run_version ,
57- script_text = mock_script_text ,
58- status = mock_status )
53+ with mock .patch ("model.database" ) as db_layer :
54+ returned = records .create_reduction_run_record (experiment = mock_experiment ,
55+ instrument = mock_inst ,
56+ message = mock_msg ,
57+ run_version = mock_run_version ,
58+ script_text = mock_script_text ,
59+ status = mock_status )
5960
60- mock_record_orm = db_layer .start_database .return_value .data_model
61+ mock_record_orm = db_layer . access .start_database .return_value .data_model
6162
6263 self .assertEqual (mock_record_orm .ReductionRun .return_value , returned )
6364
6465 mock_record_orm .ReductionRun .assert_called_once_with (
6566 run_number = mock_msg .run_number ,
6667 run_version = mock_run_version ,
67- created = datetime_patch . utcnow .return_value ,
68- last_updated = datetime_patch . utcnow .return_value ,
68+ created = timezone_mock . now .return_value ,
69+ last_updated = timezone_mock . now .return_value ,
6970 experiment = mock_experiment ,
7071 instrument = mock_inst ,
7172 status_id = mock_status .id ,
@@ -75,4 +76,5 @@ def test_create_reduction_record_forwards_correctly(self, datetime_patch, db_lay
7576 run_description = mock .ANY ,
7677 hidden_in_failviewer = mock .ANY ,
7778 admin_log = mock .ANY ,
78- reduction_log = mock .ANY )
79+ reduction_log = mock .ANY ,
80+ reduction_host = socket .getfqdn ())
0 commit comments