@@ -37,23 +37,17 @@ def client(mock_driver) -> Client:
3737 return Client (mock_driver )
3838
3939
40- @patch ("datetime.datetime" )
41- def test_insert_with_only_args (mock_datetime , client , mock_exec ):
42- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
43-
40+ def test_insert_with_only_args (client , mock_exec ):
4441 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
4542 mock_exec .job_insert .return_value = "job_row"
4643
47- result = client .insert (SimpleArgs ())
44+ insert_res = client .insert (SimpleArgs ())
4845
4946 mock_exec .job_insert .assert_called_once ()
50- assert result .job == "job_row"
47+ assert insert_res .job == "job_row"
5148
5249
53- @patch ("datetime.datetime" )
54- def test_insert_tx (mock_datetime , mock_driver , client ):
55- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
56-
50+ def test_insert_tx (mock_driver , client ):
5751 mock_exec = MagicMock (spec = ExecutorProtocol )
5852 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
5953 mock_exec .job_insert .return_value = "job_row"
@@ -66,47 +60,38 @@ def mock_unwrap_executor(tx: sqlalchemy.Transaction):
6660
6761 mock_driver .unwrap_executor .side_effect = mock_unwrap_executor
6862
69- result = client .insert_tx (mock_tx , SimpleArgs ())
63+ insert_res = client .insert_tx (mock_tx , SimpleArgs ())
7064
7165 mock_exec .job_insert .assert_called_once ()
72- assert result .job == "job_row"
73-
66+ assert insert_res .job == "job_row"
7467
75- @patch ("datetime.datetime" )
76- def test_insert_with_opts (mock_datetime , client , mock_exec ):
77- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
7868
79- args = SimpleArgs ()
80- insert_opts = InsertOpts (queue = "high_priority" , unique_opts = None )
69+ def test_insert_with_opts ( client , mock_exec ):
70+ insert_opts = InsertOpts (queue = "high_priority" )
8171
8272 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
8373 mock_exec .job_insert .return_value = "job_row"
8474
85- result = client .insert (args , insert_opts = insert_opts )
75+ insert_res = client .insert (SimpleArgs () , insert_opts = insert_opts )
8676
8777 mock_exec .job_insert .assert_called_once ()
88- assert result .job == "job_row"
78+ assert insert_res .job == "job_row"
8979
9080 # Check that the InsertOpts were correctly passed to make_insert_params
9181 call_args = mock_exec .job_insert .call_args [0 ][0 ]
9282 assert call_args .queue == "high_priority"
9383
9484
95- @patch ("datetime.datetime" )
96- def test_insert_with_unique_opts_by_args (mock_datetime , client , mock_exec ):
97- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
98-
99- args = SimpleArgs ()
100- unique_opts = UniqueOpts (by_args = True )
101- insert_opts = InsertOpts (unique_opts = unique_opts )
85+ def test_insert_with_unique_opts_by_args (client , mock_exec ):
86+ insert_opts = InsertOpts (unique_opts = UniqueOpts (by_args = True ))
10287
10388 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
10489 mock_exec .job_insert .return_value = "job_row"
10590
106- result = client .insert (args , insert_opts = insert_opts )
91+ insert_res = client .insert (SimpleArgs () , insert_opts = insert_opts )
10792
10893 mock_exec .job_insert .assert_called_once ()
109- assert result .job == "job_row"
94+ assert insert_res .job == "job_row"
11095
11196 # Check that the UniqueOpts were correctly processed
11297 call_args = mock_exec .job_insert .call_args [0 ][0 ]
@@ -117,59 +102,47 @@ def test_insert_with_unique_opts_by_args(mock_datetime, client, mock_exec):
117102def test_insert_with_unique_opts_by_period (mock_datetime , client , mock_exec ):
118103 mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
119104
120- args = SimpleArgs ()
121- unique_opts = UniqueOpts (by_period = 900 )
122- insert_opts = InsertOpts (unique_opts = unique_opts )
105+ insert_opts = InsertOpts (unique_opts = UniqueOpts (by_period = 900 ))
123106
124107 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
125108 mock_exec .job_insert .return_value = "job_row"
126109
127- result = client .insert (args , insert_opts = insert_opts )
110+ insert_res = client .insert (SimpleArgs () , insert_opts = insert_opts )
128111
129112 mock_exec .job_insert .assert_called_once ()
130- assert result .job == "job_row"
113+ assert insert_res .job == "job_row"
131114
132115 # Check that the UniqueOpts were correctly processed
133116 call_args = mock_exec .job_insert .call_args [0 ][0 ]
134117 assert call_args .kind == "simple"
135118
136119
137- @patch ("datetime.datetime" )
138- def test_insert_with_unique_opts_by_queue (mock_datetime , client , mock_exec ):
139- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
140-
141- args = SimpleArgs ()
142- unique_opts = UniqueOpts (by_queue = True )
143- insert_opts = InsertOpts (unique_opts = unique_opts )
120+ def test_insert_with_unique_opts_by_queue (client , mock_exec ):
121+ insert_opts = InsertOpts (unique_opts = UniqueOpts (by_queue = True ))
144122
145123 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
146124 mock_exec .job_insert .return_value = "job_row"
147125
148- result = client .insert (args , insert_opts = insert_opts )
126+ insert_res = client .insert (SimpleArgs () , insert_opts = insert_opts )
149127
150128 mock_exec .job_insert .assert_called_once ()
151- assert result .job == "job_row"
129+ assert insert_res .job == "job_row"
152130
153131 # Check that the UniqueOpts were correctly processed
154132 call_args = mock_exec .job_insert .call_args [0 ][0 ]
155133 assert call_args .kind == "simple"
156134
157135
158- @patch ("datetime.datetime" )
159- def test_insert_with_unique_opts_by_state (mock_datetime , client , mock_exec ):
160- mock_datetime .now .return_value = datetime (2024 , 6 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
161-
162- args = SimpleArgs ()
163- unique_opts = UniqueOpts (by_state = ["available" , "running" ])
164- insert_opts = InsertOpts (unique_opts = unique_opts )
136+ def test_insert_with_unique_opts_by_state (client , mock_exec ):
137+ insert_opts = InsertOpts (unique_opts = UniqueOpts (by_state = ["available" , "running" ]))
165138
166139 mock_exec .job_get_by_kind_and_unique_properties .return_value = None
167140 mock_exec .job_insert .return_value = "job_row"
168141
169- result = client .insert (args , insert_opts = insert_opts )
142+ insert_res = client .insert (SimpleArgs () , insert_opts = insert_opts )
170143
171144 mock_exec .job_insert .assert_called_once ()
172- assert result .job == "job_row"
145+ assert insert_res .job == "job_row"
173146
174147 # Check that the UniqueOpts were correctly processed
175148 call_args = mock_exec .job_insert .call_args [0 ][0 ]
0 commit comments