Skip to content

Commit e17f964

Browse files
committed
Fix number of times validation is called
1 parent 5e09991 commit e17f964

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

functions/host-info/test_main.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def test_on_post_success(self, mock_format_error, mock_validate_host_id):
4242
self.assertEqual(response.code, 200)
4343
self.assertEqual(response.body["host"], "valid-host-123")
4444

45-
# Verify validation was called with correct host_id
46-
mock_validate_host_id.assert_called_once_with("valid-host-123")
45+
# Verify validation was called twice (once for logging, once for condition)
46+
self.assertEqual(mock_validate_host_id.call_count, 2)
47+
mock_validate_host_id.assert_called_with("valid-host-123")
4748

4849
# Verify logger was called
4950
self.assertEqual(mock_logger.info.call_count, 2)
@@ -77,8 +78,9 @@ def test_on_post_invalid_host_id(self, mock_format_error, mock_validate_host_id)
7778
# Should return error response (default code is likely 400)
7879
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid host ID format"}])
7980

80-
# Verify validation was called with correct host_id
81-
mock_validate_host_id.assert_called_once_with("invalid-host")
81+
# Verify validation was called twice (once for logging, once for condition)
82+
self.assertEqual(mock_validate_host_id.call_count, 2)
83+
mock_validate_host_id.assert_called_with("invalid-host")
8284

8385
# Verify error formatting was called
8486
mock_format_error.assert_called_once_with("Invalid host ID format")
@@ -110,8 +112,9 @@ def test_on_post_missing_host_id(self, mock_format_error, mock_validate_host_id)
110112
# Should return error response
111113
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid host ID format"}])
112114

113-
# Verify validation was called with None
114-
mock_validate_host_id.assert_called_once_with(None)
115+
# Verify validation was called twice (once for logging, once for condition)
116+
self.assertEqual(mock_validate_host_id.call_count, 2)
117+
mock_validate_host_id.assert_called_with(None)
115118

116119
# Verify error formatting was called
117120
mock_format_error.assert_called_once_with("Invalid host ID format")
@@ -145,8 +148,9 @@ def test_on_post_empty_host_id(self, mock_format_error, mock_validate_host_id):
145148
# Should return error response
146149
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid host ID format"}])
147150

148-
# Verify validation was called with empty string
149-
mock_validate_host_id.assert_called_once_with("")
151+
# Verify validation was called twice (once for logging, once for condition)
152+
self.assertEqual(mock_validate_host_id.call_count, 2)
153+
mock_validate_host_id.assert_called_with("")
150154

151155
# Verify error formatting was called
152156
mock_format_error.assert_called_once_with("Invalid host ID format")
@@ -180,8 +184,9 @@ def test_on_post_with_config(self, mock_format_error, mock_validate_host_id):
180184
self.assertEqual(response.code, 200)
181185
self.assertEqual(response.body["host"], "test-host-456")
182186

183-
# Verify validation was called
184-
mock_validate_host_id.assert_called_once_with("test-host-456")
187+
# Verify validation was called twice (once for logging, once for condition)
188+
self.assertEqual(mock_validate_host_id.call_count, 2)
189+
mock_validate_host_id.assert_called_with("test-host-456")
185190

186191
# Verify logger was called
187192
self.assertEqual(mock_logger.info.call_count, 2)

functions/user-management/test_main.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def test_on_post_success(self, mock_format_error, mock_validate_email):
4242
self.assertEqual(response.code, 200)
4343
self.assertEqual(response.body["email"], "user@example.com")
4444

45-
# Verify validation was called with correct email
46-
mock_validate_email.assert_called_once_with("user@example.com")
45+
# Verify validation was called twice (once for logging, once for condition)
46+
self.assertEqual(mock_validate_email.call_count, 2)
47+
mock_validate_email.assert_called_with("user@example.com")
4748

4849
# Verify logger was called
4950
self.assertEqual(mock_logger.info.call_count, 2)
@@ -77,8 +78,9 @@ def test_on_post_invalid_email(self, mock_format_error, mock_validate_email):
7778
# Should return error response
7879
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid email format"}])
7980

80-
# Verify validation was called with correct email
81-
mock_validate_email.assert_called_once_with("invalid-email")
81+
# Verify validation was called twice (once for logging, once for condition)
82+
self.assertEqual(mock_validate_email.call_count, 2)
83+
mock_validate_email.assert_called_with("invalid-email")
8284

