Skip to content

Commit cd0b129

Browse files
committed
Fix test naming for default_account_valid_days and default_account_expire and
adjust test without start_time to be more robust against rounding issues.
1 parent 03fb945 commit cd0b129

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

tests/test_mig_shared_accountstate.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,35 @@ def before_each(self):
8686
configuration.oidc_valid_days = 30
8787
configuration.generic_valid_days = 14
8888

89-
def test_returns_cert_valid_days_for_certificate_auth(self):
89+
def test_default_account_valid_days_auth_cert(self):
9090
"""Test that cert_valid_days is returned for AUTH_CERTIFICATE."""
9191
configuration = self.configuration
9292

9393
result = default_account_valid_days(configuration, AUTH_CERTIFICATE)
9494
self.assertEqual(result, 365)
9595

96-
def test_returns_oid_valid_days_for_openid_v2_auth(self):
96+
def test_default_account_valid_days_auth_oid(self):
9797
"""Test that oid_valid_days is returned for AUTH_OPENID_V2."""
9898
configuration = self.configuration
9999

100100
result = default_account_valid_days(configuration, AUTH_OPENID_V2)
101101
self.assertEqual(result, 30)
102102

103-
def test_returns_oidc_valid_days_for_openid_connect_auth(self):
103+
def test_default_account_valid_days_auth_oidc(self):
104104
"""Test that oidc_valid_days is returned for AUTH_OPENID_CONNECT."""
105105
configuration = self.configuration
106106

107107
result = default_account_valid_days(configuration, AUTH_OPENID_CONNECT)
108108
self.assertEqual(result, 30)
109109

110-
def test_returns_generic_valid_days_for_generic_auth(self):
110+
def test_default_account_valid_days_auth_generic(self):
111111
"""Test that generic_valid_days is returned for AUTH_GENERIC."""
112112
configuration = self.configuration
113113

114114
result = default_account_valid_days(configuration, AUTH_GENERIC)
115115
self.assertEqual(result, 14)
116116

117-
def test_returns_generic_valid_days_for_unknown_auth_type(self):
117+
def test_default_account_valid_days_auth_unknown(self):
118118
"""Test that generic_valid_days is fallback for unknown auth type."""
119119
configuration = self.configuration
120120

@@ -135,8 +135,8 @@ def before_each(self):
135135
configuration.oidc_valid_days = 30
136136
configuration.generic_valid_days = 14
137137

138-
def test_calculates_expire_from_valid_days(self):
139-
"""Test that expire is calculated correctly from valid days."""
138+
def test_default_account_expire_for_auth_cert(self):
139+
"""Test expire calculation for AUTH_CERTIFICATE."""
140140
configuration = self.configuration
141141

142142
start_time = time.time()
@@ -146,7 +146,7 @@ def test_calculates_expire_from_valid_days(self):
146146
expected = int(start_time + 365 * 24 * 60 * 60)
147147
self.assertEqual(result, expected)
148148

149-
def test_calculates_expire_for_openid_v2(self):
149+
def test_default_account_expire_for_auth_oid(self):
150150
"""Test expire calculation for AUTH_OPENID_V2."""
151151
configuration = self.configuration
152152

@@ -157,7 +157,7 @@ def test_calculates_expire_for_openid_v2(self):
157157
expected = int(start_time + 30 * 24 * 60 * 60)
158158
self.assertEqual(result, expected)
159159

160-
def test_calculates_expire_for_openid_connect(self):
160+
def test_default_account_expire_for_auth_oidc(self):
161161
"""Test expire calculation for AUTH_OPENID_CONNECT."""
162162
configuration = self.configuration
163163

@@ -168,7 +168,7 @@ def test_calculates_expire_for_openid_connect(self):
168168
expected = int(start_time + 30 * 24 * 60 * 60)
169169
self.assertEqual(result, expected)
170170

171-
def test_calculates_expire_for_generic_auth(self):
171+
def test_default_account_expire_for_auth_generic(self):
172172
"""Test expire calculation for AUTH_GENERIC."""
173173
configuration = self.configuration
174174

@@ -179,17 +179,19 @@ def test_calculates_expire_for_generic_auth(self):
179179
expected = int(start_time + 14 * 24 * 60 * 60)
180180
self.assertEqual(result, expected)
181181

182-
def test_uses_current_time_if_start_time_not_provided(self):
182+
def test_default_account_expire_without_start_time(self):
183183
"""Test that current time is used when start_time is not provided."""
184184
configuration = self.configuration
185185

186186
before = int(time.time())
187187
result = default_account_expire(configuration, AUTH_CERTIFICATE)
188188
after = int(time.time())
189189

190-
# Result should be between before + 365 days and after + 365 days
191-
min_expected = before + 365 * 24 * 60 * 60
190+
# Result should be between before + 364 days and after + 365 days
191+
min_expected = before + 364 * 24 * 60 * 60
192192
max_expected = after + 365 * 24 * 60 * 60
193+
print("DEBUG: before %s, result %s , after %s" %
194+
(min_expected, result, max_expected))
193195
self.assertTrue(min_expected <= result <= max_expected)
194196

195197

0 commit comments

Comments
 (0)