2424 Role ,
2525 User ,
2626)
27+ from galaxy .model .orm .now import now
2728from galaxy .schema .notifications import (
2829 BroadcastNotificationContent ,
2930 BroadcastNotificationCreateRequest ,
@@ -88,7 +89,7 @@ def _send_message_notification_to_users(self, users: list[User], notification: O
8889 return created_notification , notifications_sent
8990
9091 def _has_expired (self , expiration_time : Optional [datetime ]) -> bool :
91- return expiration_time < datetime . utcnow () if expiration_time else False
92+ return expiration_time < now () if expiration_time else False
9293
9394 def _assert_notification_expected (self , actual_notification : Any , expected_notification : dict [str , Any ]):
9495 assert actual_notification
@@ -146,13 +147,13 @@ def test_get_broadcasted_notification(self):
146147 assert actual_notification .id == created_notification .id
147148
148149 def test_get_all_broadcasted_notifications (self ):
149- now = datetime . utcnow ()
150- next_week = now + timedelta (days = 7 )
151- next_month = now + timedelta (days = 30 )
150+ current_time = now ()
151+ next_week = current_time + timedelta (days = 7 )
152+ next_month = current_time + timedelta (days = 30 )
152153
153154 notification_data = self ._default_broadcast_notification_data ()
154155 notification_data ["content" ]["subject" ] = "Recent Notification"
155- notification_data ["publication_time" ] = now
156+ notification_data ["publication_time" ] = current_time
156157 self ._send_broadcast_notification (notification_data )
157158
158159 notification_data = self ._default_broadcast_notification_data ()
@@ -179,18 +180,18 @@ def test_get_all_broadcasted_notifications(self):
179180 assert notifications [0 ].content ["subject" ] == "Scheduled Next Month Notification"
180181
181182 def test_update_broadcasted_notification (self ):
182- next_month = datetime . utcnow () + timedelta (days = 30 )
183+ next_month = now () + timedelta (days = 30 )
183184 notification_data = self ._default_broadcast_notification_data ()
184185 notification_data ["content" ]["subject" ] = "Old Scheduled Notification"
185186 notification_data ["publication_time" ] = next_month
186187 actual_notification = self ._send_broadcast_notification (notification_data )
187188
188- now = datetime . utcnow ()
189+ current_time = now ()
189190 expected_content = BroadcastNotificationContent (subject = "Updated Notification" , message = "Updated Message" )
190191 update_request = NotificationBroadcastUpdateRequest (
191192 source = "updated_source" ,
192193 variant = NotificationVariant .warning ,
193- publication_time = now ,
194+ publication_time = current_time ,
194195 content = expected_content ,
195196 )
196197 updated_count = self .notification_manager .update_broadcasted_notification (
@@ -206,7 +207,7 @@ def test_update_broadcasted_notification(self):
206207 assert content ["message" ] == expected_content .message
207208
208209 def test_cleanup_expired_broadcast_notifications (self ):
209- one_hour_ago = datetime . utcnow () - timedelta (hours = 1 )
210+ one_hour_ago = now () - timedelta (hours = 1 )
210211 notification_data = self ._default_broadcast_notification_data ()
211212 notification_data ["expiration_time" ] = one_hour_ago
212213 actual_notification = self ._send_broadcast_notification (notification_data )
@@ -290,7 +291,7 @@ def test_update_user_notifications(self):
290291
291292 def test_scheduled_notifications (self ):
292293 user = self ._create_test_user ()
293- tomorrow = datetime . utcnow () + timedelta (hours = 24 )
294+ tomorrow = now () + timedelta (hours = 24 )
294295 expected_notification = self ._default_test_notification_data ()
295296 expected_notification ["source" ] = "test_scheduled"
296297 expected_notification ["publication_time" ] = tomorrow
@@ -347,8 +348,10 @@ def test_update_user_notification_preferences(self):
347348
348349 def test_cleanup_expired_notifications (self ):
349350 user = self ._create_test_user ()
350- now = datetime .utcnow ()
351- notification , _ = self ._send_message_notification_to_users ([user ], notification = {"expiration_time" : now })
351+ current_time = now ()
352+ notification , _ = self ._send_message_notification_to_users (
353+ [user ], notification = {"expiration_time" : current_time }
354+ )
352355 user_notification = self .notification_manager .get_user_notification (user , notification .id , active_only = False )
353356 assert user_notification
354357 assert self ._has_expired (user_notification .expiration_time ) is True
0 commit comments