8385
# Verify error formatting was called
8486
mock_format_error.assert_called_once_with("Invalid email format")
@@ -110,8 +112,9 @@ def test_on_post_missing_email(self, mock_format_error, mock_validate_email):
110112
# Should return error response
111113
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid email format"}])
112114

113-
# Verify validation was called with None
114-
mock_validate_email.assert_called_once_with(None)
115+
# Verify validation was called twice (once for logging, once for condition)
116+
self.assertEqual(mock_validate_email.call_count, 2)
117+
mock_validate_email.assert_called_with(None)
115118

116119
# Verify error formatting was called
117120
mock_format_error.assert_called_once_with("Invalid email format")
@@ -145,8 +148,9 @@ def test_on_post_empty_email(self, mock_format_error, mock_validate_email):
145148
# Should return error response
146149
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid email format"}])
147150

148-
# Verify validation was called with empty string
149-
mock_validate_email.assert_called_once_with("")
151+
# Verify validation was called twice (once for logging, once for condition)
152+
self.assertEqual(mock_validate_email.call_count, 2)
153+
mock_validate_email.assert_called_with("")
150154

151155
# Verify error formatting was called
152156
mock_format_error.assert_called_once_with("Invalid email format")
@@ -191,8 +195,9 @@ def test_on_post_valid_email_variations(self, mock_format_error, mock_validate_e
191195
self.assertEqual(response.code, 200)
192196
self.assertEqual(response.body["email"], email)
193197

194-
# Verify validation was called with correct email
195-
mock_validate_email.assert_called_once_with(email)
198+
# Verify validation was called twice (once for logging, once for condition)
199+
self.assertEqual(mock_validate_email.call_count, 2)
200+
mock_validate_email.assert_called_with(email)
196201

197202
# Verify format_error_response was not called
198203
mock_format_error.assert_not_called()
@@ -235,8 +240,9 @@ def test_on_post_invalid_email_variations(self, mock_format_error, mock_validate
235240
# Should return error response
236241
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid email format"}])
237242

238-
# Verify validation was called with correct email
239-
mock_validate_email.assert_called_once_with(email)
243+
# Verify validation was called twice (once for logging, once for condition)
244+
self.assertEqual(mock_validate_email.call_count, 2)
245+
mock_validate_email.assert_called_with(email)
240246

241247
# Verify error formatting was called
242248
mock_format_error.assert_called_once_with("Invalid email format")
@@ -265,8 +271,9 @@ def test_on_post_with_config(self, mock_format_error, mock_validate_email):
265271
self.assertEqual(response.code, 200)
266272
self.assertEqual(response.body["email"], "newuser@company.com")
267273

268-
# Verify validation was called
269-
mock_validate_email.assert_called_once_with("newuser@company.com")
274+
# Verify validation was called twice (once for logging, once for condition)
275+
self.assertEqual(mock_validate_email.call_count, 2)
276+
mock_validate_email.assert_called_with("newuser@company.com")
270277

271278
# Verify logger was called
272279
self.assertEqual(mock_logger.info.call_count, 2)
@@ -293,8 +300,9 @@ def test_on_post_case_sensitivity(self, mock_format_error, mock_validate_email):
293300
self.assertEqual(response.code, 200)
294301
self.assertEqual(response.body["email"], "User.Name@EXAMPLE.COM")
295302

296-
# Verify validation was called with the exact email as provided
297-
mock_validate_email.assert_called_once_with("User.Name@EXAMPLE.COM")
303+
# Verify validation was called twice (once for logging, once for condition)
304+
self.assertEqual(mock_validate_email.call_count, 2)
305+
mock_validate_email.assert_called_with("User.Name@EXAMPLE.COM")
298306

299307
# Verify logger was called with the exact email
300308
mock_logger.info.assert_any_call("Email: User.Name@EXAMPLE.COM")
@@ -322,8 +330,9 @@ def test_on_post_whitespace_handling(self, mock_format_error, mock_validate_emai
322330
# Should return error response (assuming validation handles whitespace)
323331
self.assertEqual(response.errors, [{"code": 400, "message": "Invalid email format"}])
324332

325-
# Verify validation was called with the exact email including whitespace
326-
mock_validate_email.assert_called_once_with(" user@example.com ")
333+
# Verify validation was called twice (once for logging, once for condition)
334+
self.assertEqual(mock_validate_email.call_count, 2)
335+
mock_validate_email.assert_called_with(" user@example.com ")
327336

328337

329338
if __name__ == "__main__":

0 commit comments

Comments
 (0)