@@ -409,42 +409,104 @@ def test_aws_api_create_rds_snapshot(
409409
410410
411411@pytest .mark .parametrize (
412- ("region" , "identifier" , "expected_log_files" ),
412+ ("region" , "identifier" , "paginator_return_value" , " expected_log_files" ),
413413 [
414414 (
415415 "us-west-2" ,
416416 "test-db-instance" ,
417+ [
418+ {
419+ "DescribeDBLogFiles" : [
420+ {"LogFileName" : "error/mysql-error.log" },
421+ {"LogFileName" : "slowquery/mysql-slowquery.log" },
422+ ]
423+ }
424+ ],
417425 ["error/mysql-error.log" , "slowquery/mysql-slowquery.log" ],
418426 ),
419- ("us-east-1" , "postgres-instance" , ["postgresql.log" ]),
420- ("eu-west-1" , "empty-instance" , []),
427+ (
428+ "us-east-1" ,
429+ "postgres-instance" ,
430+ [{"DescribeDBLogFiles" : [{"LogFileName" : "postgresql.log" }]}],
431+ ["postgresql.log" ],
432+ ),
433+ (
434+ "eu-west-1" ,
435+ "empty-instance" ,
436+ [{"DescribeDBLogFiles" : []}],
437+ [],
438+ ),
439+ (
440+ "ap-south-1" ,
441+ "multi-page-db" ,
442+ [
443+ {"DescribeDBLogFiles" : [{"LogFileName" : "error.log" }]},
444+ {
445+ "DescribeDBLogFiles" : [
446+ {"LogFileName" : "slow.log" },
447+ {"LogFileName" : "general.log" },
448+ ]
449+ },
450+ ],
451+ ["error.log" , "slow.log" , "general.log" ],
452+ ),
453+ (
454+ "eu-north-1" ,
455+ "missing-key-db" ,
456+ [
457+ {"DescribeDBLogFiles" : [{"LogFileName" : "valid.log" }]},
458+ {"NotDescribeDBLogFiles" : []}, # Page missing 'DescribeDBLogFiles' key
459+ ],
460+ ["valid.log" ],
461+ ),
462+ (
463+ "ca-central-1" ,
464+ "empty-filename-db" ,
465+ [
466+ {
467+ "DescribeDBLogFiles" : [
468+ {"LogFileName" : "valid.log" },
469+ {"LogFileName" : "" }, # Empty filename should be filtered out
470+ {"LogFileName" : "another.log" },
471+ ]
472+ }
473+ ],
474+ ["valid.log" , "another.log" ],
475+ ),
476+ ],
477+ ids = [
478+ "success_single_page" ,
479+ "postgres_instance" ,
480+ "empty_instance" ,
481+ "multiple_pages" ,
482+ "missing_key_in_page" ,
483+ "empty_filename_filtered" ,
421484 ],
422485)
423486def test_aws_api_list_rds_logs (
424487 mock_aws_credentials : MagicMock ,
425488 mocker : MockerFixture ,
426489 region : str ,
427490 identifier : str ,
491+ paginator_return_value : list [dict [str , list [dict [str , str ]]]],
428492 expected_log_files : list [str ],
429493) -> None :
430- """Tests the list_rds_logs method of AWSApi."""
494+ """Tests the list_rds_logs method of AWSApi with paginated responses ."""
431495 aws_api = AWSApi (credentials = mock_aws_credentials , region = region )
432496
433497 mock_rds_client_on_instance = mocker .MagicMock ()
434498 aws_api .rds_client = mock_rds_client_on_instance
435499
436- # Mock the describe_db_log_files response
437- mock_rds_client_on_instance .describe_db_log_files .return_value = {
438- "DescribeDBLogFiles" : [
439- {"LogFileName" : log_file } for log_file in expected_log_files
440- ]
441- }
500+ mock_paginator = mocker .MagicMock ()
501+ mock_rds_client_on_instance .get_paginator .return_value = mock_paginator
502+ mock_paginator .paginate .return_value = paginator_return_value
442503
443504 result = aws_api .list_rds_logs (identifier = identifier )
444505
445- mock_rds_client_on_instance .describe_db_log_files .assert_called_once_with (
446- DBInstanceIdentifier = identifier
506+ mock_rds_client_on_instance .get_paginator .assert_called_once_with (
507+ "describe_db_log_files"
447508 )
509+ mock_paginator .paginate .assert_called_once_with (DBInstanceIdentifier = identifier )
448510 assert result == expected_log_files
449511
450512
0 commit comments