1- from datetime import datetime
1+ from datetime import datetime , timedelta
22from io import StringIO
33from unittest .mock import Mock
44
@@ -48,15 +48,15 @@ def test_with_leases_columns(self):
4848 add_display_columns (table , options )
4949
5050 columns = [col .header for col in table .columns ]
51- assert columns == ["NAME" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "START TIME " ]
51+ assert columns == ["NAME" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "EXPECTED RELEASE " ]
5252
5353 def test_with_all_columns (self ):
5454 table = Table ()
5555 options = WithOptions (show_online = True , show_leases = True )
5656 add_display_columns (table , options )
5757
5858 columns = [col .header for col in table .columns ]
59- assert columns == ["NAME" , "ONLINE" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "START TIME " ]
59+ assert columns == ["NAME" , "ONLINE" , "LABELS" , "LEASED BY" , "LEASE STATUS" , "EXPECTED RELEASE " ]
6060
6161
6262class TestAddExporterRow :
@@ -91,7 +91,7 @@ def test_row_with_lease_info(self):
9191 add_exporter_row (table , exporter , options , lease_info )
9292
9393 assert len (table .rows ) == 1
94- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, START TIME
94+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
9595
9696 def test_row_with_lease_info_available (self ):
9797 table = Table ()
@@ -115,7 +115,7 @@ def test_row_with_all_options(self):
115115 add_exporter_row (table , exporter , options , lease_info )
116116
117117 assert len (table .rows ) == 1
118- assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, START TIME
118+ assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
119119
120120
121121class TestExporterList :
@@ -124,6 +124,7 @@ def create_test_lease(self, client="test-client", status="Active"):
124124 lease .client = client
125125 lease .get_status .return_value = status
126126 lease .effective_begin_time = datetime (2023 , 1 , 1 , 10 , 0 , 0 )
127+ lease .effective_duration = timedelta (hours = 1 )
127128 return lease
128129
129130 def test_exporter_without_lease (self ):
@@ -175,7 +176,7 @@ def test_exporter_with_lease_display(self):
175176 exporter .rich_add_rows (table , options )
176177
177178 assert len (table .rows ) == 1
178- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, START TIME
179+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
179180
180181 # Test actual table content by rendering it
181182 console = Console (file = StringIO (), width = 120 )
@@ -187,7 +188,7 @@ def test_exporter_with_lease_display(self):
187188 assert "type=device" in output
188189 assert "test-client" in output
189190 assert "Active" in output
190- assert "2023-01-01 10 :00:00" in output
191+ assert "2023-01-01 11 :00:00" in output # Expected release: begin_time (10:00:00) + duration (1h)
191192
192193 def test_exporter_without_lease_but_show_leases (self ):
193194 exporter = Exporter (
@@ -203,7 +204,7 @@ def test_exporter_without_lease_but_show_leases(self):
203204 exporter .rich_add_rows (table , options )
204205
205206 assert len (table .rows ) == 1
206- assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, START TIME
207+ assert len (table .columns ) == 5 # NAME, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
207208
208209 # Test actual table content by rendering it
209210 console = Console (file = StringIO (), width = 120 )
@@ -285,7 +286,7 @@ def test_exporter_all_features_display(self):
285286 exporter_offline_no_lease .rich_add_rows (table , options )
286287
287288 assert len (table .rows ) == 2
288- assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, START TIME
289+ assert len (table .columns ) == 6 # NAME, ONLINE, LABELS, LEASED BY, LEASE STATUS, EXPECTED RELEASE
289290
290291 # Test actual table content by rendering it
291292 console = Console (file = StringIO (), width = 150 )
@@ -302,7 +303,7 @@ def test_exporter_all_features_display(self):
302303 assert "full-test-client" in output # Lease client
303304 assert "Active" in output # Lease status
304305 assert "Available" in output # Available status for no lease
305- assert "2023-01-01 10 :00:00" in output # Lease start time
306+ assert "2023-01-01 11 :00:00" in output # Expected release time (begin_time + duration)
306307
307308 def test_exporter_lease_info_extraction (self ):
308309 """Test that lease information is correctly extracted from lease objects"""
@@ -325,10 +326,13 @@ def test_exporter_lease_info_extraction(self):
325326 if options .show_leases and exporter .lease :
326327 lease_client = exporter .lease .client
327328 lease_status = exporter .lease .get_status ()
328- start_time = exporter .lease .effective_begin_time .strftime ("%Y-%m-%d %H:%M:%S" )
329- lease_info = (lease_client , lease_status , start_time )
329+ expected_release = ""
330+ if exporter .lease .effective_begin_time and exporter .lease .effective_duration :
331+ release_time = exporter .lease .effective_begin_time + exporter .lease .effective_duration
332+ expected_release = release_time .strftime ("%Y-%m-%d %H:%M:%S" )
333+ lease_info = (lease_client , lease_status , expected_release )
330334
331- assert lease_info == ("my-client" , "Expired" , "2023-01-01 10 :00:00" )
335+ assert lease_info == ("my-client" , "Expired" , "2023-01-01 11 :00:00" )
332336
333337 def test_exporter_no_lease_info_extraction (self ):
334338 """Test that default lease information is used when no lease exists"""
0 commit comments