@@ -566,14 +566,27 @@ def test_check_if_workspace_needs_to_be_terminated_returns_yes_is_dry_run_false(
566566 # 'terminateUnusedWorkspaces': 'Yes'
567567 # 'isDryRun': False
568568
569+ start_time = time .strftime ("%Y-%m" ) + '-01T00:00:00Z'
570+ end_time = time .strftime ("%Y-%m" ) + '-02T00:00:00Z'
569571 settings = {
570572 'region' : 'us-east-1' ,
571573 'hourlyLimits' : 10 ,
572574 'testEndOfMonth' : 'yes' ,
573575 'isDryRun' : False ,
574576 'startTime' : 1 ,
575577 'endTime' : 2 ,
576- 'terminateUnusedWorkspaces' : 'Yes'
578+ 'terminateUnusedWorkspaces' : 'Yes' ,
579+ 'dateTimeValues' : {
580+ "start_time_for_current_month" : '' ,
581+ "end_time_for_current_month" : '' ,
582+ "last_day_current_month" : '' ,
583+ "first_day_selected_month" : '' ,
584+ "start_time_selected_date" : start_time ,
585+ "end_time_selected_date" : end_time ,
586+ "current_month_last_day" : True ,
587+ "date_today" : '' ,
588+ "date_for_s3_key" : ''
589+ }
577590 }
578591 workspace_id = "123qwe123qwe"
579592 workspace_helper = workspaces_helper .WorkspacesHelper (session , settings )
@@ -652,6 +665,9 @@ def test_get_last_known_user_connection_timestamp_returns_resource_unavailable_f
652665
653666
654667def test_get_termination_status_returns_empty_string_for_terminate_workspaces_no (session ):
668+ start_time = time .strftime ("%Y-%m" ) + '-01T00:00:00Z'
669+ end_time = time .strftime ("%Y-%m" ) + '-02T00:00:00Z'
670+
655671 workspace_utils .TERMINATE_UNUSED_WORKSPACES = 'No'
656672 settings = {
657673 'region' : 'us-east-1' ,
@@ -660,7 +676,18 @@ def test_get_termination_status_returns_empty_string_for_terminate_workspaces_no
660676 'isDryRun' : True ,
661677 'startTime' : 1 ,
662678 'endTime' : 2 ,
663- 'TerminateUnusedWorkspaces' : 'No'
679+ 'TerminateUnusedWorkspaces' : 'No' ,
680+ 'dateTimeValues' : {
681+ "start_time_for_current_month" : '' ,
682+ "end_time_for_current_month" : '' ,
683+ "last_day_current_month" : '' ,
684+ "first_day_selected_month" : '' ,
685+ "start_time_selected_date" : start_time ,
686+ "end_time_selected_date" : end_time ,
687+ "current_month_last_day" : True ,
688+ "date_today" : '' ,
689+ "date_for_s3_key" : ''
690+ }
664691 }
665692 workspace_id = "123qwe123qwe"
666693 billable_time = 0
@@ -755,14 +782,27 @@ def test_get_termination_status_returns_dry_run_for_terminate_workspaces_dry_run
755782
756783
757784def test_get_termination_status_returns_empty_string_when_workspace_used (mocker , session ):
785+ start_time = time .strftime ("%Y-%m" ) + '-01T00:00:00Z'
786+ end_time = time .strftime ("%Y-%m" ) + '-02T00:00:00Z'
758787 settings = {
759788 'region' : 'us-east-1' ,
760789 'hourlyLimits' : 10 ,
761790 'testEndOfMonth' : 'yes' ,
762791 'isDryRun' : True ,
763792 'startTime' : 1 ,
764793 'endTime' : 2 ,
765- 'TerminateUnusedWorkspaces' : 'Dry Run'
794+ 'TerminateUnusedWorkspaces' : 'Dry Run' ,
795+ 'dateTimeValues' : {
796+ "start_time_for_current_month" : '' ,
797+ "end_time_for_current_month" : '' ,
798+ "last_day_current_month" : '' ,
799+ "first_day_selected_month" : '' ,
800+ "start_time_selected_date" : start_time ,
801+ "end_time_selected_date" : end_time ,
802+ "current_month_last_day" : True ,
803+ "date_today" : '' ,
804+ "date_for_s3_key" : ''
805+ }
766806 }
767807 workspace_id = "123qwe123qwe"
768808 billable_time = 0
@@ -784,14 +824,27 @@ def test_get_termination_status_returns_empty_string_when_workspace_used(mocker,
784824
785825
786826def test_get_termination_status_returns_empty_string_when_workspace_not_available_first_day (mocker , session ):
827+ start_time = time .strftime ("%Y-%m" ) + '-01T00:00:00Z'
828+ end_time = time .strftime ("%Y-%m" ) + '-02T00:00:00Z'
787829 settings = {
788830 'region' : 'us-east-1' ,
789831 'hourlyLimits' : 10 ,
790832 'testEndOfMonth' : True ,
791833 'isDryRun' : True ,
792834 'startTime' : 1 ,
793835 'endTime' : 2 ,
794- 'terminateUnusedWorkspaces' : 'Dry Run'
836+ 'terminateUnusedWorkspaces' : 'Dry Run' ,
837+ 'dateTimeValues' : {
838+ "start_time_for_current_month" : '' ,
839+ "end_time_for_current_month" : '' ,
840+ "last_day_current_month" : '' ,
841+ "first_day_selected_month" : '' ,
842+ "start_time_selected_date" : start_time ,
843+ "end_time_selected_date" : end_time ,
844+ "current_month_last_day" : True ,
845+ "date_today" : '' ,
846+ "date_for_s3_key" : ''
847+ }
795848 }
796849 workspace_id = "123qwe123qwe"
797850 billable_time = 0
@@ -1203,3 +1256,36 @@ def test_compare_usage_metrics_for_always_on_returns_no_change_for_end_of_month_
12031256 workspace_helper .modify_workspace_properties .return_value = '-N-'
12041257
12051258 assert workspace_helper .compare_usage_metrics_for_always_on ('ws-112d' , 10 , 85 , "ALWAYS_ON" ) == expected
1259+
1260+
1261+ def test_check_if_workspace_needs_to_be_terminated_returns_empty_string_for_last_day_month_false (session ):
1262+ # 'terminateUnusedWorkspaces': 'Dry Run'
1263+ # 'isDryRun': True
1264+
1265+ start_time = time .strftime ("%Y-%m" ) + '-01T00:00:00Z'
1266+ end_time = time .strftime ("%Y-%m" ) + '-02T00:00:00Z'
1267+ settings = {
1268+ 'region' : 'us-east-1' ,
1269+ 'hourlyLimits' : 10 ,
1270+ 'testEndOfMonth' : 'yes' ,
1271+ 'isDryRun' : False ,
1272+ 'startTime' : 1 ,
1273+ 'endTime' : 2 ,
1274+ 'terminateUnusedWorkspaces' : 'Yes' ,
1275+ 'dateTimeValues' : {
1276+ "start_time_for_current_month" : '' ,
1277+ "end_time_for_current_month" : '' ,
1278+ "last_day_current_month" : '' ,
1279+ "first_day_selected_month" : '' ,
1280+ "start_time_selected_date" : start_time ,
1281+ "end_time_selected_date" : end_time ,
1282+ "current_month_last_day" : False ,
1283+ "date_today" : '' ,
1284+ "date_for_s3_key" : ''
1285+ }
1286+ }
1287+ workspace_id = "123qwe123qwe"
1288+ workspace_helper = workspaces_helper .WorkspacesHelper (session , settings )
1289+ result = workspace_helper .check_if_workspace_needs_to_be_terminated (workspace_id )
1290+ assert result == ''
1291+
0 commit comments