@@ -115,8 +115,8 @@ def ws_record(ws_billing_data, ws_metrics):
115115 billing_data = ws_billing_data ,
116116 performance_metrics = ws_metrics ,
117117 report_date = "test-report-date" ,
118- last_reported_metric_period = "test-last-period " ,
119- last_known_user_connection = "test-last-connection " ,
118+ last_reported_metric_period = "2024-09-03T00:00:00Z " ,
119+ last_known_user_connection = "2024-09-02T00:00:00Z " ,
120120 tags = "[{'key1': 'tag1'}, {'key2': 'tag2'}]" ,
121121 )
122122
@@ -235,7 +235,9 @@ def test_get_end_of_month(session):
235235@unittest .mock .patch ("boto3.session.Session" )
236236@unittest .mock .patch (DirectoryReader .__module__ + ".upload_report" )
237237@unittest .mock .patch (DirectoryReader .__module__ + ".WorkspacesHelper" )
238+ @unittest .mock .patch (DirectoryReader .__module__ + ".UsageTableDAO" )
238239def test_process_directory_with_multiple_graphics_workspaces (
240+ mock_usage_table_dao ,
239241 MockWorkspacesHelper ,
240242 mock_session ,
241243 stack_parameters ,
@@ -248,6 +250,7 @@ def test_process_directory_with_multiple_graphics_workspaces(
248250 "WorkspaceId" : "ws-graphics1" ,
249251 "DirectoryId" : "foobarbazqux" ,
250252 "UserName" : "graphics_user" ,
253+ "ComputerName" : "cpu1" ,
251254 "State" : "AVAILABLE" ,
252255 "WorkspaceProperties" : {
253256 "RunningMode" : "AUTO_STOP" ,
@@ -258,6 +261,7 @@ def test_process_directory_with_multiple_graphics_workspaces(
258261 "WorkspaceId" : "ws-graphicsPro1" ,
259262 "DirectoryId" : "foobarbazqux" ,
260263 "UserName" : "graphicsPro_user" ,
264+ "ComputerName" : "cpu2" ,
261265 "State" : "AVAILABLE" ,
262266 "WorkspaceProperties" : {
263267 "RunningMode" : "AUTO_STOP" ,
@@ -268,26 +272,45 @@ def test_process_directory_with_multiple_graphics_workspaces(
268272 MockWorkspacesHelper .return_value .get_workspaces_for_directory .return_value = (
269273 graphics_workspaces
270274 )
275+ MockWorkspacesHelper .return_value .get_hourly_threshold_for_bundle_type .return_value = Decimal (
276+ "100"
277+ )
271278 ws_records = [copy .deepcopy (ws_record ), copy .deepcopy (ws_record )]
272279 for idx , record in enumerate (ws_records ):
273280 record .description = ws_description (
274281 ** {
282+ "username" : graphics_workspaces [idx ]["UserName" ],
283+ "directory_id" : graphics_workspaces [idx ]["DirectoryId" ],
275284 "bundle_type" : graphics_workspaces [idx ]["WorkspaceProperties" ][
276285 "ComputeTypeName"
277286 ],
287+ "initial_mode" : graphics_workspaces [idx ]["WorkspaceProperties" ][
288+ "RunningMode"
289+ ],
278290 "workspace_id" : graphics_workspaces [idx ]["WorkspaceId" ],
291+ "computer_name" : graphics_workspaces [idx ]["ComputerName" ],
279292 }
280293 )
281-
282- mock_session .client .return_value .get_item .return_value = {}
294+ mock_session .client .return_value .get_caller_identity .return_value = {
295+ "Account" : ws_record .description .account
296+ }
283297 mock_process_workspace = MockWorkspacesHelper .return_value .process_workspace
284298 mock_process_workspace .side_effect = ws_records
285299 region = "us-east-1"
300+ mock_usage_table_dao .return_value .get_workspace_ddb_item .side_effect = [
301+ ws_records [0 ].description ,
302+ ws_records [1 ].description ,
303+ ]
286304 directory_reader = DirectoryReader (mock_session , region )
287305 result = directory_reader .process_directory (
288306 stack_parameters , directory_parameters , dashboard_metrics
289307 )
290- mock_process_workspace .has_calls ([(ws_records [0 ], None ), (ws_records [1 ], None )])
308+ mock_process_workspace .assert_has_calls (
309+ [
310+ unittest .mock .call (ws_records [0 ].description , None , dashboard_metrics ),
311+ unittest .mock .call (ws_records [1 ].description , None , dashboard_metrics ),
312+ ]
313+ )
291314 assert len (mock_process_workspace .call_args_list ) == 2
292315 assert result [0 ] == 2
293316 assert result [1 ][0 ]["bundleType" ] == "GRAPHICS_G4DN"
0 commit comments